Nagios Object Configuration Database?

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
matt.uebel
Posts: 84
Joined: Thu Jun 20, 2013 7:43 am

Nagios Object Configuration Database?

Post 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?
User avatar
WillemDH
Posts: 2320
Joined: Wed Mar 20, 2013 5:49 am
Location: Ghent
Contact:

Re: Nagios Object Configuration Database?

Post by WillemDH »

Maybe you could use the backend API URL component?
Nagios XI 5.8.1
https://outsideit.net
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Nagios Object Configuration Database?

Post 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.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
matt.uebel
Posts: 84
Joined: Thu Jun 20, 2013 7:43 am

Re: Nagios Object Configuration Database?

Post 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.
matt.uebel
Posts: 84
Joined: Thu Jun 20, 2013 7:43 am

Re: Nagios Object Configuration Database?

Post 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?
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Nagios Object Configuration Database?

Post 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.
Former Nagios employee
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Nagios Object Configuration Database?

Post by abrist »

The object database is based on nagiosql's structure. It is rather relational, so you may be in for some nasty JOINs.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
matt.uebel
Posts: 84
Joined: Thu Jun 20, 2013 7:43 am

Re: Nagios Object Configuration Database?

Post by matt.uebel »

Does anybody have any documentation on the URL API stuff? I am having difficulty finding any.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Nagios Object Configuration Database?

Post 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
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked