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 +4 -4
- data/VERSION +1 -1
- data/lib/unsub/main.rb +2 -2
- data/lib/unsub/service/chef.rb +1 -1
- data/lib/unsub/service/icinga.rb +6 -6
- data/lib/unsub/service/sensu.rb +18 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a36fa0ea577e9dec28f7c2554c22e37babeacba4
|
4
|
+
data.tar.gz: c1a75f248f941788c3c4fcbb065942c7832957ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a897aede7e4bb20662b28a4040f70c1554f9ed275c9f1059e4030790854e540bdd1a6eadc61ebb14dedebd0eb69793428a923d057567c9b003d180b7fded8ff
|
7
|
+
data.tar.gz: 986f34b160d774a1f890ee3853c5804b30aee7b0fda6007afaffb5c14b81e0a127aeb6cbcc2f543bc69a4f296fd36c3c5a2d6f783073979a4e663ac24ebe1d5c
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/unsub/main.rb
CHANGED
@@ -98,13 +98,13 @@ module Unsub
|
|
98
98
|
|
99
99
|
success = case event.kind
|
100
100
|
when :launch
|
101
|
-
s1 = services[:icinga].
|
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].
|
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]
|
data/lib/unsub/service/chef.rb
CHANGED
@@ -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
|
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
|
data/lib/unsub/service/icinga.rb
CHANGED
@@ -10,16 +10,16 @@ module Unsub
|
|
10
10
|
end
|
11
11
|
|
12
12
|
|
13
|
-
def
|
14
|
-
success = cgi_command
|
15
|
-
log.info service: 'icinga', event: '
|
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
|
21
|
-
success = cgi_command
|
22
|
-
log.info service: 'icinga', event: '
|
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
|
|
data/lib/unsub/service/sensu.rb
CHANGED
@@ -12,10 +12,7 @@ module Unsub
|
|
12
12
|
|
13
13
|
def extend_host host
|
14
14
|
name = if ip = host[:ip]
|
15
|
-
|
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
|