Page 1 of 1

Contacts Report

Posted: Fri May 03, 2013 9:08 am
by mkite64
How can I generate an easy-to-read list of all contacts and what each contact gets notified for? My bosses can't read .cfg files and have requested this information. Thanks.

Re: Contacts Report

Posted: Fri May 03, 2013 12:09 pm
by abrist
I just scratched out a bash one liner to grep through objects.cache. It may not be what you are looking for, but here it is:

Code: Select all

cat /usr/local/nagios/var/objects.cache | grep 'host_name\|service_description\|contacts' > /tmp/contacts.
txt

The output would look like:

Code: Select all

        host_name       ebony
        service_description     Linux Raid Status checks /proc/mdstat
        contacts        neboglory
        host_name       ebony
        service_description     Web Server Port 80 check
        contacts        neboglory
        host_name       gent
        service_description     / Disk Usage
        contacts        andy,nagiosadmin,neboglory
When I run this, I get a few commands at the top, so you can clean it up a bit more with:

Code: Select all

cat /usr/local/nagios/var/objects.cache | grep 'host_name\|service_description\|contacts' |grep -v command_name > /tmp/contacts.txt
You could add strings as you see fit. For example, you can add the notification period with:

Code: Select all

cat /usr/local/nagios/var/objects.cache | grep 'host_name\|service_description\|contacts\|notification_period' |grep -v command_name > /tmp/contacts.txt
To make it a bit more readable, we will add a sed:

Code: Select all

cat /usr/local/nagios/var/objects.cache | grep 'host_name\|service_description\|contacts\|notification_period' |grep -v command_name | sed 's/host_name/\n/g' > /tmp/contacts.txt
The final output should look like:

Code: Select all

        ebony
        service_description     Linux Raid Status checks /proc/mdstat
        contacts        neboglory
        notification_period     24x7

        ebony
        service_description     Web Server Port 80 check
        contacts        neboglory
        notification_period     24x7

        gent
        service_description     / Disk Usage
        contacts        andy,nagiosadmin,neboglory
        notification_period     xi_timeperiod_24x7
Unfortunately, the contact information is saved on a per-object basis, not the other way around. I am sure someone better with sed/awk/grep could write you a one-liner for what you are actually looking for. But here it is , anyways.