nagios-gearman-downtime 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/downtime_client +1 -1
- data/bin/downtime_worker +6 -7
- data/lib/nagios-gearman-downtime.rb +15 -11
- data/lib/nagios-gearman-downtime/version.rb +1 -1
- metadata +1 -1
data/bin/downtime_client
CHANGED
data/bin/downtime_worker
CHANGED
@@ -2,15 +2,14 @@
|
|
2
2
|
require 'gearman'
|
3
3
|
require 'base64'
|
4
4
|
require 'openssl'
|
5
|
-
require 'logger'
|
6
5
|
require "nagios-gearman-downtime"
|
7
6
|
|
8
7
|
key = `grep key /etc/mod-gearman/worker.conf`.chomp.split('=').last.strip
|
9
|
-
::Nagios::Gearman::Downtime.
|
8
|
+
::Nagios::Gearman::Downtime.logger.info "key: #{key}"
|
10
9
|
|
11
10
|
servers = []
|
12
11
|
servers << `grep server /etc/mod-gearman/worker.conf`.chomp.split('=').last.strip
|
13
|
-
::Nagios::Gearman::Downtime.
|
12
|
+
::Nagios::Gearman::Downtime.logger.info "servers: #{servers}"
|
14
13
|
|
15
14
|
def aes256_decrypt(key, data)
|
16
15
|
key = null_padding(key)
|
@@ -43,17 +42,17 @@ def process_external_cmd(data)
|
|
43
42
|
end
|
44
43
|
|
45
44
|
w = Gearman::Worker.new(['0.0.0.0:4730'])
|
46
|
-
::Nagios::Gearman::Downtime.
|
45
|
+
::Nagios::Gearman::Downtime.logger.info w.status
|
47
46
|
|
48
47
|
w.add_ability('downtime') do |data,job|
|
49
|
-
::Nagios::Gearman::Downtime.
|
48
|
+
::Nagios::Gearman::Downtime.logger.info "Data recieved:\n#{data}"
|
50
49
|
decoded_data = Base64.strict_decode64(data.gsub("\n", ''))
|
51
50
|
|
52
51
|
decrypt = aes256_decrypt(key, decoded_data)
|
53
|
-
::Nagios::Gearman::Downtime.
|
52
|
+
::Nagios::Gearman::Downtime.logger.info "decrypted data:\n#{decrypt}"
|
54
53
|
|
55
54
|
process_external_cmd(decrypt)
|
56
|
-
::Nagios::Gearman::Downtime.
|
55
|
+
::Nagios::Gearman::Downtime.logger.info "Finished processing job"
|
57
56
|
end
|
58
57
|
|
59
58
|
loop { w.work }
|
@@ -1,13 +1,16 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
1
3
|
module Nagios
|
2
4
|
module Gearman
|
3
5
|
module Downtime
|
4
6
|
|
5
|
-
def self.
|
7
|
+
def self.logger
|
6
8
|
@@logger = Logger.new(STDOUT)
|
7
9
|
@@logger.level = Logger::DEBUG
|
8
10
|
@@logger
|
9
11
|
end
|
10
12
|
|
13
|
+
|
11
14
|
def self.create_object_type(obj, obj_name)
|
12
15
|
case obj
|
13
16
|
when 'host'
|
@@ -27,44 +30,45 @@ module Nagios
|
|
27
30
|
when 'disable_servicegroup'
|
28
31
|
object_info = "DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS;#{obj_name}"
|
29
32
|
end
|
30
|
-
|
33
|
+
logger.info "object_info: #{object_info}"
|
34
|
+
object_info
|
31
35
|
end
|
32
36
|
|
33
37
|
|
34
38
|
def self.build_payload(args)
|
35
39
|
object_info = create_object_type(args.delete(:object_type), args.delete(:object_name))
|
36
|
-
|
40
|
+
|
37
41
|
if object_info.match(/enable|disable/i)
|
38
42
|
common_args = ''
|
39
43
|
else
|
40
|
-
common_args = "
|
44
|
+
common_args = ";#{args.delete(:start_time)};#{args.delete(:end_time)};#{args.delete(:fixed)};#{args.delete(:trigger_id)};#{args.delete(:duration)};#{args.delete(:author)};#{args.delete(:comment)}"
|
41
45
|
end
|
42
46
|
|
43
|
-
payload = "[#{Time.now.to_i}] #{object_info}
|
44
|
-
|
47
|
+
payload = "[#{Time.now.to_i}] #{object_info}#{common_args}"
|
48
|
+
logger.info "payload before encryption: #{payload}"
|
45
49
|
|
46
50
|
if args.delete(:encryption)
|
47
51
|
begin
|
48
52
|
payload = aes256_encrypt(args.delete(:key), payload)
|
49
53
|
rescue Exception => e
|
50
|
-
|
54
|
+
logger.error "unable to encrypt payload: #{e}"
|
51
55
|
end
|
52
56
|
end
|
53
57
|
payload
|
54
58
|
end
|
55
59
|
|
56
60
|
def self.send_external_cmd(options)
|
57
|
-
|
61
|
+
logger.info "send_external_cmd options: #{options}"
|
58
62
|
client = ::Gearman::Client.new(options[:gearman_job_server])
|
59
63
|
taskset = ::Gearman::TaskSet.new(client)
|
60
64
|
encoded_job = Base64.encode64(options[:job])
|
61
65
|
task = ::Gearman::Task.new(options[:queue], encoded_job)
|
62
66
|
begin
|
63
|
-
|
67
|
+
logger.info "[client] Sending task: #{task.inspect}"
|
64
68
|
result = taskset.add_task(task)
|
65
|
-
|
69
|
+
logger.info "result: #{result}"
|
66
70
|
rescue Exception => e
|
67
|
-
|
71
|
+
logger.error "Send external command failed: #{e}"
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|