Gather Contact Information Of Each Host And Service In Nagios

Gather contact information of each host and service in Nagios Doesn’t have to be hard. Read this tips and tricks to make your work easier.

Scenario: Nagios Core / Nagios XI has installed and configured as per the requirements and alerting has been enabled for contacts and contact groups, few months later your Manager / Management team asked you to provide information about hosts and services contact information like which host alerts is going to which user ( Each and every host and service alerts and there associated contacts and contact groups).

In above scenario if you want to collect / gather all the information about hosts /services and their associated contacts it is an hectic task. we have to go to each and every file and write host name, service name and its associated contacts and contact groups.

Assume if you have 1000 Hosts and Ten thousand services it may take 4days to collect and consolidate all the information together.

In this article i am going to explain easy way, we can collect and consolidate with in 30minutes of time

Gather Contact Information Of Each Host And Service In Nagios

first step login to your nagios server using SSH service (Putty).

Below path is for NagiosXI version

[Nagios@ArkIT ~]$ cd /usr/local/nagios/etc/hosts/
[Nagios@ArkIT ~]$ cat * |grep -E "host_name|contact" > /tmp/hosts

[Nagios@Arkit ~]$ cd /usr/local/nagios/etc/services/
[Nagios@ArkIT ~]$ cat * |grep -E "host_name|service_description|contact" > /tmp/services

Below path is for Nagios Core ( If your environment is customized then use appropriate path )

[NagiosCore@ArkIT ~]$ cd /usr/local/nagios/etc/objects/[NagiosCore@ArkIT ~]$ cat * |grep -E "host_name|contact" > /tmp/hosts
[NagiosCore@ArkIT ~]$ cat * |grep -E "host_name|service_description|contact" > /tmp/services

Now we have collected the hosts / services and associated contacts and contact groups but the data is not in a proper way, data format will be as shown below

       host_name                       Server1.arkit.co.in
        contacts                        aravi
        contact_groups                  DL-Linux
        host_name                       Server2.arkit.co.in
        contacts                        kumar
        contact_groups                  DL-windows
        host_name                       Server3.arkit.co.in
        contacts                        ramana,aravi
        contact_groups                  DL-Administrator,IT-Team

We required hosts output like below

Server1.arkit.co.in aravi,DL-LinuxServer2.arkit.co.in kumar,DL-windowsServer3.arkit.co.in ramana,aravi,DL-Administrator,IT-Team

We required services output like below

Server1.arkit.co.in Ping aravi,DL-LinuxServer1.arkit.co.in CPU Load aravi,DL-LinuxServer2.arkit.co.in Ping Kumar,DL-WindowsServer2.arkit.co.in Web Server DL-webteam,kumar,ramana

To do this i have made few scripts which will do our job in less time, to generate host contacts use below script

[Nagios@ArkIT tmp]$ export output=; while read line; do if [[ "$line" =~ "host_name" ]]; then export output="${output}\n"; fi; export output="${output}, $line"; done < /tmp/hosts && echo -e $output | sed 's/^, \?//' | sed '/^$/d' > /tmp/comahosts

To Generate Services contacts information use below script

[Nagios@ArkIT tmp]$ export output=; while read line; do if [[ "$line" =~ "service_description" ]]; then export output="${output}\n"; fi; export output="${output}, $line"; done < /tmp/services && echo -e $output | sed 's/^, \?//' | sed '/^$/d' > /tmp/comaservices

After running above scripts our data will be available in /tmp/comahosts and /tmp/comaservices files, just open them in Excel file delimiter comma separated

Replace host_name, contacts, contact_groups and service_description with blank

find and replace

That’s your excel sheet ready with all the information.

Gather contact information of each host and service in Nagios

conclusion

We can easily collect Nagios hosts /services contact, contact group information using above method in quick way.

Thanks for the read please do comment your feedback on comment section

 

Thanks for your wonderful Support and Encouragement

Ravi Kumar Ankam

My Name is ARK. Expert in grasping any new technology, Interested in Sharing the knowledge. Learn more & Earn More

Leave a Reply

Your email address will not be published. Required fields are marked *