nagios_nrdp 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +66 -0
- data/Rakefile +40 -0
- data/lib/nagios/nrdp.rb +132 -0
- data/lib/nagios_nrdp.rb +4 -0
- data/spec/lib/nrdp_spec.rb +299 -0
- data/spec/spec.opts +8 -0
- data/spec/spec_helper.rb +7 -0
- metadata +183 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODQ2MGU1NTlhMzNkOTMyZDg2OTZkNjAzZmRhYzUyZjI3Y2I0NjYxOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YjhmMzI1OGY4ZjE1YjJhZWZmZTZiZjM2ZWQ3NzNkYmQwMDQ5MDNjNg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YTJkNzUxZGVmNmJjZDhmNzgyZDc1YmZjOWRmNmZlNDI0YmE0MGRkMmU0Njg5
|
10
|
+
YzMyZWZkNjRkYTRlMjk0NzM2NTc3NzRiZDdmYTMzMGU1ODgxZjAzMDMwMmM4
|
11
|
+
Y2UyMTg5NDk5MWE4NWEzOTIxMGU3N2IxZGI3ODEyZDliMTM5YTM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODcyOTEzMGU3MzFmNTI2MmQ2NDE0OWI3Y2JhOGJkZDE2MjE5NTJkYzljMjBl
|
14
|
+
NDkzZjU5ZjU1ODUwNDdjZGFhYTQzZTgxYzAyOTdmYzljODU5MDExMTcwODY1
|
15
|
+
ZmJlZjY4NzUxYjRkZjkwYjIxNzIzMTNhOWY5NWYwYmZiYmY4MDg=
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Nagios::Nrdp
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/stjeanp/nagios_nrdp.svg?branch=master)](https://travis-ci.org/stjeanp/nagios_nrdp) [![Coverage Status](https://coveralls.io/repos/stjeanp/nagios_nrdp/badge.svg?branch=master&service=github)](https://coveralls.io/github/stjeanp/nagios_nrdp?branch=master)
|
4
|
+
|
5
|
+
## About
|
6
|
+
|
7
|
+
The Nagios::Nrdp module provides the ability to submit passive check results and commands to a Nagios server using [NRDP](https://exchange.nagios.org/directory/Addons/Passive-Checks/NRDP--2D-Nagios-Remote-Data-Processor/details). It currenly only supports token based authentication.
|
8
|
+
|
9
|
+
## Installation Instructions
|
10
|
+
|
11
|
+
1. Install and configure [NRDP](https://exchange.nagios.org/directory/Addons/Passive-Checks/NRDP--2D-Nagios-Remote-Data-Processor/details).
|
12
|
+
2. `gem install nagios_nrdp`
|
13
|
+
|
14
|
+
## Basic Usage
|
15
|
+
|
16
|
+
* Send a host passive check
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
require 'nagios_nrdp'
|
20
|
+
|
21
|
+
url = 'http://some.host/nrdp'
|
22
|
+
token = 'your token'
|
23
|
+
hostname = 'hostname'
|
24
|
+
state = 1
|
25
|
+
output = 'DOWN'
|
26
|
+
|
27
|
+
nrdp = Nagios::Nrdp.new(url: url, token: token)
|
28
|
+
nrdp.submit_check(hostname: hostname, state: state.to_i, output: output)
|
29
|
+
```
|
30
|
+
|
31
|
+
* Send a service passive check:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'nagios_nrdp'
|
35
|
+
|
36
|
+
url = 'http://some.host/nrdp'
|
37
|
+
token = 'your token'
|
38
|
+
hostname = 'hostname'
|
39
|
+
servicename = 'service'
|
40
|
+
state = 1
|
41
|
+
output = 'DOWN'
|
42
|
+
|
43
|
+
nrdp = Nagios::Nrdp.new(url: url, token: token)
|
44
|
+
nrdp.submit_check(hostname: hostname, servicename: servicename, state: state.to_i, output: output)
|
45
|
+
```
|
46
|
+
|
47
|
+
* Send a command:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
require 'nagios_nrdp'
|
51
|
+
|
52
|
+
url = 'http://some.host/nrdp'
|
53
|
+
token = 'your token'
|
54
|
+
command = 'COMMAND;hostname'
|
55
|
+
|
56
|
+
nrdp = Nagios::Nrdp.new(url: url, token: token)
|
57
|
+
nrdp.submit_command(command)
|
58
|
+
```
|
59
|
+
|
60
|
+
## Contributing
|
61
|
+
|
62
|
+
1. Fork it ( https://github.com/stjeanp/nagios_nrdp/fork )
|
63
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
64
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
65
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
66
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
|
7
|
+
task :default => :test
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
10
|
+
|
11
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
12
|
+
task.patterns = ['lib/**/*.rb', 'examples/**/*.rb']
|
13
|
+
task.formatters = ['files']
|
14
|
+
task.fail_on_error = true
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
require 'jeweler'
|
19
|
+
Jeweler::Tasks.new do |gem|
|
20
|
+
gem.name = 'nagios_nrdp'
|
21
|
+
gem.summary = 'A ruby gem for submitting passive checks and commands to Nagios through NRDP.'
|
22
|
+
gem.description = 'A pure ruby implementation an NRDP client for submitting passive checks and commands to Nagios through NRDP.'
|
23
|
+
gem.email = 'stjeanp@pat-st-jean.com'
|
24
|
+
gem.homepage = 'http://github.com/stjeanp/nrdp'
|
25
|
+
gem.authors = ['stjeanp']
|
26
|
+
gem.require_path = 'lib'
|
27
|
+
gem.files = %w(README.md Rakefile) + Dir['lib/**/*'] + Dir['spec/**/*']
|
28
|
+
gem.test_files = Dir['spec/**/*']
|
29
|
+
gem.licenses = ['MIT']
|
30
|
+
end
|
31
|
+
Jeweler::GemcutterTasks.new
|
32
|
+
rescue LoadError
|
33
|
+
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Run syntax, lint, and rspec tests..."
|
37
|
+
task :test => [
|
38
|
+
:rubocop,
|
39
|
+
:spec,
|
40
|
+
]
|
data/lib/nagios/nrdp.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
module Nagios
|
6
|
+
# Implements an interface to Nagios NRDP to facilitate submitting check
|
7
|
+
# results and commands
|
8
|
+
class Nrdp
|
9
|
+
attr_accessor :url
|
10
|
+
attr_accessor :token
|
11
|
+
|
12
|
+
def initialize(args = {})
|
13
|
+
@url = args[:url] || nil
|
14
|
+
@token = args[:token] || nil
|
15
|
+
|
16
|
+
fail ArgumentError, 'The URL supplied is invalid!' unless @url && !@url.empty?
|
17
|
+
begin
|
18
|
+
the_uri = URI.parse(url)
|
19
|
+
fail ArgumentError, 'The URL supplied is invalid!' unless the_uri.is_a? URI::HTTP
|
20
|
+
rescue URI::InvalidURIError
|
21
|
+
raise ArgumentError, 'The URL supplied is invalid!'
|
22
|
+
end
|
23
|
+
fail ArgumentError, 'The token supplied is invalid!' unless @token && !@token.empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
def submit_check(*args)
|
27
|
+
if args[0].is_a? Hash
|
28
|
+
the_checks = [args[0]]
|
29
|
+
else
|
30
|
+
the_checks = args[0]
|
31
|
+
end
|
32
|
+
|
33
|
+
payload = build_xml(the_checks)
|
34
|
+
|
35
|
+
the_uri = URI.parse(@url)
|
36
|
+
http = Net::HTTP.new(the_uri.host, the_uri.port)
|
37
|
+
if the_uri.scheme == 'https'
|
38
|
+
http.use_ssl = true
|
39
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
40
|
+
end
|
41
|
+
request = Net::HTTP::Post.new(the_uri.request_uri + '/')
|
42
|
+
request.set_form_data(token: token, cmd: 'submitcheck', XMLDATA: payload)
|
43
|
+
request['Accept'] = 'text/*'
|
44
|
+
request['User-Agent'] = 'NrdpClient/1.0'
|
45
|
+
response = http.request(request)
|
46
|
+
|
47
|
+
if response.code != '200'
|
48
|
+
fail "Didn't get a 200 (" + response.code.to_s + ')'
|
49
|
+
end
|
50
|
+
|
51
|
+
doc = Nokogiri::XML(response.body)
|
52
|
+
|
53
|
+
status = doc.xpath('//status').first.content.to_i
|
54
|
+
message = doc.xpath('//message').first.content
|
55
|
+
|
56
|
+
fail "Status isn't 0 (" + message + ')' unless status == 0
|
57
|
+
|
58
|
+
count_agrees = false
|
59
|
+
doc.xpath('//output').each do |output|
|
60
|
+
if output.content == "#{the_checks.count} checks processed."
|
61
|
+
count_agrees = true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
fail 'Not all notifications were processed!' unless count_agrees
|
65
|
+
true
|
66
|
+
end
|
67
|
+
alias_method :submit_checks, :submit_check
|
68
|
+
|
69
|
+
def submit_command(the_command = '')
|
70
|
+
if !the_command || !the_command.is_a?(String) || the_command.empty?
|
71
|
+
fail ArgumentError, 'Invalid command supplied!'
|
72
|
+
end
|
73
|
+
|
74
|
+
the_uri = URI.parse(@url)
|
75
|
+
http = Net::HTTP.new(the_uri.host, the_uri.port)
|
76
|
+
if the_uri.scheme == 'https'
|
77
|
+
http.use_ssl = true
|
78
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
79
|
+
end
|
80
|
+
query = "?token=#{token}&cmd=submitcmd&command=#{the_command}"
|
81
|
+
request = Net::HTTP::Get.new(the_uri.request_uri + '/' + query)
|
82
|
+
request['Accept'] = 'text/*'
|
83
|
+
request['User-Agent'] = 'NrdpClient/1.0'
|
84
|
+
response = http.request(request)
|
85
|
+
|
86
|
+
if response.code != '200'
|
87
|
+
fail "Didn't get a 200 (" + response.code.to_s + ')'
|
88
|
+
end
|
89
|
+
|
90
|
+
doc = Nokogiri::XML(response.body)
|
91
|
+
|
92
|
+
status = doc.xpath('//status').first.content.to_i
|
93
|
+
message = doc.xpath('//message').first.content
|
94
|
+
|
95
|
+
fail "Status isn't 0 (" + message + ')' unless status == 0
|
96
|
+
true
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def validate_check(the_check = {})
|
102
|
+
fail ArgumentError, 'Unknown parameters in check!' unless the_check.keys.all? { |key| [:hostname, :servicename, :state, :output].include? key }
|
103
|
+
if [:hostname, :state, :output].any? { |key| !the_check.key?(key) }
|
104
|
+
fail ArgumentError, 'You must provide all check details!'
|
105
|
+
end
|
106
|
+
fail ArgumentError, "Check's state must be an integer!" unless the_check[:state].is_a? Integer
|
107
|
+
end
|
108
|
+
|
109
|
+
def build_xml(the_checks = [])
|
110
|
+
if the_checks.nil? || the_checks.count < 1
|
111
|
+
fail ArgumentError, 'You must send at least one check!'
|
112
|
+
end
|
113
|
+
|
114
|
+
the_xml = "<?xml version='1.0'?>\n"
|
115
|
+
the_xml += "<checkresults>\n"
|
116
|
+
the_checks.each do |check|
|
117
|
+
validate_check(check)
|
118
|
+
the_xml += " <checkresult type='"
|
119
|
+
the_xml += check[:servicename] ? 'service' : 'host'
|
120
|
+
the_xml += "'>\n"
|
121
|
+
the_xml += ' <hostname>' + check[:hostname] + "</hostname>\n"
|
122
|
+
if check[:servicename]
|
123
|
+
the_xml += ' <servicename>' + check[:servicename] + "</servicename>\n"
|
124
|
+
end
|
125
|
+
the_xml += ' <state>' + check[:state].to_s + "</state>\n"
|
126
|
+
the_xml += ' <output>' + check[:output] + "</output>\n"
|
127
|
+
the_xml += " </checkresult>\n"
|
128
|
+
end
|
129
|
+
the_xml += "</checkresults>\n"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
data/lib/nagios_nrdp.rb
ADDED
@@ -0,0 +1,299 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Nagios::Nrdp do
|
4
|
+
it '#initialize should raise an error without no args' do
|
5
|
+
expect { Nagios::Nrdp.new }.to raise_error(ArgumentError)
|
6
|
+
end
|
7
|
+
|
8
|
+
it '#initialize should raise an error without a token' do
|
9
|
+
expect { Nagios::Nrdp.new(url: 'http://localhost/nrdp') }.to raise_error(ArgumentError)
|
10
|
+
end
|
11
|
+
|
12
|
+
it '#initialize should raise an error without a URL' do
|
13
|
+
expect { Nagios::Nrdp.new(token: 'foobar') }.to raise_error(ArgumentError)
|
14
|
+
end
|
15
|
+
|
16
|
+
it '#initialize should raise an error with an invalid URL' do
|
17
|
+
expect { Nagios::Nrdp.new(url: 'httq::\\/localhost/nrdp', token: 'foobar') }.to raise_error(ArgumentError)
|
18
|
+
end
|
19
|
+
|
20
|
+
it '#initialize should raise an error with an invalid token' do
|
21
|
+
expect { Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: '') }.to raise_error(ArgumentError)
|
22
|
+
end
|
23
|
+
|
24
|
+
it '#initialize' do
|
25
|
+
expect(Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')).to be_an_instance_of Nagios::Nrdp
|
26
|
+
end
|
27
|
+
|
28
|
+
it '#submit_check should alert on missing hostname parameter' do
|
29
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
30
|
+
expect { nrdp.submit_check(state: 0, output: 'UP') }.to raise_error(ArgumentError)
|
31
|
+
end
|
32
|
+
|
33
|
+
it '#submit_check should alert on missing state parameter' do
|
34
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
35
|
+
expect { nrdp.submit_check(hostname: 'foobar', output: 'UP') }.to raise_error(ArgumentError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it '#submit_check should alert on missing output parameter' do
|
39
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
40
|
+
expect { nrdp.submit_check(hostname: 'foobar', state: 0) }.to raise_error(ArgumentError)
|
41
|
+
end
|
42
|
+
|
43
|
+
it '#submit_check should alert on unknown parameter' do
|
44
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
45
|
+
expect { nrdp.submit_check(hostname: 'foobar', state: 0, output: 'UP', blarg: 'blop') }.to raise_error(ArgumentError)
|
46
|
+
end
|
47
|
+
|
48
|
+
it '#submit_check should alert when called with no args' do
|
49
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
50
|
+
expect { nrdp.submit_check }.to raise_error(ArgumentError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it '#submit_check should alert when called with an empty hash' do
|
54
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
55
|
+
expect { nrdp.submit_check({}) }.to raise_error(ArgumentError)
|
56
|
+
end
|
57
|
+
|
58
|
+
it '#submit_check should alert when called with an empty array' do
|
59
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
60
|
+
expect { nrdp.submit_check([]) }.to raise_error(ArgumentError)
|
61
|
+
end
|
62
|
+
|
63
|
+
it '#submit_check, single, host, successful' do
|
64
|
+
body = <<-EOXML
|
65
|
+
<result>
|
66
|
+
<status>0</status>
|
67
|
+
<message>OK</message>
|
68
|
+
<meta>
|
69
|
+
<output>1 checks processed.</output>
|
70
|
+
</meta>
|
71
|
+
</result>
|
72
|
+
EOXML
|
73
|
+
stub_request(:post, 'http://localhost/nrdp/').to_return(body: body, status: 200)
|
74
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
75
|
+
expect(nrdp.submit_check(hostname: 'foobar', state: 0, output: 'UP')).to eq(true)
|
76
|
+
WebMock.reset!
|
77
|
+
end
|
78
|
+
|
79
|
+
it '#submit_check, single, ssl, host, successful' do
|
80
|
+
body = <<-EOXML
|
81
|
+
<result>
|
82
|
+
<status>0</status>
|
83
|
+
<message>OK</message>
|
84
|
+
<meta>
|
85
|
+
<output>1 checks processed.</output>
|
86
|
+
</meta>
|
87
|
+
</result>
|
88
|
+
EOXML
|
89
|
+
stub_request(:post, 'https://localhost/nrdp/').to_return(body: body, status: 200)
|
90
|
+
nrdp = Nagios::Nrdp.new(url: 'https://localhost/nrdp', token: 'foobar')
|
91
|
+
expect(nrdp.submit_check(hostname: 'foobar', state: 0, output: 'UP')).to eq(true)
|
92
|
+
WebMock.reset!
|
93
|
+
end
|
94
|
+
|
95
|
+
it '#submit_check, 404 error' do
|
96
|
+
body = "404: NOT FOUND"
|
97
|
+
stub_request(:post, 'http://localhost/nrdp/').to_return(body: body, status: 404)
|
98
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
99
|
+
expect { nrdp.submit_check(hostname: 'foobar', state: 0, output: 'UP') }.to raise_error(RuntimeError)
|
100
|
+
WebMock.reset!
|
101
|
+
end
|
102
|
+
|
103
|
+
it '#submit_check, single, service, successful' do
|
104
|
+
body = <<-EOXML
|
105
|
+
<result>
|
106
|
+
<status>0</status>
|
107
|
+
<message>OK</message>
|
108
|
+
<meta>
|
109
|
+
<output>1 checks processed.</output>
|
110
|
+
</meta>
|
111
|
+
</result>
|
112
|
+
EOXML
|
113
|
+
stub_request(:post, 'http://localhost/nrdp/').to_return(body: body, status: 200)
|
114
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
115
|
+
expect(nrdp.submit_check(hostname: 'foobar', servicename: 'something', state: 0, output: 'UP')).to eq(true)
|
116
|
+
WebMock.reset!
|
117
|
+
end
|
118
|
+
|
119
|
+
it '#submit_check, single, host, failed' do
|
120
|
+
body = <<-EOXML
|
121
|
+
<result>
|
122
|
+
<status>-1</status>
|
123
|
+
<message>NO DATA</message>
|
124
|
+
</result>
|
125
|
+
EOXML
|
126
|
+
stub_request(:post, 'http://localhost/nrdp/').to_return(body: body, status: 200)
|
127
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
128
|
+
expect { nrdp.submit_check(hostname: 'foobar', state: 0, output: 'UP') }.to raise_error(RuntimeError)
|
129
|
+
WebMock.reset!
|
130
|
+
end
|
131
|
+
|
132
|
+
it '#submit_check, single, service, failed' do
|
133
|
+
body = <<-EOXML
|
134
|
+
<result>
|
135
|
+
<status>-1</status>
|
136
|
+
<message>NO DATA</message>
|
137
|
+
</result>
|
138
|
+
EOXML
|
139
|
+
stub_request(:post, 'http://localhost/nrdp/').to_return(body: body, status: 200)
|
140
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
141
|
+
expect { nrdp.submit_check(hostname: 'foobar', servicename: 'blarg', state: 0, output: 'UP') }.to raise_error(RuntimeError)
|
142
|
+
WebMock.reset!
|
143
|
+
end
|
144
|
+
|
145
|
+
it '#submit_check, single, wrong count' do
|
146
|
+
body = <<-EOXML
|
147
|
+
<result>
|
148
|
+
<status>0</status>
|
149
|
+
<message>OK</message>
|
150
|
+
<meta>
|
151
|
+
<output>2 checks processed.</output>
|
152
|
+
</meta>
|
153
|
+
</result>
|
154
|
+
EOXML
|
155
|
+
stub_request(:post, 'http://localhost/nrdp/').to_return(body: body, status: 200)
|
156
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
157
|
+
expect { nrdp.submit_check(hostname: 'foobar', state: 0, output: 'UP') }.to raise_error(RuntimeError)
|
158
|
+
WebMock.reset!
|
159
|
+
end
|
160
|
+
|
161
|
+
it '#submit_check, multiple, all host, successful' do
|
162
|
+
body = <<-EOXML
|
163
|
+
<result>
|
164
|
+
<status>0</status>
|
165
|
+
<message>OK</message>
|
166
|
+
<meta>
|
167
|
+
<output>2 checks processed.</output>
|
168
|
+
</meta>
|
169
|
+
</result>
|
170
|
+
EOXML
|
171
|
+
stub_request(:post, 'http://localhost/nrdp/').to_return(body: body, status: 200)
|
172
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
173
|
+
checks = [{ hostname: 'foobar', state: 1, output: 'testing' },
|
174
|
+
{ hostname: 'foobarbaz', state: 0, output: 'moar testing' }]
|
175
|
+
expect(nrdp.submit_check(checks)).to eq(true)
|
176
|
+
WebMock.reset!
|
177
|
+
end
|
178
|
+
|
179
|
+
it '#submit_check, multiple, all service, successful' do
|
180
|
+
body = <<-EOXML
|
181
|
+
<result>
|
182
|
+
<status>0</status>
|
183
|
+
<message>OK</message>
|
184
|
+
<meta>
|
185
|
+
<output>2 checks processed.</output>
|
186
|
+
</meta>
|
187
|
+
</result>
|
188
|
+
EOXML
|
189
|
+
stub_request(:post, 'http://localhost/nrdp/').to_return(body: body, status: 200)
|
190
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
191
|
+
checks = [{ hostname: 'foobar', servicename: 'the_service', state: 1, output: 'testing' },
|
192
|
+
{ hostname: 'foobarbaz', servicename: 'another_service', state: 0, output: 'moar testing' }]
|
193
|
+
expect(nrdp.submit_check(checks)).to eq(true)
|
194
|
+
WebMock.reset!
|
195
|
+
end
|
196
|
+
|
197
|
+
it '#submit_check, multiple, mixed host/service, successful' do
|
198
|
+
body = <<-EOXML
|
199
|
+
<result>
|
200
|
+
<status>0</status>
|
201
|
+
<message>OK</message>
|
202
|
+
<meta>
|
203
|
+
<output>2 checks processed.</output>
|
204
|
+
</meta>
|
205
|
+
</result>
|
206
|
+
EOXML
|
207
|
+
stub_request(:post, 'http://localhost/nrdp/').to_return(body: body, status: 200)
|
208
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
209
|
+
checks = [{ hostname: 'foobar', servicename: 'the_service', state: 1, output: 'testing' },
|
210
|
+
{ hostname: 'foobarbaz', state: 0, output: 'moar testing' }]
|
211
|
+
expect(nrdp.submit_check(checks)).to eq(true)
|
212
|
+
WebMock.reset!
|
213
|
+
end
|
214
|
+
|
215
|
+
it '#submit_check, multiple, failed' do
|
216
|
+
body = <<-EOXML
|
217
|
+
<result>
|
218
|
+
<status>-1</status>
|
219
|
+
<message>BAD XML</message>
|
220
|
+
</result>
|
221
|
+
EOXML
|
222
|
+
stub_request(:post, 'http://localhost/nrdp/').to_return(body: body, status: 200)
|
223
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
224
|
+
checks = [{ hostname: 'foobar', servicename: 'the_service', state: 1, output: 'testing' },
|
225
|
+
{ hostname: 'foobarbaz', state: 0, output: 'moar testing' }]
|
226
|
+
expect { nrdp.submit_check(checks) }.to raise_error(RuntimeError)
|
227
|
+
WebMock.reset!
|
228
|
+
end
|
229
|
+
|
230
|
+
it '#submit_check, multiple, wrong count' do
|
231
|
+
body = <<-EOXML
|
232
|
+
<result>
|
233
|
+
<status>0</status>
|
234
|
+
<message>OK</message>
|
235
|
+
<meta>
|
236
|
+
<output>3 checks processed.</output>
|
237
|
+
</meta>
|
238
|
+
</result>
|
239
|
+
EOXML
|
240
|
+
stub_request(:post, 'http://localhost/nrdp/').to_return(body: body, status: 200)
|
241
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
242
|
+
checks = [{ hostname: 'foobar', servicename: 'the_service', state: 1, output: 'testing' },
|
243
|
+
{ hostname: 'foobarbaz', state: 0, output: 'moar testing' }]
|
244
|
+
expect { nrdp.submit_check(checks) }.to raise_error(RuntimeError)
|
245
|
+
WebMock.reset!
|
246
|
+
end
|
247
|
+
|
248
|
+
it '#submit_command should alert on missing command' do
|
249
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
250
|
+
expect { nrdp.submit_command }.to raise_error(ArgumentError)
|
251
|
+
end
|
252
|
+
|
253
|
+
it '#submit_command' do
|
254
|
+
body = <<-EOXML
|
255
|
+
<result>
|
256
|
+
<status>0</status>
|
257
|
+
<message>OK</message>
|
258
|
+
</result>
|
259
|
+
EOXML
|
260
|
+
stub_request(:get, 'http://localhost/nrdp/?cmd=submitcmd&command=DISABLE_HOST_NOTIFICATIONS%3Bfoobar&token=foobar').to_return(body: body, status: 200)
|
261
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
262
|
+
expect(nrdp.submit_command('DISABLE_HOST_NOTIFICATIONS;foobar')).to eq(true)
|
263
|
+
WebMock.reset!
|
264
|
+
end
|
265
|
+
|
266
|
+
it '#submit_command, ssl' do
|
267
|
+
body = <<-EOXML
|
268
|
+
<result>
|
269
|
+
<status>0</status>
|
270
|
+
<message>OK</message>
|
271
|
+
</result>
|
272
|
+
EOXML
|
273
|
+
stub_request(:get, 'https://localhost/nrdp/?cmd=submitcmd&command=DISABLE_HOST_NOTIFICATIONS%3Bfoobar&token=foobar').to_return(body: body, status: 200)
|
274
|
+
nrdp = Nagios::Nrdp.new(url: 'https://localhost/nrdp', token: 'foobar')
|
275
|
+
expect(nrdp.submit_command('DISABLE_HOST_NOTIFICATIONS;foobar')).to eq(true)
|
276
|
+
WebMock.reset!
|
277
|
+
end
|
278
|
+
|
279
|
+
it '#submit_command, failure' do
|
280
|
+
body = <<-EOXML
|
281
|
+
<result>
|
282
|
+
<status>-1</status>
|
283
|
+
<message>NO COMMAND</message>
|
284
|
+
</result>
|
285
|
+
EOXML
|
286
|
+
stub_request(:get, 'http://localhost/nrdp/?cmd=submitcmd&command=DISABLE_HOST_NOTIFICATIONS%3Bfoobar&token=foobar').to_return(body: body, status: 200)
|
287
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
288
|
+
expect { nrdp.submit_command('DISABLE_HOST_NOTIFICATIONS;foobar') }.to raise_error(RuntimeError)
|
289
|
+
WebMock.reset!
|
290
|
+
end
|
291
|
+
|
292
|
+
it '#submit_command, 404 error' do
|
293
|
+
body = "404: NOT FOUND"
|
294
|
+
stub_request(:get, 'http://localhost/nrdp/?cmd=submitcmd&command=DISABLE_HOST_NOTIFICATIONS%3Bfoobar&token=foobar').to_return(body: body, status: 404)
|
295
|
+
nrdp = Nagios::Nrdp.new(url: 'http://localhost/nrdp', token: 'foobar')
|
296
|
+
expect { nrdp.submit_command('DISABLE_HOST_NOTIFICATIONS;foobar') }.to raise_error(RuntimeError)
|
297
|
+
WebMock.reset!
|
298
|
+
end
|
299
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nagios_nrdp
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- stjeanp
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: !binary |-
|
20
|
+
MS42
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: !binary |-
|
28
|
+
MS42
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: rake
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: !binary |-
|
36
|
+
MTAuNA==
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: !binary |-
|
44
|
+
MTAuNA==
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: rubocop
|
47
|
+
requirement: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ~>
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: !binary |-
|
52
|
+
MC4zMA==
|
53
|
+
type: :development
|
54
|
+
prerelease: false
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: !binary |-
|
60
|
+
MC4zMA==
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: !binary |-
|
68
|
+
My4z
|
69
|
+
type: :development
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: !binary |-
|
76
|
+
My4z
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: rspec-core
|
79
|
+
requirement: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ~>
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: !binary |-
|
84
|
+
My4z
|
85
|
+
type: :development
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ~>
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: !binary |-
|
92
|
+
My4z
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: webmock
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ~>
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: !binary |-
|
100
|
+
MS4yMQ==
|
101
|
+
type: :development
|
102
|
+
prerelease: false
|
103
|
+
version_requirements: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ~>
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: !binary |-
|
108
|
+
MS4yMQ==
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: jeweler
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ~>
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: !binary |-
|
116
|
+
Mi4w
|
117
|
+
type: :development
|
118
|
+
prerelease: false
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ~>
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: !binary |-
|
124
|
+
Mi4w
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: coveralls
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: !binary |-
|
132
|
+
MC44
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ~>
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: !binary |-
|
140
|
+
MC44
|
141
|
+
description: A pure ruby implementation an NRDP client for submitting passive checks
|
142
|
+
and commands to Nagios through NRDP.
|
143
|
+
email: stjeanp@pat-st-jean.com
|
144
|
+
executables: []
|
145
|
+
extensions: []
|
146
|
+
extra_rdoc_files:
|
147
|
+
- README.md
|
148
|
+
files:
|
149
|
+
- README.md
|
150
|
+
- Rakefile
|
151
|
+
- lib/nagios/nrdp.rb
|
152
|
+
- lib/nagios_nrdp.rb
|
153
|
+
- spec/lib/nrdp_spec.rb
|
154
|
+
- spec/spec.opts
|
155
|
+
- spec/spec_helper.rb
|
156
|
+
homepage: http://github.com/stjeanp/nrdp
|
157
|
+
licenses:
|
158
|
+
- MIT
|
159
|
+
metadata: {}
|
160
|
+
post_install_message:
|
161
|
+
rdoc_options: []
|
162
|
+
require_paths:
|
163
|
+
- lib
|
164
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ! '>='
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
requirements: []
|
175
|
+
rubyforge_project:
|
176
|
+
rubygems_version: 2.4.8
|
177
|
+
signing_key:
|
178
|
+
specification_version: 4
|
179
|
+
summary: A ruby gem for submitting passive checks and commands to Nagios through NRDP.
|
180
|
+
test_files:
|
181
|
+
- spec/lib/nrdp_spec.rb
|
182
|
+
- spec/spec.opts
|
183
|
+
- spec/spec_helper.rb
|