city-watch 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- city-watch (0.5.3)
4
+ city-watch (0.5.5)
5
5
  rack
6
6
  rack-mount
7
7
  redis
@@ -1,36 +1,29 @@
1
1
  module Alerts
2
- module ClassMethods
3
-
4
- def send_alert(message,dat=nil)
5
- CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", rcv_time, Yajl::Encoder.encode({:message => message, :data => dat, :when => rcv_time})
6
- end
7
-
8
- def alerts
9
- @alerts ||= []
10
- if block_given?
11
- @alerts.each do |a|
12
- yield a
13
- end
14
- else
15
- @alerts
16
- end
17
- nil
18
- end
19
-
20
- def get_alerts(host=host,num=5)
21
- CityWatch.redis.zrevrange "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", 0, num - 1
22
- end
23
2
 
24
- def send_alerts!
25
- get_alerts.map do |alert|
26
- puts "Alert: #{alert.inspect}" if CityWatch.debug?
3
+ def send_alert(message,dat=nil)
4
+ CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", rcv_time, Yajl::Encoder.encode({:message => message, :data => dat, :when => rcv_time})
5
+ end
6
+
7
+ def alerts
8
+ @alerts ||= []
9
+ if block_given?
10
+ @alerts.each do |a|
11
+ yield a
27
12
  end
13
+ else
14
+ @alerts
28
15
  end
29
-
16
+ nil
30
17
  end
31
-
32
- def self.included(base)
33
- base.extend(ClassMethods)
18
+
19
+ def get_alerts(host=host,num=5)
20
+ CityWatch.redis.zrevrange "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", 0, num - 1
21
+ end
22
+
23
+ def send_alerts!
24
+ get_alerts.map do |alert|
25
+ puts "Alert: #{alert.inspect}" if CityWatch.debug?
26
+ end
34
27
  end
35
28
 
36
29
  end
@@ -0,0 +1,7 @@
1
+ module DataSets
2
+
3
+ def data_set(name,&block)
4
+
5
+ end
6
+
7
+ end
@@ -1,63 +1,56 @@
1
1
  module Flags
