Get a nice text or CSV dump of all configured alerts

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
rez1sog
Posts: 38
Joined: Fri Mar 16, 2012 6:02 am

Get a nice text or CSV dump of all configured alerts

Post by rez1sog »

Is there away to get either a nice text or CSV type data dump of all the hosts/alerts that are configured on the server? Something that has a line for each monitor service that includes the host, service, check, settings, etc?

I can not really fine a nice button on the server to press that generates this? Perhaps a clever mysql command?


My configuration is below...


Nagios XI Installation Profile
Download Profile
System:
nagiosxi 2.6.18-308.4.1.el5 x86_64
CentOS release 5.6 (Final)
Gnome is not installed
Apache Information
PHP Version: 5.1.6
Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1
Server Name: nagiosxi
Server Address: 10.20.20.74
Server Port: 80
Date/Time
PHP Timezone: America/New_York
PHP Time: Tue, 07 Aug 2012 08:53:25 -0400
System Time: Tue, 07 Aug 2012 08:53:25 -0400
Nagios XI Data
nagios (pid 3806) is running...
NPCD running (pid 4046).
ndo2db (pid 4181) is running...
CPU Load 15: 10.50
Total Hosts: 237
Total Services: 2019
Function 'get_base_uri' returns: http://nagiosxi/nagiosxi/
Function 'get_base_url' returns: http://nagiosxi/nagiosxi/
Function 'get_backend_url(internal_call=false)' returns: http://nagiosxi/nagiosxi/includes/compo ... rofile.php
Function 'get_backend_url(internal_call=true)' returns: http://localhost/nagiosxi/backend/
User avatar
nscott
Posts: 1040
Joined: Wed May 11, 2011 8:54 am

Re: Get a nice text or CSV dump of all configured alerts

Post by nscott »

Could you give some sample output of what you're looking for?
Nicholas Scott
Former Nagios employee
rez1sog
Posts: 38
Joined: Fri Mar 16, 2012 6:02 am

Re: Get a nice text or CSV dump of all configured alerts

Post by rez1sog »

Sure. I can be flexible. Something like a csv with:


host, service, command, options, who gets notified, monitoring period, time periods


The "host, service, command, options, who gets notified" is the important part, the rest is nice to have as well. A mysql command or something that did this would be great. It would allow us to do this on the fly and keep our spreadsheets up to date.
User avatar
nscott
Posts: 1040
Joined: Wed May 11, 2011 8:54 am

Re: Get a nice text or CSV dump of all configured alerts

Post by nscott »

What do you think about the 'Notifications' page under the Reports heading? Does somewhat accomplish what you're looking for?
Nicholas Scott
Former Nagios employee
rez1sog
Posts: 38
Joined: Fri Mar 16, 2012 6:02 am

Re: Get a nice text or CSV dump of all configured alerts

Post by rez1sog »

I have been there, but it is not what I want. That shows all the alerts that have happened in a given period. It is very nice to look at, but I want a list of all the hosts/services that are configured on the system in a nice CSV format. Not what is alerting.

Any other thoughts?
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Get a nice text or CSV dump of all configured alerts

Post by mguthrie »

We also have a backend API that returns XML data that you could use to fetch a list of all currently monitored hosts and or services.

Examples
http://yourserver/nagiosxi/backend/?cmd=gethoststatus
http://yourserver/nagiosxi/backend/?cmd ... vicestatus
http://yourserver/nagiosxi/backend/?cmd ... &brevity=3
http://yourserver/nagiosxi/backend/?cmd ... inedhost=1
User avatar
nscott
Posts: 1040
Joined: Wed May 11, 2011 8:54 am

Re: Get a nice text or CSV dump of all configured alerts

Post by nscott »

Or here is the SQL for accessing the database and getting what you want:

Code: Select all

SELECT DISTINCT
        nagios_hosts.display_name as HostName,
        nagios_services.display_name as ServiceName,
        nagios_commands.command_line as CommandLine,
        nagios_services.check_command_args as CommandArguments,
        nagios_services.check_interval as CheckInterval,
        (SELECT GROUP_CONCAT(alias) FROM nagios_contacts),
        nagios_timeperiods.alias as Timeperiod
    FROM 
        nagios_services
    JOIN
        nagios_hosts
        ON
            nagios_hosts.host_object_id=nagios_services.host_object_id
    JOIN
        nagios_commands
        ON
            nagios_commands.object_id=nagios_services.check_command_object_id
    JOIN
        nagios_service_contacts
        ON
            nagios_service_contacts.service_id=nagios_services.service_id
    JOIN
        nagios_contacts
        ON 
            nagios_contacts.contact_object_id=nagios_service_contacts.contact_object_id
    JOIN
        nagios_timeperiods
        ON
            nagios_timeperiods.timeperiod_object_id=nagios_services.check_timeperiod_object_id;
doing a

mysql -u root -p[rootpassword] nagios < [path to this sql file]

Where [rootpassword] would be replaced by your MySQL root password (you could also use the ndoutils acccount). This will yield tab delimited results.
Nicholas Scott
Former Nagios employee
rez1sog
Posts: 38
Joined: Fri Mar 16, 2012 6:02 am

Re: Get a nice text or CSV dump of all configured alerts

Post by rez1sog »

I got to admit, that was way cool. I was able to get the results that I wanted with a little fudging.

What else can this backend thingie do? Is there a doc on it somewhere?
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Get a nice text or CSV dump of all configured alerts

Post by slansing »

We certainly do have a document on it!

Found here:

http://assets.nagios.com/downloads/nagi ... nd_API.pdf
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Get a nice text or CSV dump of all configured alerts

Post by mguthrie »

These are a few other commands for the backend API, and most of them take arguments, but it depends on what you need. Unfortunately we don't have much documentation on all of parameters at this time, but if you need them we can get them to you:

backend/?cmd=

• gethoststatus
• getservicestatus
• gethosts
• getservices
• getcomments
• getprogramstatus
• getusers
• getparenthosts
• getcontacts
• gethostgroups
• gethostgroupmembers
• getservicegrouphostmembers
• getcustomhostvariablestatus
• getstatehistory
• getnotifications
Locked