Page 1 of 1

Nagios XI Rest API

Posted: Thu Sep 28, 2017 1:38 pm
by bennyboy
Hi,

I don't find option for managing hostgroup member. (Add, remove, update). There a way to do it ?

I also want to know if it's possible to show only the field I need in the response ?

I find a section about Building Limited Queries in the documentation but I don't find a way to limit the field.

Example :

Query right now :

Code: Select all

{
    "hoststatuslist": {
        "recordcount": "12",
        "hoststatus": [
            {
                "@attributes": {
                    "id": "401"
                },
                "instance_id": "1",
                "host_id": "202",
                "name": "tset",
                "display_name": "tset",
                "address": "127.0.53.53",
                "alias": "tset",
                "status_update_time": "2015-09-24 02:05:51",
                "status_text": "OK - 127.0.53.53: rta 0.021ms, lost 0%",
                "status_text_long": "",
                "current_state": "0",
                "icon_image": "server.png",
                "icon_image_alt": "",
                "performance_data": "rta=0.021ms;3000.000;5000.000;0; pl=0%;80;100;; rtmax=0.060ms;;;; rtmin=0.011ms;;;;",
                "should_be_scheduled": "1",
                "check_type": "0",
                "last_state_change": "2015-09-22 12:11:41",
                "last_hard_state_change": "2015-09-22 12:11:41",
                "last_hard_state": "0",
                "last_time_up": "2015-09-24 02:05:51",
                "last_time_down": "1969-12-31 18:00:00",
                "last_time_unreachable": "1969-12-31 18:00:00",
                "last_notification": "1969-12-31 18:00:00",
                "next_notification": "1969-12-31 18:00:00",
                "no_more_notifications": "0",
                "acknowledgement_type": "0",
                "current_notification_number": "0",
                "event_handler_enabled": "1",
                "process_performance_data": "1",
                "obsess_over_host": "1",
                "modified_host_attributes": "0",
                "event_handler": "",
                "check_command": "check_xi_host_ping!3000.0!80%!5000.0!100%",
                "normal_check_interval": "40",
                "retry_check_interval": "5",
                "check_timeperiod_id": "128",
                "has_been_checked": "1",
                "current_check_attempt": "1",
                "max_check_attempts": "4",
                "last_check": "2015-09-24 02:05:51",
                "next_check": "2015-09-24 02:45:51",
                "state_type": "1",
                "notifications_enabled": "0",
                "problem_acknowledged": "0",
                "passive_checks_enabled": "1",
                "active_checks_enabled": "1",
                "flap_detection_enabled": "1",
                "is_flapping": "0",
                "percent_state_change": "0",
                "latency": "0",
                "execution_time": "0.00226",
                "scheduled_downtime_depth": "0"
            }
        ]
    }
}
I need only

Code: Select all

{
    "hoststatuslist": {
        "recordcount": "12",
        "hoststatus": [
            {
                "@attributes": {
                    "id": "401"
                },
                "host_id": "202",
                "name": "tset",
                "address": "127.0.53.53",
                "current_state": "0",
            }
        ]
    }
}
Thank you!

Re: Nagios XI Rest API

Posted: Thu Sep 28, 2017 2:27 pm
by scottwilkerson
In the help section of XI click "Config Reference" then on the right select "POST config/hostgroup" this describes what you are looking to do for Adding.

Removing and updating is coming in a future release.

Re: Nagios XI Rest API

Posted: Thu Sep 28, 2017 3:33 pm
by bennyboy
What is the best way to manage hostgroup members ?

Add it to by hostsgroups api or hosts api ?

Thank you!

Re: Nagios XI Rest API

Posted: Thu Sep 28, 2017 3:59 pm
by scottwilkerson
It becomes much easier through the api if you add them to the host.

But other than that it is personal preference.

Re: Nagios XI Rest API

Posted: Thu Sep 28, 2017 4:12 pm
by bennyboy
it's possible to when I ask the API to return only the field I need ???

Re: Nagios XI Rest API

Posted: Fri Sep 29, 2017 8:42 am
by scottwilkerson
bennyboy wrote:it's possible to when I ask the API to return only the field I need ???
It is going to give you the whole objects, but the fields are named, you would just need to parse the object to get the value for the field you are looking for.