nagios-gearman-downtime 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ .DS_store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ bundle
20
+ *.swp
@@ -0,0 +1,57 @@
1
+ # Nagios Gearman Downtime
2
+
3
+ Gearman Client & Worker for sending downtime and enable / disable notifications for service groups
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'nagios-gearman-downtime',
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install nagios-gearman-downtime
18
+
19
+ ## Usage:
20
+ downtime_client set --duration=duration in minutes --gearman-server=Gearman server address
21
+
22
+ ## Available options are:
23
+
24
+ --object_type [host,
25
+ hostgroup_host,
26
+ hostgroup_svc,
27
+ servicegroup_host,
28
+ servicegroup_svc,
29
+ service,
30
+ enable_servicegroup,
31
+ disable_servicegroup], default => host
32
+
33
+ --object_name default => 'hostname -f', the name of the object type
34
+
35
+
36
+ --encryption true/false - default => false
37
+ --key Key to encrypt request - must be identical to the gearman_server key
38
+ --queue gearman server queue default => downtime
39
+
40
+
41
+ --start_time default => now
42
+ --end_time default => now + duration
43
+ --duration time in minutes, default => 1 minute
44
+
45
+ --author Author of downtime (default hostname)
46
+ --comment default => 'Downtime recieved by gearman server'
47
+
48
+ Send Downtime request to Gearman server - downtime queue
49
+
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -3,7 +3,7 @@ require 'gearman'
3
3
  require 'base64'
4
4
  require "openssl"
5
5
  require "thor"
6
- require "../lib/nagios-gearman-downtime"
6
+ require "nagios-gearman-downtime"
7
7
 
8
8
  class Downtime < Thor
9
9
 
@@ -0,0 +1,76 @@
1
+ module Nagios
2
+ module Gearman
3
+ module Downtime
4
+
5
+ def self.create_object_type(obj, obj_name)
6
+ case obj
7
+ when 'host'
8
+ object_info = "SCHEDULE_HOST_SVC_DOWNTIME;#{obj_name}"
9
+ when 'hostgroup_host'
10
+ object_info = "SCHEDULE_HOSTGROUP_HOST_DOWNTIME;#{obj_name}"
11
+ when 'hostgroup_svc'
12
+ object_info = "SCHEDULE_HOSTGROUP_SVC_DOWNTIME;#{obj_name}"
13
+ when 'servicegroup_host'
14
+ object_info = "SCHEDULE_SERVICEGROUP_HOST_DOWNTIME;#{obj_name}"
15
+ when 'servicegroup_svc'
16
+ object_info = "SCHEDULE_SERVICEGROUP_SVC_DOWNTIME;#{obj_name}"
17
+ when 'service'
18
+ object_info = "SCHEDULE_HOSTGROUP_HOST_DOWNTIME;#{obj_name}"
19
+ when 'enable_servicegroup'
20
+ object_info = "ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS;#{obj_name}"
21
+ when 'disable_servicegroup'
22
+ object_info = "DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS;#{obj_name}"
23
+ end
24
+ end
25
+
26
+
27
+ def self.build_payload(args)
28
+ object_info = create_object_type(args.delete(:object_type), args.delete(:object_name))
29
+
30
+ if object_info.match(/enable|disable/i)
31
+ common_args = ''
32
+ else
33
+ 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)}"
34
+ end
35
+
36
+ payload = "[#{Time.now.to_i}] #{object_info};#{common_args}"
37
+
38
+ if args.delete(:encryption)
39
+ begin
40
+ payload = aes256_encrypt(args.delete(:key), payload)
41
+ rescue Exception => e
42
+ puts "unable to encrypt: #{e}"
43
+ end
44
+ end
45
+ payload
46
+ end
47
+
48
+ def self.send_external_cmd(options)
49
+ puts "send_external_cmd options: #{options}"
50
+ client = ::Gearman::Client.new(options[:gearman_job_server])
51
+ taskset = ::Gearman::TaskSet.new(client)
52
+ encoded_job = Base64.encode64(options[:job])
53
+ task = ::Gearman::Task.new(options[:queue], encoded_job)
54
+ begin
55
+ puts "[client] Sending task: #{task.inspect}"
56
+ result = taskset.add_task(task)
57
+ rescue Exception => e
58
+ "Send external command failed: #{e}"
59
+ end
60
+ end
61
+
62
+ def self.aes256_encrypt(key, data)
63
+ key = null_padding(key)
64
+ aes = OpenSSL::Cipher.new('AES-256-ECB')
65
+ aes.encrypt
66
+ aes.key = key
67
+ aes.update(data) + aes.final
68
+ end
69
+
70
+ def self.null_padding(key)
71
+ padding = (32 - key.bytesize) if(key.kind_of?(String) && 32 != key.bytesize)
72
+ key += "\0" * padding
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,7 @@
1
+ module Nagios
2
+ module Gearman
3
+ module Downtime
4
+ VERSION = "1.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
3
+ require 'nagios-gearman-downtime/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "nagios-gearman-downtime"
7
+ s.authors = ["Ami Mahloof"]
8
+ s.email = "ami.mahloof@gmail.com"
9
+ s.homepage = "https://github.com/gtforge/nagios-gearman-downtime"
10
+ s.summary = "Send external commands to mod-gearman"
11
+ s.description = "Gearman Client & Worker for sending downtime and enable / disable notifications for service groups"
12
+ s.add_dependency 'gearman-ruby'
13
+ s.add_dependency 'thor'
14
+ s.add_dependency 'bluepill'
15
+ s.files = `git ls-files`.split("\n")
16
+ s.require_paths = ["lib"]
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.license = 'MIT'
19
+ s.version = ::Nagios::Gearman::Downtime::VERSION
20
+ end
@@ -0,0 +1,10 @@
1
+ downtime_worker = `which downtime_worker`
2
+ Bluepill.application("downtime_worker", :log_file => "/var/log/bluepill-downtime_worker.log") do |app|
3
+ app.process("downtime_worker") do |process|
4
+ process.start_command = "#{downtime_worker}"
5
+ process.stop_command = "kill -QUIT {{PID}}"
6
+ process.restart_command = "kill -HUP {{PID}}"
7
+ process.stdout = process.stderr = "/var/log/bluepill-downtime_worker.log"
8
+ process.daemonize = true
9
+ end
10
+ end
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.0
4
+ version: 1.0.1
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-03 00:00:00.000000000 Z
12
+ date: 2014-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gearman-ruby
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bluepill
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
46
62
  description: Gearman Client & Worker for sending downtime and enable / disable notifications
47
63
  for service groups
48
64
  email: ami.mahloof@gmail.com
@@ -52,8 +68,15 @@ executables:
52
68
  extensions: []
53
69
  extra_rdoc_files: []
54
70
  files:
71
+ - .gitignore
72
+ - README.md
73
+ - Rakefile
55
74
  - bin/downtime_client
56
75
  - bin/downtime_worker
76
+ - lib/nagios-gearman-downtime.rb
77
+ - lib/nagios-gearman-downtime/version.rb
78
+ - nagios-gearman-downtime.gemspec
79
+ - worker_daemon/downtime_worker.pill
57
80
  homepage: https://github.com/gtforge/nagios-gearman-downtime
58
81
  licenses:
59
82
  - MIT