2
- module ClassMethods
3
-
4
- def set_flag(name)
5
- unless get_flag(name)
6
- flag_flapped name, :on
7
- CityWatch.redis.setbit "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name), 1
8
- end
9
- end
10
-
11
- def clear_flag(name)
12
- if get_flag(name)
13
- flag_flapped name, :off
14
- CityWatch.redis.setbit "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name), 0
15
- end
16
- end
17
-
18
- def flag_flapped(name,new_val)
19
- puts "Flag flipped: #{name} -> #{new_val}" if CityWatch.debug?
20
- end
21
-
22
- def get_flag(name,host=host)
23
- @host = host
24
- CityWatch.redis.getbit("#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name)) == 1 ? true : false
25
- end
26
-
27
- def get_flags(host=host)
28
- @host = host
29
- out = []
30
- map = flag_map
31
- map.each_index do |idx|
32
- out << map[idx] if get_flag(map[idx])
33
- end
34
- out
35
- end
36
-
37
- def flag_map_key
38
- "#{CityWatch.config[:prefix]}::#{self.name}::flag_map"
39
- end
40
-
41
- def flag_map
42
- CityWatch.redis.lrange flag_map_key, 0, -1
2
+
3
+ def set_flag(name)
4
+ unless get_flag(name)
5
+ flag_flapped name, :on
6
+ CityWatch.redis.setbit "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name), 1
43
7
  end
44
-
45
- def flag_position(name)
46
- if (map = flag_map) && map.include?(name.to_s)
47
- map.index(name.to_s)
48
- else
49
- new_flag(name)
50
- end
8
+ end
9
+
10
+ def clear_flag(name)
11
+ if get_flag(name)
12
+ flag_flapped name, :off
13
+ CityWatch.redis.setbit "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name), 0
51
14
  end
52
-
53
- def new_flag(name)
54
- CityWatch.redis.rpush(flag_map_key, name) - 1
15
+ end
16
+
17
+ def flag_flapped(name,new_val)
18
+ puts "Flag flipped: #{name} -> #{new_val}" if CityWatch.debug?
19
+ end
20
+
21
+ def get_flag(name,host=host)
22
+ @host = host
23
+ CityWatch.redis.getbit("#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name)) == 1 ? true : false
24
+ end
25
+
26
+ def get_flags(host=host)
27
+ @host = host
28
+ out = []
29
+ map = flag_map
30
+ map.each_index do |idx|
31
+ out << map[idx] if get_flag(map[idx])
32
+ end
33
+ out
34
+ end
35
+
36
+ def flag_map_key
37
+ "#{CityWatch.config[:prefix]}::#{self.name}::flag_map"
38
+ end
39
+
40
+ def flag_map
41
+ CityWatch.redis.lrange flag_map_key, 0, -1
42
+ end
43
+
44
+ def flag_position(name)
45
+ if (map = flag_map) && map.include?(name.to_s)
46
+ map.index(name.to_s)
47
+ else
48
+ new_flag(name)
55
49
  end
56
-
57
50
  end
58
51
 
59
- def self.included(base)
60
- base.extend(ClassMethods)
52
+ def new_flag(name)
53
+ CityWatch.redis.rpush(flag_map_key, name) - 1
61
54
  end
62
55
 
63
56
  end
@@ -0,0 +1,8 @@
1
+ module Notifications
2
+
3
+ def notify(*args)
4
+ @notifications ||= []
5
+ @notifications << [*args]
6
+ end
7
+
8
+ end
@@ -1,21 +1,14 @@
1
1
  module Rules
2
- module ClassMethods
3
-
4
- def add_rule(name,&block)
5
- @rules ||= {}
6
- @rules[name] = block
7
- end
8
-
9
- def run_rules(dat)
10
- @rules.map do |(name,rule)|
11
- rule.call(dat)
12
- end if @rules
13
- end
14
-
15
- end
16
2
 
17
- def self.included(base)
18
- base.extend(ClassMethods)
3
+ def add_rule(name,&block)
4
+ @rules ||= {}
5
+ @rules[name] = block
6
+ end
7
+
8
+ def run_rules(dat)
9
+ @rules.map do |(name,rule)|
10
+ rule.call(dat)
11
+ end if @rules
19
12
  end
20
13
 
21
14
  end
@@ -1,6 +1,8 @@
1
1
  require 'city_watch/util/alerts'
2
2
  require 'city_watch/util/rules'
3
3
  require 'city_watch/util/flags'
4
+ require 'city_watch/util/notifications'
5
+ require 'city_watch/util/datasets'
4
6
 
5
7
  module Watchman
6
8
 
@@ -52,9 +54,11 @@ module Watchman
52
54
  end
53
55
 
54
56
  def self.included(base)
55
- base.extend(Alerts::ClassMethods)
56
- base.extend(Rules::ClassMethods)
57
- base.extend(Flags::ClassMethods)
57
+ base.extend(Alerts)
58
+ base.extend(Rules)
59
+ base.extend(Flags)
60
+ base.extend(Notifications)
61
+ base.extend(DataSets)
58
62
  base.extend(ClassMethods)
59
63
  Watchmen.register(base)
60
64
  end
@@ -5,7 +5,7 @@ class SystemInfo
5
5
  require 'sysinfo'
6
6
 
7
7
  def self.data
8
- SysInfo.new.to_hash
8
+ SysInfo.new.to_hash.merge({:summary => ["ipaddress_internal", "uptime"]})
9
9
  end
10
10
 
11
11
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CityWatch
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
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.4
5
+ version: 0.5.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Bragg
@@ -129,7 +129,9 @@ files:
129
129
  - lib/city_watch/commands/ps.rb
130
130
  - lib/city_watch/util/alerts.rb
131
131
  - lib/city_watch/util/collector.rb
132
+ - lib/city_watch/util/datasets.rb
132
133
  - lib/city_watch/util/flags.rb
134
+ - lib/city_watch/util/notifications.rb
133
135
  - lib/city_watch/util/rules.rb
134
136
  - lib/city_watch/util/run_command.rb
135
137
  - lib/city_watch/util/watchman.rb