nagios_nrdp 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +15 -0
  3. data/Rakefile +11 -1
  4. data/lib/nagios/nrdp.rb +51 -0
  5. metadata +20 -4
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODQ2MGU1NTlhMzNkOTMyZDg2OTZkNjAzZmRhYzUyZjI3Y2I0NjYxOQ==
4
+ MjZmYWQzYzA2N2JiNzJiNmI2MmI0NDIxOTVlYjNjNjc0ZjQ4NmZhOQ==
5
5
  data.tar.gz: !binary |-
6
- YjhmMzI1OGY4ZjE1YjJhZWZmZTZiZjM2ZWQ3NzNkYmQwMDQ5MDNjNg==
6
+ NzcwM2ZlYjMwZDVkYTNmOTVhZTg1Nzc1MzNhYzQ4OGRlNzNhYTRlOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTJkNzUxZGVmNmJjZDhmNzgyZDc1YmZjOWRmNmZlNDI0YmE0MGRkMmU0Njg5
10
- YzMyZWZkNjRkYTRlMjk0NzM2NTc3NzRiZDdmYTMzMGU1ODgxZjAzMDMwMmM4
11
- Y2UyMTg5NDk5MWE4NWEzOTIxMGU3N2IxZGI3ODEyZDliMTM5YTM=
9
+ ZWI5NTNmODJhYzkzNDEyMDBhYzEyNDcwYTkzNmM3ZDhiMDZiMzZjZTRmY2M2
10
+ MThkY2ZmNmFiMGQxZjk2MzQ3OTg3YTlhOThlNzE1YTg0OTkxMTY1N2RjZmI4
11
+ MmQ3MmNjMzE0ZWY2NzFmZDhkZTcyMGM5MDMzMTdhMjkxMjljZjI=
12
12
  data.tar.gz: !binary |-
13
- ODcyOTEzMGU3MzFmNTI2MmQ2NDE0OWI3Y2JhOGJkZDE2MjE5NTJkYzljMjBl
14
- NDkzZjU5ZjU1ODUwNDdjZGFhYTQzZTgxYzAyOTdmYzljODU5MDExMTcwODY1
15
- ZmJlZjY4NzUxYjRkZjkwYjIxNzIzMTNhOWY5NWYwYmZiYmY4MDg=
13
+ MjNlZmM1ZWVjZWU3MjE5NmQxYjEyMzY5YTBkNjhmYzZjYmI1ZjlmYzJhYmVi
14
+ Y2NhYjA3ZjhiMGI2ZDExOTYxY2EzNDBlYmJjMThlZDJhZmU4NWNmNTk3MTdi
15
+ ZTM2NWFlYmIxMTg0ZmEyMmQ3MzNhOTIxNmI2NDU5ZTllNmRjMGU=
data/README.md CHANGED
@@ -44,6 +44,21 @@ nrdp = Nagios::Nrdp.new(url: url, token: token)
44
44
  nrdp.submit_check(hostname: hostname, servicename: servicename, state: state.to_i, output: output)
45
45
  ```
46
46
 
47
+ * Send multiple passive checks:
48
+
49
+ ```ruby
50
+ require 'nagios_nrdp'
51
+
52
+ url = 'http://some.host/nrdp'
53
+ token = 'your token'
54
+ checks = [{ hostname: 'host1', state: 1, output: 'DOWN' },
55
+ { hostname: 'host2', state: 0, output: 'UP' }]
56
+
57
+ nrdp = Nagios::Nrdp.new(url: url, token: token)
58
+ nrdp.submit_checks(checks)
59
+ ```
60
+
61
+
47
62
  * Send a command:
48
63
 
49
64
  ```ruby
data/Rakefile CHANGED
@@ -3,6 +3,7 @@ require 'rake'
3
3
  require 'rspec/core/rake_task'
4
4
  require 'bundler/gem_tasks'
5
5
  require 'rubocop/rake_task'
6
+ require 'yard'
6
7
 
7
8
  task :default => :test
8
9
 
@@ -19,7 +20,7 @@ begin
19
20
  Jeweler::Tasks.new do |gem|
20
21
  gem.name = 'nagios_nrdp'
21
22
  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.description = 'A pure ruby implementation of an NRDP client for submitting passive checks and commands to Nagios through NRDP.'
23
24
  gem.email = 'stjeanp@pat-st-jean.com'
24
25
  gem.homepage = 'http://github.com/stjeanp/nrdp'
25
26
  gem.authors = ['stjeanp']
@@ -27,12 +28,21 @@ begin
27
28
  gem.files = %w(README.md Rakefile) + Dir['lib/**/*'] + Dir['spec/**/*']
28
29
  gem.test_files = Dir['spec/**/*']
29
30
  gem.licenses = ['MIT']
31
+ gem.required_ruby_version = '>= 1.9.3'
30
32
  end
31
33
  Jeweler::GemcutterTasks.new
32
34
  rescue LoadError
33
35
  puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
34
36
  end
35
37
 
38
+ # Include Yard tasks for rake yard
39
+ YARDOC_LOCATION = "doc"
40
+ YARD::Rake::YardocTask.new do |t|
41
+ t.files = ['lib/**/*.rb', "README"]
42
+ t.options = ["--output-dir", YARDOC_LOCATION, "--title", "nagios_nrdp "]
43
+ #t.stats_options = ["--list-undoc"]
44
+ end
45
+
36
46
  desc "Run syntax, lint, and rspec tests..."
