Services id's

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
SDohmen
Posts: 240
Joined: Thu Jun 30, 2011 4:14 am

Services id's

Post by SDohmen »

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.
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Services id's

Post by mguthrie »

My question is how are the generic services being determined.
I'm a little bit confused on what you mean by this...


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
SDohmen
Posts: 240
Joined: Thu Jun 30, 2011 4:14 am

Re: Services id's

Post by SDohmen »

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.
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Services id's

Post by mguthrie »

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

Post by scottwilkerson »

SDohmen 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.
If you run what mguthrie suggested
You can preview this data by accessing:
http://<yourserver>/nagiosxi/backend/?cmd=getservicestatus&combinedhost=1
You will see an XML field that is service_id

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=96
or &host_name=www.nagios.com to only show services with host_name=www.nagios.com

Code: Select all

http://<yourserver>/nagiosxi/backend/?cmd=getservicestatus&combinedhost=1&host_name=www.nagios.com
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
User avatar
niebais
Posts: 349
Joined: Tue Apr 13, 2010 2:15 pm

Re: Services id's

Post by niebais »

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.
SDohmen
Posts: 240
Joined: Thu Jun 30, 2011 4:14 am

Re: Services id's

Post by SDohmen »

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.
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.
Some example queries would be nice to have. It might help our programmer figure out a way around it.
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Services id's

Post by mguthrie »

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:

Code: Select all

service_description myService
host_name     host1,host2,host3,host4,host5,host6
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:

Code: Select all

service_description myService
host_name     host1

Code: Select all

service_description myService
host_name     host2
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:

Code: Select all

$backendargs["cmd"]="getservicestatus";
$backendargs["combinedhost"]=1;
$backendargs["service_description"] = "myService";
//get the XML data
$xml=get_xml_service_status($backendargs);
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.
Locked