Monitoring a remote Nagios instance

August 02, 2017

Reading time ~1 minute

Intro

I wanted a quick way to monitor a remote Nagios host from a secondary Linux server in the event the primary Nagios instance became unavailabile for any number of reasons like httpd going down.

Check if host is alive

#!/usr/bin/env bash

# Monitor if remote service (ie httpd) is down
# and alert staff/admins. Useful in the event a Nagios
# instance is hosted on same http host

########
#Server
########
SERVER=''
HOST=''
PORT=80
SERVICE='httpd'
$(nc -z -w5 $SERVER $PORT)
result=$?

######
#Mail
######
MAILTO='admin@host'
MAILFROM='noreply@host'

###############################
#check remote host/port status
###############################
if [ "$result" != 0 ]; then

    mail -s "$SERVICE service on $HOST is not responding" -r "$MAILFROM" "$MAILTO"  <<END_OF_EMAIL
$SERVICE is not listening on $HOST port $PORT. Please check.
END_OF_EMAIL

fi

exit 0


I would highly recommend Uptime Robot for an external monitoring service.

comments powered by Disqus

Generate passwords using Pwgen on Linux and macOS

Intro Pwgen is a password generator for creating easily memorable passwords. I stumbled across this tool and found it to be one of the best …… Continue reading

LDAP Mail Distribution Groups with Postfix

Published on May 01, 2018

Arch Linux Email Beta Project

Published on September 05, 2017