Listing all Hosts & Services without default contacts or contactgroups defined?

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Post Reply
TBT
Posts: 625
Joined: Wed May 18, 2011 1:26 pm

Listing all Hosts & Services without default contacts or contactgroups defined?

Post by TBT »

Upon restarting the nagios service, I noticed output warning of Hosts/Services that have no default contacts or contactgroups defined. It would be useful to determine all Host/Services in a similar state, is there a stand-alone script I can run to generate a list?

Code: Select all

Apr 02 18:49:32 nagios nagios[5317]: Warning: Service 'Memory Usage' on host 'hostname1-removed' has no default contacts or contactgroups defined!
Apr 02 18:49:32 nagios nagios[5317]: Warning: Service 'Swap Usage' on host 'hostname1-removed' has no default contacts or contactgroups defined!
Apr 02 18:49:32 nagios nagios[5317]: Warning: Service 'CPU Usage' on host 'hostname2-removed' has no default contacts or contactgroups defined!
Apr 02 18:49:32 nagios nagios[5317]: Warning: Service 'Disk Usage on C:/' on host 'hostname2-removed' has no default contacts or contactgroups defined!
Apr 02 18:49:32 nagios nagios[5317]: Warning: Service 'Memory Usage' on host 'hostname2-removed' has no default contacts or contactgroups defined!
Apr 02 18:49:32 nagios nagios[5317]: Warning: Service 'Swap Usage' on host 'hostname2-removed' has no default contacts or contactgroups defined!
Apr 02 18:49:32 nagios nagios[5317]: Warning: Host 'hostname1-removed' has no default contacts or contactgroups defined!
Apr 02 18:49:32 nagios nagios[5317]: Warning: Host 'hostname2-removed' has no default contacts or contactgroups defined!
Apr 02 18:49:32 nagios nagios[5317]: Warning: Host 'hostname3-removed' has no default contacts or contactgroups defined!
Nagios XI 2024R2.2.1 (8 Servers)
Nagios Fusion 2024R1.0.2
DoubleDoubleA
Posts: 273
Joined: Thu Feb 09, 2017 5:07 pm

Re: Listing all Hosts & Services without default contacts or contactgroups defined?

Post by DoubleDoubleA »

I don't know about an existing script, but you could run this against your hosts and services config directories (/usr/local/nagios/etc/hosts and /usr/local/nagios/etc/services):

Code: Select all

#! /bin/bash
for file in *; do
        if ! cat "$file" | grep contact -q; then
                echo "$file"
        fi
done
in theory it will output the filename of any *active config that doesn't have any contacts or contact_groups defined.

If you have any configs set as not active via the CCM, those will not be picked up, and we'd likely have to write a sql command. Which I suppose I could have done but I didn't think about the inactive exception before I had the bash sorted.

Disclaimer: works on my machine, let me know how it works on yours.

Aaron
kg2857
Posts: 490
Joined: Wed Apr 12, 2023 5:48 pm

Re: Listing all Hosts & Services without default contacts or contactgroups defined?

Post by kg2857 »

I've seen cat | grep in training classes on slides. Gruesome. Teaching people to do dumb stuff is unwise.
grep contact -q "$file"

grep "no default contacts" /<path>/logfile | cut -n x (where x is the number of character so get past the date) | sort -u

The above gives a sorted list of unique hosts/services that meet the criteria.
Post Reply