Naigosxi api request
Naigosxi api request
Hello team,
I am trying to isolate down hosts on nagiosxi specific host_group.
I use the below request of hostavailabilty:
curl "https://nagios_ip/nagiosxi/api/v1/objects/hostavailability?apikey=api_key&pretty=1&hostgroup=host_group_name¤t_state=nin:0"
the output is always all the hosts inside that host_group including online ones.
so how can I isolate only the down one in that specific host_group.
thanks for your support,
Regards.
I am trying to isolate down hosts on nagiosxi specific host_group.
I use the below request of hostavailabilty:
curl "https://nagios_ip/nagiosxi/api/v1/objects/hostavailability?apikey=api_key&pretty=1&hostgroup=host_group_name¤t_state=nin:0"
the output is always all the hosts inside that host_group including online ones.
so how can I isolate only the down one in that specific host_group.
thanks for your support,
Regards.
Re: Naigosxi api request
You would need to make a call to the objects/hostgroupmembers API end-point, and parse the JSON results somehow, in order to get the members of your hostgroup.
Example:
You can filter the output even more via sed or awk in order to get the names only in a comma separated list. Then you can make a call to objects/hoststatus as such:
Example:
Code: Select all
curl -s -q -XGET "http://x.x.x.x/nagiosxi/api/v1/objects/hostgroupmembers?apikey=xxx&pretty=1&hostgroup_name=sensors" | grep 'host_name' | tr -d '"'
host_name: AKCP SensorProbe2
host_name: EM08TCode: Select all
curl "https://x.x.x.x/nagiosxi/api/v1/objects/hostavailability?apikey=xxx&pretty=¤t_state=nin:0&name=in:HOST1,HOST2,HOST3"Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Naigosxi api request
Hello,
below curl is returning all the hosts in the server. it's not working properly.
curl "https://x.x.x.x/nagiosxi/api/v1/objects ... OST2,HOST3"
i have about hundred hosts in down state within a specific hostgroup.
how should i pass hostnames inside curl parameter "name="?
Regards.
below curl is returning all the hosts in the server. it's not working properly.
curl "https://x.x.x.x/nagiosxi/api/v1/objects ... OST2,HOST3"
i have about hundred hosts in down state within a specific hostgroup.
how should i pass hostnames inside curl parameter "name="?
Regards.
Re: Naigosxi api request
My bad - I accidentally put hostavailability instead of hoststatus. Sorry about that. The correct command should be:
The hosts should be comma-separated. Let us know if this works for you.
Code: Select all
curl "https://x.x.x.x/nagiosxi/api/v1/objects/hoststatus?apikey=xxx&pretty=1¤t_state=nin:0&name=in:HOST1,HOST2,HOST3"Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Naigosxi api request
It didn't work , here is the output:
{
"recordcount": "0"
}
note: hosts' names contains dashes, and there are many hosts.
{
"recordcount": "0"
}
note: hosts' names contains dashes, and there are many hosts.
Re: Naigosxi api request
I tried the following:
1. I set up a hostgroup, named "centos" with 4 members. All of the hosts have dashes in the name.
2. I disabled active checks on two of the hosts, and sent a passive "DOWN" check result, to bring them down.
3. I grabbed the names of the hostgroup members via a REST API call:
4. I checked which of the members are in DOWN state:
Is this what you are doing?
1. I set up a hostgroup, named "centos" with 4 members. All of the hosts have dashes in the name.
Code: Select all
define hostgroup {
hostgroup_name centos
alias centos
members CentOS-NCPA,CentOS-NRPE,CentOS-SNMP,CentOS-SSH
}Code: Select all
[root@main-nagios-xi libexec]# curl -s -XGET "http://x.x.x.x/nagiosxi/api/v1/objects/hostgroupmembers?apikey=xxx&pretty=1&hostgroup_name=centos" | grep 'host_name' | tr -d '"'
host_name: CentOS-NCPA
host_name: CentOS-SSH
host_name: CentOS-NRPE
host_name: CentOS-SNMPCode: Select all
[root@main-nagios-xi libexec]# curl -s -XGET "http://x.x.x.x/nagiosxi/api/v1/objects/hoststatus?apikey=xxx&pretty=1¤t_state=nin:0&name=in:CentOS-NCPA,CentOS-SSH,CentOS-NRPE,CentOS-SNMP"
{
"recordcount": "2",
"hoststatus": [
{
"@attributes": {
"id": "726157"
},
"instance_id": "1",
"host_id": "286",
"name": "CentOS-NRPE",
"display_name": "CentOS-NRPE",
"address": "192.168.x.x",
"alias": "CentOS-NRPE",
"status_update_time": "2019-10-29 08:58:00",
"status_text": "test",
"status_text_long": {
},
"current_state": "1",
"icon_image": "centos.png",
"icon_image_alt": {
},
"performance_data": {
},
"should_be_scheduled": "0",
"check_type": "1",
"last_state_change": "2019-10-29 08:57:27",
"last_hard_state_change": "2019-10-29 08:57:27",
"last_hard_state": "1",
"last_time_up": "2019-10-29 08:57:27",
"last_time_down": "2019-10-17 09:17:15",
"last_time_unreachable": "2019-08-16 11:55:17",
"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": "2",
"event_handler": {
},
"check_command": "check_xi_host_ping!3000.0!80%!5000.0!100%!!!!",
"normal_check_interval": "1",
"retry_check_interval": "1",
"check_timeperiod_id": "132",
"has_been_checked": "1",
"current_check_attempt": "1",
"max_check_attempts": "5",
"last_check": "2019-10-29 08:57:27",
"next_check": "2019-10-29 08:58:00",
"state_type": "1",
"notifications_enabled": "1",
"problem_acknowledged": "0",
"passive_checks_enabled": "1",
"active_checks_enabled": "0",
"flap_detection_enabled": "1",
"is_flapping": "0",
"percent_state_change": "6.11842",
"latency": "0.90374",
"execution_time": "0",
"scheduled_downtime_depth": "0",
"notes": "44.8277446,-92.9438218",
"notes_url": {
},
"action_url": {
}
},
{
"@attributes": {
"id": "726156"
},
"instance_id": "1",
"host_id": "284",
"name": "CentOS-NCPA",
"display_name": "CentOS-NCPA",
"address": "192.168.x.x",
"alias": "CentOS-NCPA",
"status_update_time": "2019-10-29 09:00:42",
"status_text": "test",
"status_text_long": {
},
"current_state": "1",
"icon_image": "ncpa.png",
"icon_image_alt": {
},
"performance_data": {
},
"should_be_scheduled": "0",
"check_type": "1",
"last_state_change": "2019-10-29 08:56:58",
"last_hard_state_change": "2019-10-29 08:56:58",
"last_hard_state": "1",
"last_time_up": "2019-10-29 08:56:58",
"last_time_down": "2019-06-20 16:43:45",
"last_time_unreachable": "2019-08-16 11:55:21",
"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": "2",
"event_handler": {
},
"check_command": "check_xi_host_ping!3000.0!80%!5000.0!100%",
"normal_check_interval": "5",
"retry_check_interval": "1",
"check_timeperiod_id": "132",
"has_been_checked": "1",
"current_check_attempt": "1",
"max_check_attempts": "5",
"last_check": "2019-10-29 08:56:58",
"next_check": "2019-10-29 09:00:42",
"state_type": "1",
"notifications_enabled": "1",
"problem_acknowledged": "0",
"passive_checks_enabled": "1",
"active_checks_enabled": "0",
"flap_detection_enabled": "1",
"is_flapping": "0",
"percent_state_change": "0",
"latency": "0.33262",
"execution_time": "0",
"scheduled_downtime_depth": "0",
"notes": "44.8479039,-93.0428119",
"notes_url": {
},
"action_url": {
}
}
]
}You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Naigosxi api request
here is my curl request and the output:
curl -k -XGET "https://x.x.x.x/nagiosxi/api/v1/objects ... ea42102192"
{
"recordcount": "0"
}
curl -k -XGET "https://x.x.x.x/nagiosxi/api/v1/objects ... ea42102192"
{
"recordcount": "0"
}
Re: Naigosxi api request
Hmm, I added a new test host, named "---i-00178cdd511":
This is still working for me, even with the dashes.
I am not using SSL but it's not likely that this is going to make a difference. I will have to discuss this our our developers to see if they can figure our what might me causing the issue.
Code: Select all
define host {
host_name ---i-00178cdd511
use xiwizard_genericnetdevice_host
address 2.2.2.2
max_check_attempts 5
check_interval 5
retry_interval 1
check_period xi_timeperiod_24x7
contacts nagiosadmin
notification_interval 60
notification_period xi_timeperiod_24x7
icon_image network_node.png
statusmap_image network_node.png
_xiwizard genericnetdevice
register 1
}
Code: Select all
[root@main-nagios-xi libexec]# curl -s -XGET "http://x.x.x.x/nagiosxi/api/v1/objects/hoststatus?apikey=xxx&pretty=1¤t_state=nin:0&name=in:CentOS-NCPA,CentOS-SSH,CentOS-NRPE,CentOS-SNMP,---i-00178cdd511" | grep name | grep -v display
"name": "CentOS-NRPE",
"name": "CentOS-NCPA",
"name": "---i-00178cdd511",Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Naigosxi api request
Are all of these hosts down - aa-test-point-window,---i-00178cdd511,---i-021a829b419,---i-0d9207ed315,---i-05cea42102192? They would show up in the REST API call only if they are down... If they are UP, nothing will be returned, unless you change your call to be:
(looking for hosts that are UP)
Code: Select all
curl -k -XGET "https://x.x.x.x/nagiosxi/api/v1/objects/hoststatus?apikey=xxxxxxx&pretty=1¤t_state=0&name=in:aa-test-point-window,---i-00178cdd511,---i-021a829b419,---i-0d9207ed315,---i-05cea42102192"Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Naigosxi api request
Thank you lmiltchev for you support.
actually some of hosts are up and others are down. cause the purpose of the request is to isolate down hosts only.
I followed the request step by step. now it's working.
Thanks.
actually some of hosts are up and others are down. cause the purpose of the request is to isolate down hosts only.
I followed the request step by step. now it's working.
Thanks.