Class: IcingaRest::ServiceCheck
- Inherits:
-
Object
- Object
- IcingaRest::ServiceCheck
- Defined in:
- lib/icinga_rest/service_check.rb
Overview
Class to count services in a given state, optionally filtered by host name, either as a pattern (‘foo*’, or ‘foo’), or as an exact match (‘foobar’)
Constant Summary collapse
- SERVICE_STATES =
{ :ok => 0, :warn => 1, :critical => 2 }
Instance Attribute Summary collapse
-
#authkey ⇒ Object
The Icinga server.
-
#filter ⇒ Object
The Icinga server.
-
#host ⇒ Object
The Icinga server.
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(params) ⇒ ServiceCheck
constructor
Define a service check to be carried out.
Constructor Details
#initialize(params) ⇒ ServiceCheck
Define a service check to be carried out.
Currently, only counting services in a given state is possible, where the service name and state are provided as literals, with optional filtering on host name, either as an exact match or with wildcards in the host name.
Arguments:
-
:host - The Icinga host. The REST API must be available at the default location [host]/icinga-web/web/api/
-
:authkey - Your API key to access the REST API
-
:filter - a list of tuples to filter the count e.g.
[ {:host_name => 'web*'}, {:service_name => 'Load', :state => :critical} ]
The :host_name and :service_name should match hosts and services you have configured in Icinga (otherwise your count will always be zero).
:state should be one of :ok, :warn, :critical
Example:
check = IcingaRest::ServiceCheck.new(
:host => 'my.icinga.host',
:authkey => 'mysecretapikey',
:filter => [
{:host_name => 'web*'},
{:service_name => 'Load', :state => :critical}
]
)
puts check.count
47 48 49 50 51 |
# File 'lib/icinga_rest/service_check.rb', line 47 def initialize(params) @host = params[:host] @authkey = params[:authkey] @filter = params[:filter] end |
Instance Attribute Details
#authkey ⇒ Object
The Icinga server
4 5 6 |
# File 'lib/icinga_rest/service_check.rb', line 4 def authkey @authkey end |
#filter ⇒ Object
The Icinga server
4 5 6 |
# File 'lib/icinga_rest/service_check.rb', line 4 def filter @filter end |
#host ⇒ Object
The Icinga server
4 5 6 |
# File 'lib/icinga_rest/service_check.rb', line 4 def host @host end |
Instance Method Details
#count ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/icinga_rest/service_check.rb', line 53 def count json = request.get result = JSON.load json if result['success'] == 'true' result['total'] else raise "API call failed" end end |