Page 1 of 1

REST API Query

Posted: Tue May 28, 2019 7:36 pm
by rajasegar
Hi,

How to I get REST API to get all the services status for a particular host or service?

Thanks

Re: REST API Query

Posted: Wed May 29, 2019 11:27 am
by tgriep
In the Nagios XI GUI, if you go to the Help menu and click on the Objects Reference link, it shows examples on how to get status information for hosts and Services.

If you want to get the status for one host, you would add 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://xxx.xxx.xxx.xxx/nagiosxi/api/v1/objects/hoststatus?apikey=<APIKEY>&pretty=1&host_name=localhost"
You would use the following example to get the service status of one service called HTTP for the localhost host.

Code: Select all

curl -XGET "https://xxx.xxx.xxx.xxx/nagiosxi/api/v1/objects/servicestatus?apikey=<APIKEY>&host_name=localhost&name=HTTP&pretty=1" -k
Try them out and see if they work for your needs.

Re: REST API Query

Posted: Wed May 29, 2019 7:52 pm
by rajasegar
tgriep wrote:In the Nagios XI GUI, if you go to the Help menu and click on the Objects Reference link, it shows examples on how to get status information for hosts and Services.

If you want to get the status for one host, you would add 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://xxx.xxx.xxx.xxx/nagiosxi/api/v1/objects/hoststatus?apikey=<APIKEY>&pretty=1&host_name=localhost"
You would use the following example to get the service status of one service called HTTP for the localhost host.

Code: Select all

curl -XGET "https://xxx.xxx.xxx.xxx/nagiosxi/api/v1/objects/servicestatus?apikey=<APIKEY>&host_name=localhost&name=HTTP&pretty=1" -k
Try them out and see if they work for your needs.
Thanks works well.

Code: Select all

{
    "recordcount": "1",
    "servicestatus": {
        "@attributes": {
            "id": "75918978"
        },
        "instance_id": "1",
        "service_id": "20165",
        "host_id": "7063",
        "host_name": "nagiosprodxi1",
        "host_alias": "Nagios App Server",
        "name": "CPU Load",
        "host_display_name": {
            
        },
        "host_address": "17.17.17.17",
        "display_name": "CPU Load",
        "status_update_time": "2019-05-30 08:46:36",
        "status_text": "OK - load average per CPU: 0.26, 0.27, 0.25",
        "status_text_long": {
            
        },
        "current_state": "0",
        "performance_data": "load1=0.259;3.000;5.000;0; load5=0.265;3.000;5.000;0; load15=0.254;3.000;5.000;0;",
        "should_be_scheduled": "1",
        "check_type": "0",
        "last_state_change": "2019-04-19 17:33:42",
        "last_hard_state_change": "2019-04-19 17:33:42",
        "last_hard_state": "0",
        "last_time_ok": "2019-05-30 08:46:34",
        "last_time_warning": "2019-04-19 17:33:42",
        "last_time_critical": "2019-03-17 00:47:30",
        "last_time_unknown": "2019-03-05 18:32:50",
        "last_notification": "1970-01-01 07:30:00",
        "next_notification": "1970-01-01 07:30:00",
        "no_more_notifications": "0",
        "acknowledgement_type": "0",
        "current_notification_number": "0",
        "process_performance_data": "1",
        "obsess_over_service": "1",
        "event_handler_enabled": "1",
        "modified_service_attributes": "0",
        "event_handler": {
            
        },
        "check_command": "rs_fping_check_nrpe_unix_alt!check_load!$_HOSTLIMIT_UNIX_CPU_LOAD_WARN$!$_HOSTLIMIT_UNIX_CPU_LOAD_CRIT$!!!!!",
        "normal_check_interval": "5",
        "retry_check_interval": "5",
        "check_timeperiod_id": "109",
        "icon_image": {
            
        },
        "icon_image_alt": {
            
        },
        "has_been_checked": "1",
        "current_check_attempt": "1",
        "max_check_attempts": "6",
        "last_check": "2019-05-30 08:46:34",
        "next_check": "2019-05-30 08:51:34",
        "state_type": "1",
        "notifications_enabled": "1",
        "problem_acknowledged": "0",
        "flap_detection_enabled": "1",
        "is_flapping": "0",
        "percent_state_change": "0",
        "latency": "0",
        "execution_time": "2.07546",
        "scheduled_downtime_depth": "0",
        "passive_checks_enabled": "1",
        "active_checks_enabled": "1",
        "notes_url": {
            
        },
        "action_url": {
            
        }
    }
}
Is it possible to extract only the following properties or I need to grep the output?
1) "status_text": "OK - load average per CPU: 0.26, 0.27, 0.25",
2) "current_state": "0",
3) "performance_data": "load1=0.259;3.000;5.000;0; load5=0.265;3.000;5.000;0; load15=0.254;3.000;5.000;0;",

Re: REST API Query

Posted: Thu May 30, 2019 7:06 am
by scottwilkerson
There isn't any automatic filtering, so you would need to extract them in your script that is getting the JSON

Re: REST API Query

Posted: Thu May 30, 2019 7:40 pm
by rajasegar
scottwilkerson wrote:There isn't any automatic filtering, so you would need to extract them in your script that is getting the JSON
Thanks. Please close this thread.

Re: REST API Query

Posted: Fri May 31, 2019 6:37 am
by scottwilkerson
rajasegar wrote:
scottwilkerson wrote:There isn't any automatic filtering, so you would need to extract them in your script that is getting the JSON
Thanks. Please close this thread.
Great!

Closing