Page 1 of 1

Add host status field to ServiceStatus API

Posted: Wed Feb 10, 2021 9:41 pm
by rajasegar
Can anyone advise me how to add current host state in this API output?
Thanks

XI 5.7.5
curl -XGET "http://10.17.19.235/nagiosxi/api/v1/obj ... q&pretty=1"
Response JSON:
{
"recordcount": "59",
"servicestatus": [
{
"@attributes": {
"id": "3081"
},
"instance_id": "1",
"service_id": "195",
"host_id": "187",
"host_name": "test123",
"name": "Domain Expiration",
"host_display_name": "",
"host_address": "127.0.0.1",
"display_name": "Domain Expiration",
"status_update_time": "2015-09-24 02:33:54",
"status_text": "CRITICAL - Domain 'test123' will expire in -16699 days (The expiration date displayed in this record is the date the).",
"status_text_long": "",
"current_state": "2",
"performance_data": "",
"should_be_scheduled": "1",
"check_type": "0",
"last_state_change": "2015-09-22 05:44:33",
"last_hard_state_change": "2015-09-22 05:48:27",
"last_hard_state": "2",
"last_time_ok": "2015-09-19 19:27:11",
"last_time_warning": "1969-12-31 18:00:00",
"last_time_critical": "2015-09-21 02:24:18",
"last_time_unknown": "1969-12-31 18:00:00",
"last_notification": "2015-09-23 05:48:25",
"next_notification": "2015-09-23 06:48:25",
"no_more_notifications": "0",
"acknowledgement_type": "0",
"current_notification_number": "2",
"process_performance_data": "1",
"obsess_over_service": "1",
"event_handler_enabled": "1",
"modified_service_attributes": "0",
"event_handler": "",
"check_command": "check_xi_domain_v2!test123!-w 4!-c 6",
"normal_check_interval": "1440",
"retry_check_interval": "1",
"check_timeperiod_id": "128",
"icon_image": "",
"icon_image_alt": "",
"has_been_checked": "1",
"current_check_attempt": "5",
"max_check_attempts": "5",
"last_check": "2015-09-23 05:48:25",
"next_check": "2015-09-24 05:48:25",
"state_type": "1",
"notifications_enabled": "1",
"problem_acknowledged": "0",
"flap_detection_enabled": "1",
"is_flapping": "0",
"percent_state_change": "6.12",
"latency": "0",
"execution_time": "0.51",
"scheduled_downtime_depth": "0",
"passive_checks_enabled": "1",
"active_checks_enabled": "1"
}
]
}

Re: Add host status field to ServiceStatus API

Posted: Thu Feb 11, 2021 6:03 pm
by benjaminsmith
Hi,

There's another API endpoint that data, see GET objects/hoststatus.

Code: Select all

curl -XGET "https://192.168.23.113/nagiosxi/api/v1/objects/hoststatus?apikey=<YOURAPIKEY>&pretty=1"
"host_object_id": "238",
"host_name": "192.168.23.142",
"host_alias": "192.168.23.142",
"display_name": "192.168.23.142",
"address": "192.168.23.142",
"icon_image": "ncpa.png",
"icon_image_alt": "",
"notes": "",
"notes_url": "",
"action_url": "",
"hoststatus_id": "3",
"instance_id": "1",
"status_update_time": "2021-02-11 17:01:45",
"output": "OK - 192.168.23.142 rta 5.845ms lost 0%",
"long_output": "",
"perfdata": "rta=5.845ms;3000.000;5000.000;0; pl=0%;80;100;0;100 rtmax=10.649ms;;;; rtmin=0.473ms;;;;",
"current_state": "0",
"has_been_checked": "1",
"should_be_scheduled": "1",
"current_check_attempt": "1",
"max_check_attempts": "5",
"last_check": "2021-02-11 17:01:45",
"next_check": "2021-02-11 17:06:45",
"check_type": "0",
It's an extra step but it will be necessary to pull it from that end point.

benjamin

Re: Add host status field to ServiceStatus API