37
47
  task :test => [
38
48
  :rubocop,
@@ -2,13 +2,29 @@ require 'net/http'
2
2
  require 'uri'
3
3
  require 'nokogiri'
4
4
 
5
+ # The parent, trying to keep the class tree clean
5
6
  module Nagios
6
7
  # Implements an interface to Nagios NRDP to facilitate submitting check
7
8
  # results and commands
9
+ #
10
+ # @see https://assets.nagios.com/downloads/nrdp/docs/NRDP_Overview.pdf
8
11
  class Nrdp
12
+ # @!attribute [rw] url
13
+ # The URL of the NRDP endpoint
14
+ # @return [String] the URL of the NRDP endpoint
9
15
  attr_accessor :url
16
+ # @!attribute [rw] token
17
+ # The authentication token
18
+ # @return [String] the authentication token
10
19
  attr_accessor :token
11
20
 
21
+ # Create a new instance of Nagios::Nrdp and set the URL and token
22
+ #
23
+ # @param [Hash] args parameters for this instance
24
+ # @option args [String] :url the URL of the NRDP endpoint
25
+ # @option args [String] :token the authentication token
26
+ #
27
+ # @raise [ArgumentError] when the args fail validation
12
28
  def initialize(args = {})
13
29
  @url = args[:url] || nil
14
30
  @token = args[:token] || nil
@@ -23,6 +39,17 @@ module Nagios
23
39
  fail ArgumentError, 'The token supplied is invalid!' unless @token && !@token.empty?
24
40
  end
25
41
 
42
+ # @overload submit_check(the_check)
43
+ # Submit a single passive check result
44
+ # @param [Hash] the_check the passive check result data
45
+ # @option the_check [String] :hostname The hostname for this passive check
46
+ # @option the_check [String] :servicename The optional service name for this passive check
47
+ # @option the_check [Integer] :state The state of this passive check
48
+ # @option the_check [String] :output The output of this passive check
49
+ # @raise [RuntimeError] when the submission fails
50
+ # @overload submit_check(the_checks)
51
+ # @param [Array<Hash>] the_checks an array of passive check results
52
+ # @raise [RuntimeError] when the submission fails
26
53
  def submit_check(*args)
27
54
  if args[0].is_a? Hash
28
55
  the_checks = [args[0]]
@@ -66,6 +93,12 @@ module Nagios
66
93
  end
67
94
  alias_method :submit_checks, :submit_check
68
95
 
96
+ # Submit a Nagios command
97
+ #
98
+ # @param [String] the_command the command to be submitted
99
+ #
100
+ # @raise [ArgumentError] when the args fail validation
101
+ # @raise [RuntimeError] when the submission fails
69
102
  def submit_command(the_command = '')
70
103
  if !the_command || !the_command.is_a?(String) || the_command.empty?
71
104
  fail ArgumentError, 'Invalid command supplied!'
@@ -98,6 +131,17 @@ module Nagios
98
131
 
99
132
  private
100
133
 
134
+ # Validate the supplied check's data
135
+ #
136
+ # @api private
137
+ #
138
+ # @param [Hash] the_check the passive check result data
139
+ # @option the_check [String] :hostname The hostname for this passive check
140
+ # @option the_check [String] :servicename The optional service name for this passive check
141
+ # @option the_check [Integer] :state The state of this passive check
142
+ # @option the_check [String] :output The output of this passive check
143
+ #
144
+ # @raise [ArgumentError] when validation fails
101
145
  def validate_check(the_check = {})
102
146
  fail ArgumentError, 'Unknown parameters in check!' unless the_check.keys.all? { |key| [:hostname, :servicename, :state, :output].include? key }
103
147
  if [:hostname, :state, :output].any? { |key| !the_check.key?(key) }
@@ -106,6 +150,13 @@ module Nagios
106
150
  fail ArgumentError, "Check's state must be an integer!" unless the_check[:state].is_a? Integer
107
151
  end
108
152
 
153
+ # Create the XML document containing the passive check results
154
+ #
155
+ # @param [Array<Hash>] the_checks the array of passive check results
156
+ #
157
+ # @return [String] the XML document to be submitted
158
+ #
159
+ # @raise [ArgumentError] when the checks aren't valid
109
160
  def build_xml(the_checks = [])
110
161
  if the_checks.nil? || the_checks.count < 1
111
162
  fail ArgumentError, 'You must send at least one check!'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagios_nrdp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - stjeanp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-29 00:00:00.000000000 Z
11
+ date: 2015-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -138,7 +138,23 @@ dependencies:
138
138
  - !ruby/object:Gem::Version
139
139
  version: !binary |-
140
140
  MC44
141
- description: A pure ruby implementation an NRDP client for submitting passive checks
141
+ - !ruby/object:Gem::Dependency
142
+ name: yard
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ~>
146
+ - !ruby/object:Gem::Version
147
+ version: !binary |-
148
+ MC44
149
+ type: :development
150
+ prerelease: false
151
+ version_requirements: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ~>
154
+ - !ruby/object:Gem::Version
155
+ version: !binary |-
156
+ MC44
157
+ description: A pure ruby implementation of an NRDP client for submitting passive checks
142
158
  and commands to Nagios through NRDP.
143
159
  email: stjeanp@pat-st-jean.com
144
160
  executables: []
@@ -165,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
181
  requirements:
166
182
  - - ! '>='
167
183
  - !ruby/object:Gem::Version
168
- version: '0'
184
+ version: 1.9.3
169
185
  required_rubygems_version: !ruby/object:Gem::Requirement
170
186
  requirements:
171
187
  - - ! '>='