[icinga-users] Question about icinga2 api dynamically added hosts and hostgroups

Michael Friedrich Michael.Friedrich at netways.de
Sun Nov 15 12:39:36 CET 2015


> On 13 Nov 2015, at 23:02, Madhusmita Gochhait <mgochhait at juniper.net> wrote:
>
> After restart of icinga process , Icinga unable to query the hosts/groups objects through api . Icinga http returns object does not exist
>
> Here are the steps to simulate the issue (Single Node)
>
> Step 1:   curl -k -s -u icingaadmin:icinga 'https://localhost:5665/v1/objects/hosts/10.102.58.77'  -H "Accept: application/json" -X PUT -d '{ "templates": [ "generic-host" ], "attrs": { "address": "10.102.58.77”}}
>                 {"results":[{"code":200.0,"status":"Object was created"}]}
> Step 2 :  query to icinga - curl -k -s -u icingaadmin:icinga 'https://localhost:5665/v1/objects/hosts/10.102.58.77'  will result with detailed host output
>
> Step 3: Restart Icinga
>                service icinga2 reload
>
> Step 4: Host Query as detailed in Step 2
> curl -k -s -u icingaadmin:icinga 'https://localhost:5665/v1/objects/hosts/10.102.58.77'
> Error: Object does not exist

I’m also unable to reproduce this here.

michi at mbmif ~ $ icinga2 --version
icinga2 - The Icinga 2 network monitoring daemon (version: v2.3.11-854-ge9db4bc; debug)

