city-watch 0.5.7 → 0.5.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,7 +20,7 @@ module Alerts
20
20
  CityWatch.redis.zrevrange "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", 0, num - 1
21
21
  end
22
22
 
23
- def send_alerts!
23
+ def send_alerts!(*args)
24
24
  get_alerts.map do |alert|
25
25
  puts "Alert: #{alert.inspect}" if CityWatch.debug?
26
26
  end
@@ -5,7 +5,7 @@ module DataSets
5
5
  @datasets[name] = block
6
6
  end
7
7
 
8
- def run_dataset_collector(dat)
8
+ def run_dataset_collector(dat,rcv=nil,host=nil)
9
9
  @datasets.map do |(name,dataset)|
10
10
  dataset.call(dat)
11
11
  end if @datasets
@@ -5,7 +5,7 @@ module Rules
5
5
  @rules[name] = block
6
6
  end
7
7
 
8
- def run_rules(dat)
8
+ def run_rules(dat,rcv=nil,host=nil)
9
9
  @rules.map do |(name,rule)|
10
10
  rule.call(dat)
11
11
  end if @rules
@@ -21,9 +21,7 @@ module Watchman
21
21
  sum = dat[:summary].is_a?(Array) ? dat[:summary].inject({}) {|acc,k| acc[k.to_sym] = dat[k.to_sym]; acc} : dat[:summary]
22
22
  CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::summary", rcv_time, Yajl::Encoder.encode(sum)
23
23
  end
24
- run_rules(dat)
25
- run_dataset_collector(dat)
26
- send_alerts!
24
+ run_post_processors!(dat,rcv,host)
27
25
  return 0, sum || nil
28
26
  end
29
27
 
@@ -53,16 +51,30 @@ module Watchman
53
51
  end
54
52
  alias_method :option, :options
55
53
 
54
+ def run_post_processors!(dat,rcv,host)
55
+ @post_processors.each do |proc|
56
+ proc.call(dat,rcv,host)
57
+ end if @post_processors
58
+ end
59
+
60
+ def add_post_processor(meth=nil,&block)
61
+ @post_processors ||= []
62
+ @post_processors << (block_given? ? block : meth)
63
+ end
64
+
56
65
  end
57
66
 
58
67
  def self.included(base)
68
+ base.extend(ClassMethods)
59
69
  base.extend(Alerts)
70
+ base.add_post_processor base.method(:send_alerts!)
60
71
  base.extend(Rules)
72
+ base.add_post_processor base.method(:run_rules)
61
73
  base.extend(Flags)
62
74
  base.extend(Notifications)
63
75
  base.extend(DataSets)
76
+ base.add_post_processor base.method(:run_dataset_collector)
64
77
  base.extend(Status)
65
- base.extend(ClassMethods)
66
78
  Watchmen.register(base)
67
79
  end
68
80
 
@@ -17,4 +17,8 @@ class Uptime
17
17
  out.merge({:summary => [:uptime_days]})
18
18
  end
19
19
 
20
+ add_rule(:status_vars) do |data|
21
+ set_status_var :uptime, data[:uptime_days]
22
+ end
23
+
20
24
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CityWatch
2
- VERSION = "0.5.7"
2
+ VERSION = "0.5.8"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: city-watch
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.7
5
+ version: 0.5.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Bragg