Page 1 of 1

API to get Host current_state

Posted: Wed May 17, 2017 2:13 pm
by nagwindmon
Nagios team,
Is there an API I could utilize to retrieve host's current_state instead of query MySQL table directly?

Thanks!

Re: API to get Host current_state

Posted: Wed May 17, 2017 3:37 pm
by tgriep
If you are running a newer 5.x.x version of XI, there is an API you can use to check the status of a host.
To view the API instructions , go to the Help > Objects Reference menu. There you will see the example on getting the host status.
The default example if ran, will give you the status of all of the hosts on the server

Ig you want to get the status for one host, you would ass the host_name= and then the name of the host. The example below displays the status for the localhost.

Code: Select all

curl -XGET "https://192.168.112.129/nagiosxi/api/v1/objects/hoststatus?apikey=j8hf9ss5&pretty=1&host_name=localhost"
This is the output that is generated.

Code: Select all

{
    "hoststatuslist": {
        "recordcount": "1",
        "hoststatus": {
            "@attributes": {
                "id": "182754"
            },
            "instance_id": "1",
            "host_id": "135",
            "name": "localhost",
            "display_name": "localhost",
            "address": "localhost",
            "alias": "localhost alias",
            "status_update_time": "2017-05-17 15:35:48",
            "status_text": "OK - localhost: rta 0.008ms, lost 0%",
            "status_text_long": "",
            "current_state": "0",
            "icon_image": "",
            "icon_image_alt": "",
            "performance_data": "rta=0.008ms;3000.000;5000.000;0; pl=0%;80;100;; rtmax=0.019ms;;;; rtmin=0.005ms;;;;",
            "should_be_scheduled": "1",
            "check_type": "0",
            "last_state_change": "2016-10-25 07:40:36",
            "last_hard_state_change": "2016-06-09 01:23:56",
            "last_hard_state": "0",
            "last_time_up": "2017-05-17 15:35:48",
            "last_time_down": "2016-10-24 15:16:57",
            "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": "1",
            "event_handler": "",
            "check_command": "check-host-alive",
            "normal_check_interval": "5",
            "retry_check_interval": "1",
            "check_timeperiod_id": "117",
            "has_been_checked": "1",
            "current_check_attempt": "1",
            "max_check_attempts": "10",
            "last_check": "2017-05-17 15:35:39",
            "next_check": "2017-05-17 15:40:48",
            "state_type": "1",
            "notifications_enabled": "1",
            "problem_acknowledged": "0",
            "passive_checks_enabled": "1",
            "active_checks_enabled": "1",
            "flap_detection_enabled": "1",
            "is_flapping": "0",
            "percent_state_change": "0",
            "latency": "0.0588",
            "execution_time": "0.01204",
            "scheduled_downtime_depth": "0"
        }
    }
}

Re: API to get Host current_state

Posted: Thu May 18, 2017 9:10 am
by nagwindmon
Excellent! In process installing 5.x.x version but in meantime is it possible to get what I only need and not entire output from API call?
For example if I only needed these 2 values:
"current_state": "0",
"last_time_up": "2017-03-24 02:05:51",

Re: API to get Host current_state

Posted: Thu May 18, 2017 11:35 am
by tgriep
No, the API call outputs all of the data for the object so you would have to parse out the information on your own.