cepmon-nagios 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cepmon-nagios.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cepmon-nagios (0.0.1)
5
+ bundler
6
+ json
7
+ trollop
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ json (1.6.5)
13
+ json (1.6.5-java)
14
+ trollop (1.16.2)
15
+
16
+ PLATFORMS
17
+ java
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ cepmon-nagios!
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # cepmon-nagios
2
+
3
+ A Nagios plugin to monitor [cepmon](https://github.com/fetep/cepmon)
4
+ rule state.
5
+
6
+ ## Usage
7
+
8
+ $ check_cepmon --help
9
+ Options:
10
+ --cepmon, -c <s>: cepmon host:port
11
+ --rule, -r <s>: rule name to filter on
12
+ --host, -h <s>: host name to filter on
13
+ --help, -e: Show this message
14
+
15
+
16
+ $ check_cepmon -c localhost:8989 -r sync_503
17
+ CRITICAL: rule sync_503 has 2 hosts alerting: zlb2_pub (3.93 > 0.1
18
+ 503s/second for 1 min since 2012-03-13/09:51), zlb1_pub (4.13 > 0.1
19
+ 503s/second for 1 min since 2012-03-13/09:51)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/check_cepmon ADDED
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env ruby
2
+ # Nagios plugin to monitor cepmon rules.
3
+
4
+ require "rubygems"
5
+ require "bundler/setup"
6
+
7
+ require "json"
8
+ require "net/http"
9
+ require "trollop"
10
+ require "uri"
11
+
12
+ opts = Trollop::options do
13
+ opt :cepmon, "cepmon host:port",
14
+ :short => "-c", :required => true, :type => :string
15
+ opt :rule, "rule name to filter on",
16
+ :short => "-r", :required => true, :type => :string
17
+ opt :host, "host name to filter on",
18
+ :short => "-h", :type => :string
19
+ end
20
+
21
+ cepmon_uri = URI.join("http://" + opts[:cepmon], "/alerts.json")
22
+ uri_params = { :rule => URI.escape(opts[:rule]) }
23
+ if opts[:host]
24
+ uri_params[:host] = URI.escape(opts[:host])
25
+ end
26
+ cepmon_uri.query = uri_params.collect { |k, v| [k, v].join("=") }.join("&")
27
+
28
+ begin
29
+ alerts_json = Net::HTTP.get_response(cepmon_uri)
30
+ alerts = JSON.parse(alerts_json.body)
31
+ rescue Net::HTTPExceptions
32
+ $stderr.puts "UNKNOWN: error fetching #{cepmon_uri.to_s}: #{$!}"
33
+ exit 3
34
+ rescue JSON::ParserError
35
+ $stderr.puts "UNKNOWN: error parsing JSON from #{cepmon_uri.to_s}: #{$!}"
36
+ exit 3
37
+ end
38
+
39
+ if !alerts.is_a?(Hash) or !alerts["alerts"].is_a?(Array)
40
+ $stderr.puts "UNKNOWN: error parsing JSON from #{cepmon_uri.to_s}: " +
41
+ "missing alerts field"
42
+ exit 3
43
+ end
44
+
45
+ if alerts["alerts"].length == 0
46
+ $stderr.puts "OK: no cepmon alerts"
47
+ exit 0
48
+ end
49
+
50
+ msg = []
51
+ alerts["alerts"].each do |alert|
52
+ since = Time.at(alert['started']).strftime('%F/%R')
53
+ msg << "#{alert['host']} (#{alert['reason']} since #{since})"
54
+ end
55
+
56
+ if opts[:host]
57
+ puts "CRITICAL: rule #{opts[:rule]} alerting: " +
58
+ msg.join(", ")
59
+ else
60
+ puts "CRITICAL: rule #{opts[:rule]} has #{msg.length} " +
61
+ (msg.length > 1 ? "hosts" : "host") + " alerting: " +
62
+ msg.join(", ")
63
+ end
64
+ exit 2
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Pete Fritchman"]
5
+ gem.email = ["petef@databits.net"]
6
+ gem.summary = %q{Nagios plugin to check cepmon rules}
7
+ gem.homepage = "https://github.com/fetep/cepmon-nagios"
8
+
9
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
10
+ gem.files = `git ls-files`.split("\n")
11
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
+ gem.name = "cepmon-nagios"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = "0.1.0"
15
+
16
+ gem.add_runtime_dependency "bundler"
17
+ gem.add_runtime_dependency "json"
18
+ gem.add_runtime_dependency "trollop"
19
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cepmon-nagios
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Pete Fritchman
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-14 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: bundler
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: json
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: trollop
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ description:
64
+ email:
65
+ - petef@databits.net
66
+ executables:
67
+ - check_cepmon
68
+ extensions: []
69
+
70
+ extra_rdoc_files: []
71
+
72
+ files:
73
+ - .gitignore
74
+ - Gemfile
75
+ - Gemfile.lock
76
+ - README.md
77
+ - Rakefile
78
+ - bin/check_cepmon
79
+ - cepmon-nagios.gemspec
80
+ has_rdoc: true
81
+ homepage: https://github.com/fetep/cepmon-nagios
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options: []
86
+
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ requirements: []
108
+
109
+ rubyforge_project:
110
+ rubygems_version: 1.3.7
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Nagios plugin to check cepmon rules
114
+ test_files: []
115
+