Page 1 of 1

Nagios Object Configuration Database?

Posted: Mon Oct 28, 2013 6:56 am
by matt.uebel
I have been writing a set of scripts which read the Nagios configuration files, as well as the objects.cache file, in order to generate a CSV of host-service-contact to property. For instance, a list of hosts and the actual hostgroups that the host is in. Or what contact groups are assigned to some service.

An example:

Code: Select all

#!/bin/bash

awk 'BEGIN { print "host,template" }
	/^define host \{/{
	while ( $1 != "}" )
	{
		getline
		if ( $1 == "host_name" )
		{
			HN=$NF
		}	
                if ( index($1,"use") > 0  )
                {
                        i=3;
                        template=$2;
                        while ( i <= NF )
                        {
                                template=template "," $i
                                i=i+1;
                        }
                }
	}
        print HN "," "\""template"\""
	HN="";
	template="";
}' /usr/local/nagios/etc/hosts/*
I am starting to think about writing something to output ALL of the properties of a host.

What I am wondering is if I am reinventing the wheel here. Has anybody already done this? Is there a way to get at this data by some mechanism that XI already has?

Re: Nagios Object Configuration Database?

Posted: Mon Oct 28, 2013 8:33 am
by WillemDH
Maybe you could use the backend API URL component?

Re: Nagios Object Configuration Database?

Posted: Mon Oct 28, 2013 9:57 am
by abrist
The backend may not contain all the data or correlations:

Code: Select all

http://<ip>/nagiosxi/backend/?cmd=gethoststatus
http://<ip>/nagiosxi/backend/?cmd=getcontacts
But I don't think configured contacts are linked to the objects in the possible backend api results.

I am working on some thing (a little web ui/frontend sdk) to search the object/status information using a client-side model and the new JSON cgis, but it is still in development.

Re: Nagios Object Configuration Database?

Posted: Mon Oct 28, 2013 10:02 am
by matt.uebel
That API looks very interesting, haven't seen it yet. However, as abrist mentioned, it doesn't seem to get all the info I want. Hostgroup configuration, template configuration, contact groups etc.

Re: Nagios Object Configuration Database?

Posted: Mon Oct 28, 2013 10:18 am
by matt.uebel
Can I get to all the info I want from querying the XI backend DBs? (mysql and/or postgresql?)

What kind of queries would I want in that case?

Re: Nagios Object Configuration Database?

Posted: Mon Oct 28, 2013 10:33 am
by tmcdonald
In theory, yes. XI obviously provides some Controller-level logic (assuming a MVC structure) to make connections between databses, but generally all the good stuff is in a DB somewhere. HOWEVER! This is dangerous territory. You have the capability to easily and majorly mess things up when you tread into the realm of manual SQL. If you stick to just reading you should be fine, but I cannot emphasize enough how careful you should be anyway. Double-check your queries, make backups, etc etc.

That said, take a look at this: http://nagios.sourceforge.net/docs/ndou ... _Model.pdf

It is a bit dated, but the databases haven't changed much it seems. As for specific queries, that is not a subject I want to touch with a 10-foot pole.

Re: Nagios Object Configuration Database?

Posted: Mon Oct 28, 2013 10:38 am
by abrist
The object database is based on nagiosql's structure. It is rather relational, so you may be in for some nasty JOINs.

Re: Nagios Object Configuration Database?

Posted: Fri Nov 01, 2013 2:05 pm
by matt.uebel
Does anybody have any documentation on the URL API stuff? I am having difficulty finding any.

Re: Nagios Object Configuration Database?

Posted: Fri Nov 01, 2013 2:25 pm
by abrist
Below, you will find a document and a video to get you started!
http://assets.nagios.com/downloads/nagi ... nd_API.pdf
http://www.youtube.com/watch?v=kFJrEdeCqfg