Our programmer is busy with writing several components to make our normal work easier. Today he kinda hit a speedbump because he couldn't find a generic id for a service.
The thing he found is that each service gets its own id which is linked to the host. My question is how are the generic services being determined. The thing he needs it for is one of our new components which is able to show several services as 1 in a bbmap style overview. Normally it wouldn't be a problem to use the normal service name but we tend to have a very nice co-worker who kinda changes names every day which will destroy the component again.
If there are no generic service id's does anyone perhaps have an idea how we could solve it without strapping our co-worker to a tree.
Services id's
Re: Services id's
I'm a little bit confused on what you mean by this...My question is how are the generic services being determined.
XI actually uses unique services ID's for all of the services so that the names can be changed without dropping all of the data. For your component, I might suggest the following call, which would fetch data for all hosts, with their corresponding services.
$backendargs["cmd"]="getservicestatus";
$backendargs["combinedhost"]=1;
//get the XML data
$xml=get_xml_service_status($backendargs);
You can preview this data by accessing:
[url]http://<yourserver>/nagiosxi/backend/?cmd=getservicestatus&combinedhost=1[/url]
Also, we just posted a doc on Xi Component Development that references a starting list for our backend data, it might be worth a look.
http://assets.nagios.com/downloads/nagi ... opment.pdf
Re: Services id's
We found the things you described before already.
What we are looking for is a id or something which doesn't change, what we can use to find the service and use it as a group item.
What we are looking for is a id or something which doesn't change, what we can use to find the service and use it as a group item.
Re: Services id's
When you retrieve the service XML, the service_id and host_id's are unique ID's that don't change in the DB even if the host name or service description get changed.
<servicestatus id="68541">
<instance_id>1</instance_id>
<service_id>332</service_id>
<host_id>312</host_id>
<host_name>_testhost_5</host_name>
<name>_testservice_ping</name>
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Services id's
If you run what mguthrie suggestedSDohmen wrote:We found the things you described before already.
What we are looking for is a id or something which doesn't change, what we can use to find the service and use it as a group item.
You will see an XML field that is service_idYou can preview this data by accessing:
http://<yourserver>/nagiosxi/backend/?cmd=getservicestatus&combinedhost=1
This is unique to the service. With the new backend api you can also add params to the URL like &service_id=96 to only show that service
Code: Select all
http://<yourserver>/nagiosxi/backend/?cmd=getservicestatus&combinedhost=1&service_id=96Code: Select all
http://<yourserver>/nagiosxi/backend/?cmd=getservicestatus&combinedhost=1&host_name=www.nagios.comRe: Services id's
For API programming, we usually make 3 calls to the backend api and we combine the values:
$hoststatus_url = 'http://'.$_SERVER['SERVER_NAME'].'/nagiosxi/backend/?cmd=gethoststatus&username=MYAPIUSERNAME&ticket={TICKET_STRING}';
$hostgroupmembers_url = 'http://'.$_SERVER['SERVER_NAME'].'/nagiosxi/backend/?cmd=gethostgroupmembers&username=MYAPIUSERNAME&ticket={TICKET_STRING)';
$hosts_url = 'http://'.$_SERVER['SERVER_NAME'].'/nagiosxi/backend/?cmd=gethosts&username=MYAPIUSERNAME&ticket={TICKET_STRING}';
Get the hoststatus, hostgroupmembers, and the hosts. Same goes with the services from the backend api. In most cases we found that it was much quicker to go directly to the database to get the information.
If you want some sample DB queries, let me know.
$hoststatus_url = 'http://'.$_SERVER['SERVER_NAME'].'/nagiosxi/backend/?cmd=gethoststatus&username=MYAPIUSERNAME&ticket={TICKET_STRING}';
$hostgroupmembers_url = 'http://'.$_SERVER['SERVER_NAME'].'/nagiosxi/backend/?cmd=gethostgroupmembers&username=MYAPIUSERNAME&ticket={TICKET_STRING)';
$hosts_url = 'http://'.$_SERVER['SERVER_NAME'].'/nagiosxi/backend/?cmd=gethosts&username=MYAPIUSERNAME&ticket={TICKET_STRING}';
Get the hoststatus, hostgroupmembers, and the hosts. Same goes with the services from the backend api. In most cases we found that it was much quicker to go directly to the database to get the information.
If you want some sample DB queries, let me know.
Re: Services id's
Thanks for all the answers.
I might be wrong here but i checked out the xml's you described. What i see is a service id for each service defined. The problem we are facing is when i have a service called ping and i have it on 10 hosts, it also creates 10 service id's instead of 1 global one. Am i wrong here or am i perhaps looking at the wrong files? I cant find a general service id anywhere.
I might be wrong here but i checked out the xml's you described. What i see is a service id for each service defined. The problem we are facing is when i have a service called ping and i have it on 10 hosts, it also creates 10 service id's instead of 1 global one. Am i wrong here or am i perhaps looking at the wrong files? I cant find a general service id anywhere.
Some example queries would be nice to have. It might help our programmer figure out a way around it.niebais wrote:For API programming, we usually make 3 calls to the backend api and we combine the values:
$hoststatus_url = 'http://'.$_SERVER['SERVER_NAME'].'/nagiosxi/backend/?cmd=gethoststatus&username=MYAPIUSERNAME&ticket={TICKET_STRING}';
$hostgroupmembers_url = 'http://'.$_SERVER['SERVER_NAME'].'/nagiosxi/backend/?cmd=gethostgroupmembers&username=MYAPIUSERNAME&ticket={TICKET_STRING)';
$hosts_url = 'http://'.$_SERVER['SERVER_NAME'].'/nagiosxi/backend/?cmd=gethosts&username=MYAPIUSERNAME&ticket={TICKET_STRING}';
Get the hoststatus, hostgroupmembers, and the hosts. Same goes with the services from the backend api. In most cases we found that it was much quicker to go directly to the database to get the information.
If you want some sample DB queries, let me know.
Re: Services id's
OK, I think I see where the confusion is here. Lets say you create a new service called myService, and apply it to 10 hosts. In the config files you'll see something like:
However, what happens is that when nagios starts, it recompiles the configs into the objects.cache files, and all of those services become separate definitions:
These service as then fed to ndoutils backend, and each service (by necessity) has to have their own unique numeric id. So in order to access the host->service combinations, you could simply do an XML fetch like:
However, I should note that a search like this is case insensitive.
If that doesn't work for you, then you'll have to dive into writing your own SQL queries that do the necessary JOINS to get the data that you need.
Code: Select all
service_description myService
host_name host1,host2,host3,host4,host5,host6Code: Select all
service_description myService
host_name host1Code: Select all
service_description myService
host_name host2Code: Select all
$backendargs["cmd"]="getservicestatus";
$backendargs["combinedhost"]=1;
$backendargs["service_description"] = "myService";
//get the XML data
$xml=get_xml_service_status($backendargs);If that doesn't work for you, then you'll have to dive into writing your own SQL queries that do the necessary JOINS to get the data that you need.