Page 1 of 1

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

Posted: Thu Apr 03, 2025 1:16 pm
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!

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

Posted: Thu Apr 03, 2025 3:49 pm
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

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

Posted: Thu Apr 03, 2025 11:32 pm
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.