Page 1 of 1

API for ServiceNow

Posted: Thu Feb 11, 2021 6:01 am
by FCC_Nagios_Support
Hi,

Can I procces several Nagios Tables from ServiceNow in order to get the Service Group to which event/service belongs to.
Do you have documentation of the API
Thanks

Re: API for ServiceNow

Posted: Thu Feb 11, 2021 6:34 am
by FCC_Nagios_Support
I am querying:
curl -XGET "http://10.5.1.159/nagiosxi/api/v1/objec ... 7&pretty=1"


{
"host_name": "mad63205.se.gr.fcc.es",
"service_description": "OS_Windows_1_7_CPU Usage Template",
"objecttype_id": "2",
"object_id": "21047",
"state_time": "2021-02-11 12:23:43",
"state_change": "1",
"state": "1",
"state_type": "1",
"current_check_attempt": "5",
"max_check_attempts": "5",
"last_state": "1",
"last_hard_state": "0",
"instance_id": "1",
"output": "could not fetch information from server"
},

And I obtain all the events
I would like to know to what ServiceGroup belongs to each "service_description"
Do you know the syntax?

Thanks

Re: API for ServiceNow

Posted: Thu Feb 11, 2021 7:22 am
by FCC_Nagios_Support
Is It possible to create a VIEW that can be plublished in the API

Many Thanks

Re: API for ServiceNow

Posted: Thu Feb 11, 2021 8:50 am
by jweijters
Hi,

I Think wat you are loooking for is the "/nagiosxi/api/v1/objects/servicegroupmembers"
In this API call you get the servicegroups, and all members of this servicegroup.

In the Help of NagiosXI you can find all API refrence documentation



Kind regards,

Joris Weijters

Re: API for ServiceNow

Posted: Thu Feb 11, 2021 10:33 am
by FCC_Nagios_Support
Many Thanks
What I want is to call the api for the statehistory and chain/join with service groupmembers in order to obtain event and its servicegroup
Thanks again

Re: API for ServiceNow

Posted: Thu Feb 11, 2021 6:37 pm
by benjaminsmith
Hi @FCC_Nagios_Support,

The REST API is fully documented in the user interface with example commands, just go to Help > API Docs.

We do not provide custom scripting/programming as part of product support, but I believe what you want to do here is run a command to get all the members of a particular service using the GET objects/servicegroupmember endpoint.

Code: Select all

curl -XGET "https://192.168.23.113/nagiosxi/api/v1/objects/servicegroupmembersapikey=<YOURAPIKEY>&pretty=1" -k -k
Once you have created a sequence containing all those members, you can gather the state history by using a limited query on those service group members on the GET objects/statehistory endpoint by object id.

Code: Select all

curl -XGET "https://192.168.23.113/nagiosxi/api/v1/objects/statehistory?apikey=<YOURAPIKEY>&object_id=<OBJECTID>&pretty=1" -k
Let us know how it goes.

Benjamin

Re: API for ServiceNow

Posted: Sat Feb 13, 2021 4:39 am
by FCC_Nagios_Support
Hi

I create a View in Laboratory
called
FER
CREATE VIEW FER
AS
SELECT s.object_id as object_id, n.display_name as display_name, n.service_object_id as service_id
ON s.object_id=n.service_object_id


But I cannot query by the API
[root@osboxes ~]# curl -XGET "http://192.168.1.117//nagiosxi/api/v1/o ... D&pretty=1" {
"error": "Unknown API endpoint."
}
[root@osboxes ~]#


How can I publish the VIEW in order to query it

Thanks

Re: API for ServiceNow

Posted: Mon Feb 15, 2021 2:22 pm
by ssax
You cannot call a MySQL view directly from the API, you would need to write your own custom API endpoint that calls the view and does with it what you want programmatically, see here on your system:

Code: Select all

http://YOURXISERVER/nagiosxi/help/custom-api-endpoints.php
I can submit a request to development to see if they'll add what servicegroups the service is in to the State History API endpoint if you'd like?