Coder Social home page Coder Social logo

ruby-icinga2's Introduction

ruby-icinga2

An enhanced ruby gem to communicate with Icinga2 API

Gem Version

Build Status Gem Downloads total Downloads Dependency Status

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:

ruby-icinga2's People

Contributors

bodsch avatar davidhrbac avatar dayne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ruby-icinga2's Issues

bug undefined method `each' for nil:NilClass

cm-icinga-client        | /usr/lib/ruby/gems/2.4.0/gems/icinga2-0.6.6.0/lib/icinga2/services.rb:233:in `problem_services': undefined method `each' for nil:NilClass (NoMethodError)
cm-icinga-client        |       from /usr/lib/ruby/gems/2.4.0/gems/icinga2-0.6.6.0/lib/icinga2/status.rb:202:in `extract_data'
cm-icinga-client        |       from /usr/lib/ruby/gems/2.4.0/gems/icinga2-0.6.6.0/lib/icinga2.rb:134:in `initialize'
cm-icinga-client        |       from /usr/local/lib/icinga.rb:56:in `initialize'
cm-icinga-client        |       from /usr/local/bin/icinga-client.rb:74:in `new'
cm-icinga-client        |       from /usr/local/bin/icinga-client.rb:74:in `<main>'

Zone setting in config

Hello,

Is there a way to set zone when connecting to multi-zone instance API?

config = {
  icinga: {
    host: "host",
    zone: "zone",
    api: {
      port: port,
      username: "username",
      password: "password"
    }
  }
}

better implemantation of eval()

bundler exec rake style:ruby

lib/icinga2/hosts.rb:97:15: C: The use of eval is a serious security risk.
          v = eval(attr)
              ^^^^
lib/icinga2/hosts.rb:105:16: C: The use of eval is a serious security risk.
           v = eval(attr)
               ^^^^
lib/icinga2/hosts.rb:116:16: C: The use of eval is a serious security risk.
           v = eval(attr)
               ^^^^
lib/icinga2/hosts.rb:121:13: C: The use of eval is a serious security risk.
        v = eval(attr)
            ^^^^

Documentation create instance

add require, replace :pass and Icinga::Client.new

require 'icinga2'

config = {
  :icinga => {
    :host      => 'fornax.icinga-book.local',
    :api       => {
      :port => api_port,
      :user => api_user,
      :password => api_password
    }
  }
}

@icinga = Icinga2::Client.new( config )

API Calls for Service Object

  • vars (Dictionary)
  • action_url (String)
  • check_command (String)
  • check_interval (Number)
  • check_period (String)
  • check_timeout (Value)
  • command_endpoint (String)
  • enable_active_checks (Number)
  • enable_event_handler (Number)
  • enable_flapping (Number)
  • enable_notifications (Number)
  • enable_passive_checks (Number)
  • enable_perfdata (Number)
  • event_command (String)
  • flapping_threshold (Number)
  • flapping_threshold_high (Number)
  • flapping_threshold_low (Number)
  • icon_image (String)
  • icon_image_alt (String)
  • max_check_attempts (Number)
  • notes (String)
  • notes_url (String)
  • retry_interval (Number)
  • volatile (Number)
  • display_name (String)
  • host_name (String)

API Calls for Host Object

  • vars (Dictionary)
  • action_url (String)
  • check_command (String)
  • check_interval (Number)
  • check_period (String)
  • check_timeout (Value)
  • command_endpoint (String)
  • enable_active_checks (Number)
  • enable_event_handler (Number)
  • enable_flapping (Number)
  • enable_notifications (Number)
  • enable_passive_checks (Number)
  • enable_perfdata (Number)
  • event_command (String)
  • flapping_threshold (Number)
  • flapping_threshold_high (Number)
  • flapping_threshold_low (Number)
  • icon_image (String)
  • icon_image_alt (String)
  • max_check_attempts (Number)
  • notes (String)
  • notes_url (String)
  • retry_interval (Number)
  • volatile (Number)
  • address (String)
  • address6 (String)
  • display_name (String)

Direct match attributes in lib funs to icinga2 objects attributes

Hello,

I found that this lib doesn't have a direct match to icinga2 object attributes.

for example section in lib/icinga2/hosts.rb

      payload = {
        'templates' => [ 'generic-host' ],
        'attrs'     => {
          'address'              => fqdn,
          'display_name'         => display_name,
          'max_check_attempts'   => max_check_attempts.to_i,
          'check_interval'       => check_interval.to_i,
          'retry_interval'       => retry_interval.to_i,
          'enable_notifications' => notifications,
          'action_url'           => action_url,
          'notes'                => notes,
          'notes_url'            => notes_url
        }
      }

so I have to look at this library file and find that to set address attribute I have to define fqdn in add_host options. This is strange because i'm waiting that setting 'address' in options will set the same attribute in object. Agree?

What do you think if I'll send PR that will do direct match from funcs options to icinga2 object options?

more examples

we need more examples.
the folder examples are the home of this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.