unsub 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7573632df7e513045df45faf213a4ceb43711a9
4
- data.tar.gz: cb65143b20481d3f8981248a2493dc577d23ce2f
3
+ metadata.gz: a36fa0ea577e9dec28f7c2554c22e37babeacba4
4
+ data.tar.gz: c1a75f248f941788c3c4fcbb065942c7832957ce
5
5
  SHA512:
6
- metadata.gz: 4ed4f03b1f05827b24d18a0d0f967dbcbdc2c9b8e868b433323a2aaf0de093abe132be95f7722f0c28ebc37dbb0c5940414b54fe89b9655eec6ca26149c03b0c
7
- data.tar.gz: 2df0645c5915ac9a6227331d53de395fc9667a7981b0f509f3099e1498d0b795fdde425648c8e818fc3d9729e0eff4055a171548da101a7dcb1ceb094f017095
6
+ metadata.gz: 5a897aede7e4bb20662b28a4040f70c1554f9ed275c9f1059e4030790854e540bdd1a6eadc61ebb14dedebd0eb69793428a923d057567c9b003d180b7fded8ff
7
+ data.tar.gz: 986f34b160d774a1f890ee3853c5804b30aee7b0fda6007afaffb5c14b81e0a127aeb6cbcc2f543bc69a4f296fd36c3c5a2d6f783073979a4e663ac24ebe1d5c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -98,13 +98,13 @@ module Unsub
98
98
 
99
99
  success = case event.kind
100
100
  when :launch
101
- s1 = services[:icinga].disable_downtime event.host
101
+ s1 = services[:icinga].enable_notifications event.host
102
102
  s2 = services[:chef].remove_tag event.host, 'terminated'
103
103
  s3 = services[:chef].add_tag event.host, 'launched'
104
104
  s1 && s2 && s3
105
105
  when :terminate
106
106
  s1 = services[:sensu].delete_client event.host
107
- s2 = services[:icinga].enable_downtime event.host
107
+ s2 = services[:icinga].disable_notifications event.host
108
108
  s3 = services[:chef].remove_tag event.host, 'launched'
109
109
  s4 = services[:chef].add_tag event.host, 'terminated'
110
110
  db.delete! event.host[:id]
@@ -20,7 +20,7 @@ module Unsub
20
20
 
21
21
  def extend_host host
22
22
  name = if ip = host[:ip]
23
- api.search.query(:node, 'ipaddress:"%s"' % ip).rows.shift.name rescue nil
23
+ api.search.query(:node, 'ipaddress:"%s"' % ip).rows.shift['name'] rescue nil
24
24
  end
25
25
 
26
26
  old_host = host.dup ; host.merge! chef_name: name if name
@@ -10,16 +10,16 @@ module Unsub
10
10
  end
11
11
 
12
12
 
13
- def enable_downtime host
14
- success = cgi_command 28, host # CMD_ENABLE_HOST_SVC_NOTIFICATIONS
15
- log.info service: 'icinga', event: 'enable_downtime', host: host, success: success
13
+ def disable_notifications host
14
+ success = cgi_command 29, host # CMD_DISABLE_HOST_SVC_NOTIFICATIONS
15
+ log.info service: 'icinga', event: 'disable_notifications', host: host, success: success
16
16
  success
17
17
  end
18
18
 
19
19
 
20
- def disable_downtime host
21
- success = cgi_command 29, host # CMD_DISABLE_HOST_SVC_NOTIFICATIONS
22
- log.info service: 'icinga', event: 'disable_downtime', host: host, success: success
20
+ def enable_notifications host
21
+ success = cgi_command 28, host # CMD_ENABLE_HOST_SVC_NOTIFICATIONS
22
+ log.info service: 'icinga', event: 'enable_notifications', host: host, success: success
23
23
  success
24
24
  end
25
25
 
@@ -12,10 +12,7 @@ module Unsub
12
12
 
13
13
  def extend_host host
14
14
  name = if ip = host[:ip]
15
- get_clients = Net::HTTP::Get.new '/clients?limit=1000000'
16
- response = http.request get_clients
17
- clients = JSON.parse response.body, symbolize_names: true
18
- client = clients.select { |c| c[:address] == ip }.shift
15
+ client = sensu_clients.select { |c| c[:address] == ip }.shift
19
16
  client.nil? ? nil : client[:name]
20
17
  end
21
18
 
@@ -35,6 +32,23 @@ module Unsub
35
32
  log.info service: 'sensu', event: 'delete_client', host: host, success: success
36
33
  success
37
34
  end
35
+
36
+
37
+ private
38
+
39
+ def sensu_clients limit=1000, offset=0, results=[]
40
+ loop do
41
+ endpoint = '/clients?limit=%d&offset=%d' % [ limit, offset ]
42
+ request = Net::HTTP::Get.new endpoint
43
+ response = http.request request
44
+ clients = JSON.parse response.body, symbolize_names: true
45
+
46
+ return results if clients.empty?
47
+ results += clients
48
+ offset += limit
49
+ end
50
+ end
51
+
38
52
  end
39
53
  end
40
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unsub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Clemmer