nagios-gearman-downtime 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/downtime_worker +14 -9
- data/lib/nagios-gearman-downtime.rb +12 -3
- data/lib/nagios-gearman-downtime/version.rb +1 -1
- metadata +2 -2
data/bin/downtime_worker
CHANGED
@@ -3,15 +3,14 @@ require 'gearman'
|
|
3
3
|
require 'base64'
|
4
4
|
require 'openssl'
|
5
5
|
require 'logger'
|
6
|
-
|
7
|
-
logger = Logger.new(STDOUT)
|
6
|
+
require "nagios-gearman-downtime"
|
8
7
|
|
9
8
|
key = `grep key /etc/mod-gearman/worker.conf`.chomp.split('=').last.strip
|
10
|
-
|
9
|
+
::Nagios::Gearman::Downtime.log.info "key: #{key}"
|
11
10
|
|
12
11
|
servers = []
|
13
12
|
servers << `grep server /etc/mod-gearman/worker.conf`.chomp.split('=').last.strip
|
14
|
-
|
13
|
+
::Nagios::Gearman::Downtime.log.info "servers: #{servers}"
|
15
14
|
|
16
15
|
def aes256_decrypt(key, data)
|
17
16
|
key = null_padding(key)
|
@@ -28,8 +27,14 @@ end
|
|
28
27
|
|
29
28
|
|
30
29
|
def process_external_cmd(data)
|
31
|
-
|
30
|
+
if File.exist?('/usr/local/nagios/var/rw/nagios.cmd')
|
31
|
+
path = '/usr/local/nagios/var/rw/nagios.cmd'
|
32
|
+
end
|
32
33
|
|
34
|
+
if File.exist?('/var/lib/icinga/rw/icinga.cmd')
|
35
|
+
path = '/var/lib/icinga/rw/icinga.cmd'
|
36
|
+
end
|
37
|
+
|
33
38
|
File.open(path, 'a') do |pipe|
|
34
39
|
puts "Sending downtime: #{data}"
|
35
40
|
pipe.puts data
|
@@ -38,17 +43,17 @@ def process_external_cmd(data)
|
|
38
43
|
end
|
39
44
|
|
40
45
|
w = Gearman::Worker.new(['0.0.0.0:4730'])
|
41
|
-
|
46
|
+
::Nagios::Gearman::Downtime.log.info w.status
|
42
47
|
|
43
48
|
w.add_ability('downtime') do |data,job|
|
44
|
-
|
49
|
+
::Nagios::Gearman::Downtime.log.info "Data recieved:\n#{data}"
|
45
50
|
decoded_data = Base64.strict_decode64(data.gsub("\n", ''))
|
46
51
|
|
47
52
|
decrypt = aes256_decrypt(key, decoded_data)
|
48
|
-
|
53
|
+
::Nagios::Gearman::Downtime.log.info "decrypted data:\n#{decrypt}"
|
49
54
|
|
50
55
|
process_external_cmd(decrypt)
|
51
|
-
|
56
|
+
::Nagios::Gearman::Downtime.log.info "Finished processing job"
|
52
57
|
end
|
53
58
|
|
54
59
|
loop { w.work }
|
@@ -2,6 +2,12 @@ module Nagios
|
|
2
2
|
module Gearman
|
3
3
|
module Downtime
|
4
4
|
|
5
|
+
def self.log
|
6
|
+
@@logger = Logger.new(STDOUT)
|
7
|
+
@@logger.level = Logger::DEBUG
|
8
|
+
@@logger
|
9
|
+
end
|
10
|
+
|
5
11
|
def self.create_object_type(obj, obj_name)
|
6
12
|
case obj
|
7
13
|
when 'host'
|
@@ -21,6 +27,7 @@ module Nagios
|
|
21
27
|
when 'disable_servicegroup'
|
22
28
|
object_info = "DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS;#{obj_name}"
|
23
29
|
end
|
30
|
+
log.info("object_info: #{object_info}")
|
24
31
|
end
|
25
32
|
|
26
33
|
|
@@ -34,6 +41,7 @@ module Nagios
|
|
34
41
|
end
|
35
42
|
|
36
43
|
payload = "[#{Time.now.to_i}] #{object_info};#{common_args}"
|
44
|
+
log.info("payload before encryption: #{payload}")
|
37
45
|
|
38
46
|
if args.delete(:encryption)
|
39
47
|
begin
|
@@ -46,16 +54,17 @@ module Nagios
|
|
46
54
|
end
|
47
55
|
|
48
56
|
def self.send_external_cmd(options)
|
49
|
-
|
57
|
+
log.info "send_external_cmd options: #{options}"
|
50
58
|
client = ::Gearman::Client.new(options[:gearman_job_server])
|
51
59
|
taskset = ::Gearman::TaskSet.new(client)
|
52
60
|
encoded_job = Base64.encode64(options[:job])
|
53
61
|
task = ::Gearman::Task.new(options[:queue], encoded_job)
|
54
62
|
begin
|
55
|
-
|
63
|
+
log.info "[client] Sending task: #{task.inspect}"
|
56
64
|
result = taskset.add_task(task)
|
65
|
+
log.info("result: #{resault}")
|
57
66
|
rescue Exception => e
|
58
|
-
"Send external command failed: #{e}"
|
67
|
+
log.error "Send external command failed: #{e}"
|
59
68
|
end
|
60
69
|
end
|
61
70
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nagios-gearman-downtime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03
|
12
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gearman-ruby
|