ruby-icinga2
An enhanced ruby gem to communicate with Icinga2 API
Requirements
- ruby version => 2.0
- rest-client ~> 2.0
- json ~> 2.1
- openssl ~> 2.0 (only with ruby >= 2.3)
- ruby_dig (only with ruby < 2.3)
Install
gem install icinga2
Usage
create an instance
require 'icinga2'
config = {
icinga: {
host: icinga_host,
api: {
port: icinga_api_port,
username: icinga_api_user,
password: icinga_api_pass
}
}
}
@icinga = Icinga2::Client.new( config )
Use the examples
You can use the Icinga Vagrant-Box from the Icinga Team or my own Docker Container as Datasource.
Remember Change the exported Environment Variables to your choosed Datasource!
you can find many examples under the directory examples
:
$ export ICINGA_HOST=localhost ; export ICINGA_API_USER=root ; export ICINGA_API_PASSWORD=icinga
$ ruby examples/informations.rb
$ ruby examples/statistics.rb
$ ruby examples/users.rb
and so on.
Test via CLI
$ irb
irb(main):001:0> require 'icinga2'
=> true
irb(main):002:0> config = { icinga: { host: 'localhost', api: { username: 'root', password: 'icinga' } } }
=> {:icinga=>{:host=>"localhost", :api=>{:username=>"root", :password=>"icinga"}}}
irb(main):003:0> i = Icinga2::Client.new( config )
irb(main):004:0> i.available?
=> true
irb(main):005:0>
Create a own gem file
$ gem build icinga2.gemspec
Successfully built RubyGem
Name: icinga2
Version: 0.9.2.7
File: icinga2-0.9.2.7.gem
Install local gem
$ gem install icinga2
Successfully installed icinga2-0.9.2.7
1 gem installed
Status
supports the following API Calls:
-
- add host
- delete host
- modify host
- list hosts
- check if host exists
- list host objects
- count of hosts with problems
- list of hosts with problems
- count of all hosts
- count hosts with problems
- calculate host severity (protected)
-
- enable host notifications
- disable host notifications
- enable service notifications
- disable service notifications
- enable hostgroup notifications
- disable hostgroup notifications
- list all notifications
- host notification (protected)
- hostgroup notification (protected)
- service notification (protected)