Monitor Alexa with Nagios

Monitor Alexa with Nagios

Amazon Alexa devices don’t respond to ping so the default check-host-alive command doesn’t establish whether Alexa is up or down.

She does respond, however, to NMAP requests and these instructions provide a way to do that.

NMAP how to (for when a host doesn't respnod to pings)

Save check_nmap.sh somewhere, eg /usr/local/nagios_nmap/check_nmap.sh:

#!/bin/bash

# Command paths
CMDNMAP=/usr/bin/nmap
CMDGREP=/bin/grep

# Return codes:
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

HELP () {
	echo "Usage: check_host_alive_nmap -H [host or ip] [-t timeout]"
	exitstatus=$STATE_UNKNOWN
    exit $exitstatus
}

while test $# -ne 0; do
	case "$1" in
		-H)
			shift
			HOST_TO_SCAN=$1
			shift
			;;
		-t)
			shift
			HOST_TIMEOUT=$1
			shift
			;;
		-h|--help|*)
			shift
			HELP
			;;
	esac
done

# Right number of args?
if [ "x$HOST_TO_SCAN" == "x" ]
then
    echo "Usage: check_host_alive_nmap -H [host or ip] [-t timeout]"
    exitstatus=$STATE_UNKNOWN
    exit $exitstatus
fi

# Do we have grep installed?
if [ ! -f "$CMDGREP" ]; then
    echo "Error, $CMDGREP doesn't exist."
    exitstatus=$STATE_UNKNOWN
    exit $exitstatus
fi

# Do we have nmap installed?
if [ ! -f "$CMDNMAP" ]; then
    echo "Error, $CMDNMAP doesn't exist."
    exitstatus=$STATE_UNKNOWN
    exit $exitstatus
fi

NMAP_RESULT=`$CMDNMAP -sP -P0 $HOST_TO_SCAN | grep -i "host is up"`

if [ ! -z "$NMAP_RESULT" ]
then
  echo "NMAP OK: $HOST_TO_SCAN - $NMAP_RESULT"
  exitstatus=$STATE_OK
  exit $exitstatus
else
  echo "CRITICAL: $HOST_TO_SCAN - $NMAP_RESULT"
  exitstatus=$STATE_CRITICAL
  exit $exitstatus
fi



----
then
----
add a check_nmap command to /usr/local/nagios/etc/objects/commands.cfg 

# CBL added
define command {
        command_name    check_nmap
        command_line    /usr/local/nagios_nmap/check_nmap.sh -H $HOSTADDRESS$
}

---
then
---
define a host:

define host {
        use                     generic-host
        host_name               Alexa Living Room
        alias                   alexa-livingroom
        address                 amazon-b93a9714d
        check_command           check_nmap
        max_check_attempts      3
}

---
then
---
ensure that host config file is in the nagios.cfg

Restart nagios.service

Leave a Reply

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