Posted: Sun Feb 14, 2021 9:23 pm
by rajasegar
benjaminsmith wrote:Hi,

There's another API endpoint that data, see GET objects/hoststatus.

Code: Select all

curl -XGET "https://192.168.23.113/nagiosxi/api/v1/objects/hoststatus?apikey=<YOURAPIKEY>&pretty=1"
"host_object_id": "238",
"host_name": "192.168.23.142",
"host_alias": "192.168.23.142",
"display_name": "192.168.23.142",
"address": "192.168.23.142",
"icon_image": "ncpa.png",
"icon_image_alt": "",
"notes": "",
"notes_url": "",
"action_url": "",
"hoststatus_id": "3",
"instance_id": "1",
"status_update_time": "2021-02-11 17:01:45",
"output": "OK - 192.168.23.142 rta 5.845ms lost 0%",
"long_output": "",
"perfdata": "rta=5.845ms;3000.000;5000.000;0; pl=0%;80;100;0;100 rtmax=10.649ms;;;; rtmin=0.473ms;;;;",
"current_state": "0",
"has_been_checked": "1",
"should_be_scheduled": "1",
"current_check_attempt": "1",
"max_check_attempts": "5",
"last_check": "2021-02-11 17:01:45",
"next_check": "2021-02-11 17:06:45",
"check_type": "0",
It's an extra step but it will be necessary to pull it from that end point.

benjamin
I am aware of this. This is what we want to avoid.
Any SQL I can use instead to get the servicestatus with hoststate included?

Re: Add host status field to ServiceStatus API

Posted: Mon Feb 15, 2021 4:00 pm
by benjaminsmith
Hi,
Any SQL I can use instead to get the servicestatus with hoststate included?
All of this information is located in the nagios database. While we do not provide customer scripting as part of product support, here's an example query to grab service status along with host status. Hopefully, this will help get you started.

Code: Select all

select nagios_servicestatus.service_object_id,nagios_servicestatus.current_state,nagios_services.display_name, nagios_services.host_object_id, nagios_hoststatus.current_state from nagios_servicestatus join nagios_services ON nagios_servicestatus.service_object_id = nagios_services.service_object_id join nagios_hoststatus ON nagios_hoststatus.host_object_id = nagios_services.host_object_id;
Best Regards,
Benjamin

Re: Add host status field to ServiceStatus API

Posted: Mon Feb 15, 2021 8:11 pm
by rajasegar
benjaminsmith wrote:Hi,
Any SQL I can use instead to get the servicestatus with hoststate included?
All of this information is located in the nagios database. While we do not provide customer scripting as part of product support, here's an example query to grab service status along with host status. Hopefully, this will help get you started.

Code: Select all

select nagios_servicestatus.service_object_id,nagios_servicestatus.current_state,nagios_services.display_name, nagios_services.host_object_id, nagios_hoststatus.current_state from nagios_servicestatus join nagios_services ON nagios_servicestatus.service_object_id = nagios_services.service_object_id join nagios_hoststatus ON nagios_hoststatus.host_object_id = nagios_services.host_object_id;
Best Regards,
Benjamin
Thanks. Appreciate the help.

Re: Add host status field to ServiceStatus API

Posted: Tue Feb 16, 2021 8:26 am
by scottwilkerson
rajasegar wrote:
benjaminsmith wrote:Hi,
Any SQL I can use instead to get the servicestatus with hoststate included?
All of this information is located in the nagios database. While we do not provide customer scripting as part of product support, here's an example query to grab service status along with host status. Hopefully, this will help get you started.

Code: Select all

select nagios_servicestatus.service_object_id,nagios_servicestatus.current_state,nagios_services.display_name, nagios_services.host_object_id, nagios_hoststatus.current_state from nagios_servicestatus join nagios_services ON nagios_servicestatus.service_object_id = nagios_services.service_object_id join nagios_hoststatus ON nagios_hoststatus.host_object_id = nagios_services.host_object_id;
Best Regards,
Benjamin
Thanks. Appreciate the help.
Locking thread