Copyright (c) 2012-2015 Icinga Development Team (https://www.icinga.org)
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl2.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Application information:
  Installation root: /usr/local/icinga2
  Sysconf directory: /usr/local/icinga2/etc
  Run directory: /usr/local/icinga2/var/run
  Local state directory: /usr/local/icinga2/var
  Package data directory: /usr/local/icinga2/share/icinga2
  State path: /usr/local/icinga2/var/lib/icinga2/icinga2.state
  Modified attributes path: /usr/local/icinga2/var/lib/icinga2/modified-attributes.conf
  Objects path: /usr/local/icinga2/var/cache/icinga2/icinga2.debug
  Vars path: /usr/local/icinga2/var/cache/icinga2/icinga2.vars
  PID path: /usr/local/icinga2/var/run/icinga2/icinga2.pid

System information:
  Operating system: Darwin
  Operating system version: 15.0.0
  Architecture: x86_64


michi at mbmif ~ $ curl -k -s -u root:icinga -H 'Accept: application/json' -X PUT -d '{ "attrs": { "check_command": "hostalive", "address": "192.168.2.123" } }' 'https://localhost:5665/v1/objects/hosts/michiathome1'
{"results":[{"code":200.0,"status":"Object was created"}]}

[2015-11-15 12:32:31 +0100] information/ApiListener: New client connection (no client certificate)
[2015-11-15 12:32:31 +0100] information/HttpServerConnection: Request: PUT /v1/objects/hosts/michiathome1 (root)
[2015-11-15 12:32:31 +0100] information/ConfigCompiler: Compiling config file: /usr/local/icinga2/var/lib/icinga2/api/packages/_api/mbmif.int.netways.de-1442309540-1/conf.d/hosts/michiathome1.conf
[2015-11-15 12:32:31 +0100] information/ConfigItem: Committing config items

michi at mbmif ~ $ curl -k -s -u root:icinga 'https://localhost:5665/v1/objects/hosts/michiathome1'
{"results":[{"attrs":{"__name":"michiathome1","acknowledgement":0.0,"acknowledgement_expiry":0.0,"action_url":"","active":true,"address":"192.168.2.123","address6":"","check_attempt":1.0,"check_command":"hostalive","check_interval":300.0,"display_name":"michiathome1","enable_active_checks":true,"enable_event_handler":true,"enable_flapping":false,"enable_notifications":true,"enable_passive_checks":true,"enable_perfdata":true,"flapping":false,"flapping_last_change":0.0,"flapping_negative":0.0,"flapping_positive":0.0,"flapping_threshold":30.0,"force_next_check":false,"force_next_notification":false,"groups":[],"ha_mode":0.0,"icon_image":"","icon_image_alt":"","last_check":-1.0,"last_check_result":null,"last_hard_state":1.0,"last_hard_state_change":1447587016.4019169807,"last_in_downtime":false,"last_reachable":true,"last_state":1.0,"last_state_change":1447587016.4019169807,"last_state_down":0.0,"last_state_type":0.0,"last_state_unreachable":0.0,"last_state_up":0.0,"max_check_attempts":3.0,"name":"michiathome1","next_check":1447587300.0599999428,"notes":"","notes_url":"","original_attributes":null,"package":"_api","paused":false,"retry_interval":60.0,"state":1.0,"state_type":0.0,"templates":["michiathome1"],"type":"Host","vars":null,"version":1447587151.0631680489,"volatile":false,"zone":""},"joins":{},"meta":{},"name":"michiathome1","type":"Host"}]}

michi at mbmif ~ $ sudo cat /usr/local/icinga2/var/lib/icinga2/api/packages/_api/mbmif.int.netways.de-1442309540-1/conf.d/hosts/michiathome1.conf
object Host "michiathome1" {
address = "192.168.2.123"
check_command = "hostalive"
version = 1447587151.063168
}

michi at mbmif ~ $ sudo kill -HUP $(pidof icinga2)

michi at mbmif ~ $ sudo cat /usr/local/icinga2/var/lib/icinga2/api/packages/_api/mbmif.int.netways.de-1442309540-1/conf.d/hosts/michiathome1.conf
object Host "michiathome1" {
address = "192.168.2.123"
check_command = "hostalive"
version = 1447587151.063168
}

michi at mbmif ~ $ curl -k -s -u root:icinga 'https://localhost:5665/v1/objects/hosts/michiathome1'
{"results":[{"attrs":{"__name":"michiathome1","acknowledgement":0.0,"acknowledgement_expiry":0.0,"action_url":"","active":true,"address":"192.168.2.123","address6":"","check_attempt":1.0,"check_command":"hostalive","check_interval":300.0,"display_name":"michiathome1","enable_active_checks":true,"enable_event_handler":true,"enable_flapping":false,"enable_notifications":true,"enable_passive_checks":true,"enable_perfdata":true,"flapping":false,"flapping_last_change":1447587315.097356081,"flapping_negative":0.0,"flapping_positive":1447587315.0,"flapping_threshold":30.0,"force_next_check":false,"force_next_notification":false,"groups":[],"ha_mode":0.0,"icon_image":"","icon_image_alt":"","last_check":1447587315.096987009,"last_check_result":{"active":true,"check_source":"mbmif.int.netways.de","command":["/usr/local/sbin/check_ping","-H","192.168.2.123","-c","5000,100%","-w","3000,80%"],"execution_end":1447587315.0968000889,"execution_start":1447587300.0619831085,"exit_status":2.0,"output":"PING CRITICAL - Packet loss = 100%","performance_data":["rta=5000.000000ms;3000.000000;5000.000000;0.000000","pl=100%;80;100;0"],"schedule_end":1447587315.096987009,"schedule_start":1447587600.0599999428,"state":2.0,"type":"CheckResult","vars_after":{"attempt":1.0,"reachable":true,"state":2.0,"state_type":1.0},"vars_before":null},"last_hard_state":1.0,"last_hard_state_change":1447587315.096987009,"last_in_downtime":false,"last_reachable":true,"last_state":1.0,"last_state_change":1447587315.096987009,"last_state_down":0.0,"last_state_type":0.0,"last_state_unreachable":0.0,"last_state_up":0.0,"max_check_attempts":3.0,"name":"michiathome1","next_check":1447587599.129999876,"notes":"","notes_url":"","original_attributes":null,"package":"_api","paused":false,"retry_interval":60.0,"state":1.0,"state_type":1.0,"templates":["michiathome1"],"type":"Host","vars":null,"version":1447587151.0631680489,"volatile":false,"zone":""},"joins":{},"meta":{},"name":"michiathome1","type":"Host"}]}


michi at mbmif ~ $ sudo mysql icinga -p -e 'select * from icinga_hoststatus hs join icinga_objects ohs on hs.host_object_id=ohs.object_id where ohs.name1="michiathome1" and ohs.is_active=1\G'
Enter password:
*************************** 1. row ***************************
                hoststatus_id: 643
                  instance_id: 1
               host_object_id: 8940
           status_update_time: 2015-11-15 12:35:58
                       output: PING CRITICAL - Packet loss = 100%
                  long_output:
                     perfdata: rta=5000.000000ms;3000.000000;5000.000000;0.000000 pl=100%;80;100;0
                 check_source: mbmif.int.netways.de
                current_state: 1
             has_been_checked: 1
          should_be_scheduled: 1
        current_check_attempt: 1
           max_check_attempts: 3
                   last_check: 2015-11-15 12:35:15
                   next_check: 2015-11-15 12:39:59
                   check_type: 0
            last_state_change: 2015-11-15 12:35:15
       last_hard_state_change: 2015-11-15 12:35:15
              last_hard_state: 1
                 last_time_up: 0000-00-00 00:00:00
               last_time_down: 0000-00-00 00:00:00
        last_time_unreachable: 0000-00-00 00:00:00
                   state_type: 1
            last_notification: 0000-00-00 00:00:00
            next_notification: 0000-00-00 00:00:00
        no_more_notifications: 0
        notifications_enabled: 1
problem_has_been_acknowledged: 0
         acknowledgement_type: 0
  current_notification_number: 0
       passive_checks_enabled: 1
        active_checks_enabled: 1
        event_handler_enabled: 1
       flap_detection_enabled: 0
                  is_flapping: 0
         percent_state_change: 0
                      latency: 0
               execution_time: 15.034816980361938
     scheduled_downtime_depth: 0
   failure_prediction_enabled: 0
     process_performance_data: 1
             obsess_over_host: 0
     modified_host_attributes: 0
                event_handler:
                check_command: hostalive
        normal_check_interval: 5
         retry_check_interval: 1
   check_timeperiod_object_id: 0
                 is_reachable: 1
           endpoint_object_id: 1
          original_attributes: null
                    object_id: 8940
                  instance_id: 1
                objecttype_id: 1
                        name1: michiathome1
                        name2: NULL
                    is_active: 1


>
>
> Similar behavior with host groups also .
>
> Thanks,
> mgochhait
>
>
>
>
> From: Madhusmita Gochhait <mgochhait at juniper.net>
> Date: Tuesday, November 10, 2015 at 3:21 PM
> To: "icinga-users at lists.icinga.org" <icinga-users at lists.icinga.org>
> Subject: Question about icinga2 api dynamically added hosts and hostgroups
>
> I am using the snapshot version of icinga2 for the api feature . Dynamically add hosts and host groups.
> Here is what i am doing :
> To add hostgroup : curl -k -s -u icingaadmin:icinga 'https://localhost:5665/v1/objects/hostgroups/testgrp' -X PUT -d '{ "attrs": { "name" : "testgrp" ,"display_name" : "testgrp" , "state_loaded" :true }}'
> To add host :
> curl -k -s -u icingaadmin:icinga 'https://localhost:5665/v1/objects/hosts/testhost' -X PUT -d '{ "templates": [ "generic-host" ], "attrs": { "address": "8.8.8.8" , "groups" : [ "testgrp" ]} }'
> It gets successfully added  and I am also able to  query them through the api .
> But in UI , I am seeing only the host and no hostgroup .
> The host group gets displayed once I restart/reload icinga .
> Since , we have a large setup (>1000 hosts ) , we don’t want to reload /restart everytime we add hostgroups .
> Is there any way it can be done in same way as the host , so that both host and host groups shows in UI without restart everytime ?
>
> Thanks,
> mgochhait
>
> _______________________________________________
> icinga-users mailing list
> icinga-users at lists.icinga.org
> https://lists.icinga.org/mailman/listinfo/icinga-users


-- 
Michael Friedrich, DI (FH)
Senior Developer

NETWAYS GmbH | Deutschherrnstr. 15-19 | D-90429 Nuernberg
Tel: +49 911 92885-0 | Fax: +49 911 92885-77
GF: Julian Hein, Bernd Erk | AG Nuernberg HRB18461
http://www.netways.de | Michael.Friedrich at netways.de

** OSMC 2015 - November - netways.de/osmc **
** OSDC 2016 - April – netways.de/osdc **


More information about the icinga-users mailing list