nagios plugins
this is my collection of linux shell scripts which serve as plugins and event handlers for nagios core.
back when i was managing nagios core 2.x solutions at both work and home, the need to either create from scratch or improve upon available nagios plugins existed. i'm now running nagios core 4.x at home and have found a need to write from scratch many new nagios plugins as well as rewrite some of my previous "from scratch" nagios plugins.
apart from plugins (scripts) that check other plugins (i.e. check_by_ftp and check_by_http) or plugins that use other plugins (i.e. check_xfinity_gateway), these plugins are independent of each other and shouldn't require dependencies not found in a typical linux distro install.
check_by_ftpcheck_by_ftp
"this plugin checks the status of a nagios plugin via ftp"
unable to utilize check_by_ssh to check the status of plugins on a linksys ea3500 wireless router, as is, i had to roll my own solution. my ea3500 is an arm powered off the shelf router with an os loaded from a rom. the ea3500 supports ftp to share files via attached usb drive. this usb drive also allows for ssh which allows for the creation of plugins to check the status of.
this script uses wget to facilitate the status check of other plugins. these other plugins need to have their output redirected to a file with the timestamp, in seconds, of said plugin being run appended to the output as performance data. this timestamp is necessary to ensure freshness of data. if this timestamp is in excess of 10 minutes (600 seconds) or missing, regardless of the status from the plugin being checked, that status will be overwritten as critical/down. this file is retrieved by wget, via ftp, which compares the timestamp and passes along the status of the plugin being checked.
i use this plugin to check the status of check_disk2, check_load2, and check_os2 on my ea3500. this is handled by another script , for simplicity, which is run from a cron folder whose content is executed every five minutes.
- check_by_ftp
-
#!/bin/sh
#
# check_by_ftp
#
# Nagios plugin to check the status of a Nagios plugin via FTP.
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -H host[:port] -f file"
exit 3
}
help() {
echo "This plugin checks the status of a Nagios plugin via FTP"
echo ""
echo "Usage: `basename $0` -H host[:port] -f file"
echo ""
echo "Options:"
echo " -H, --hostname"
echo " Host to check."
echo " -f, --file"
echo " File containing output from a Nagios plugin."
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
get_status() {
if [ "$address" = "" ] || [ "$file" = "" ]; then
help
fi
now=`date +'%s'`
command=`wget ftp://$address$file -t 1 -T 10 -qO-`
if [ "$command" = "" ]; then
exit 3
fi
modified=`echo "$command" | grep -o '[[:digit:]]\{10\}'`
command=`echo "$command" | sed 's/ | /\n/' | grep -v '[[:digit:]]\{10\}'`
if [ "$modified" != "" ]; then
if [ "`expr $now - $modified`" -gt "600" ]; then
command="`echo $command | sed 's/OK/CRITICAL/;s/WARNING/CRITICAL/'` -- Timestamp 10+ minutes old."
fi
else
command="`echo $command | sed 's/OK/CRITICAL/;s/WARNING/CRITICAL/'` -- Timestamp blank."
fi
status=`echo "$command" | grep -o '\(OK\|WARNING\|CRITICAL\|UNKNOWN\)'`
case $status in
OK)
echo "$command"
exit 0
;;
WARNING)
echo "$command"
exit 1
;;
CRITICAL)
echo "$command"
exit 2
;;
UNKNOWN)
echo "$command"
exit 3
;;
esac
}
while test $# -ge 0; do
case "$1" in
-H | --hostname)
shift
address="`echo $1`"
;;
-f | --file)
shift
file="`echo $1`"
get_status
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
check_by_httpcheck_by_http
"this plugin checks the status of a nagios plugin via http"
unable to utilize check_by_ssh to check the status of plugins on a slackware box, likely due to encryption issues, i had to roll my own solution. in addition to using its http server to test this site prior to publishing, that box also serves as a time authority and syslog repository. it does this being powered by a 100 mhz 486dx4 overdrive processor (which the bios only sees as 66 mhz) and 32 mb of ram.
this script uses wget to facilitate the status check of other plugins. these other plugins need to have their output redirected to a file with the timestamp, in seconds, of said plugin being run appended to the output as performance data. this timestamp is necessary to ensure freshness of data. if this timestamp is in excess of 10 minutes (600 seconds) or missing, regardless of the status from the plugin being checked, that status will be overwritten as critical/down. this file is retrieved by wget, via http, which compares the timestamp and passes along the status of the plugin being checked.
i use this plugin to check the status of check_disk2, check_load2, check_ntp2, and check_os2 on my slackware box. they're scheduled to execute every five minutes via cron jobs.
- check_by_http
-
#!/bin/sh
#
# check_by_http
#
# Nagios plugin to check the status of a Nagios plugin via HTTP.
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -H host[:port] -f file"
exit 3
}
help() {
echo "This plugin checks the status of a Nagios plugin via HTTP"
echo ""
echo "Usage: `basename $0` -H host[:port] -f file"
echo ""
echo "Options:"
echo " -H, --hostname"
echo " Host to check."
echo " -f, --file"
echo " File containing output from a Nagios plugin."
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
get_status() {
if [ "$address" = "" ] || [ "$file" = "" ]; then
help
fi
now=`date +'%s'`
command=`wget http://$address$file -t 1 -T 10 -qO-`
if [ "$command" = "" ]; then
exit 3
fi
modified=`echo "$command" | grep -o '[[:digit:]]\{10\}'`
command=`echo "$command" | sed 's/ | /\n/' | grep -v '[[:digit:]]\{10\}'`
if [ "$modified" != "" ]; then
if [ "`expr $now - $modified`" -gt "600" ]; then
command="`echo $command | sed 's/OK/CRITICAL/;s/WARNING/CRITICAL/'` -- Timestamp 10+ minutes old."
fi
else
command="`echo $command | sed 's/OK/CRITICAL/;s/WARNING/CRITICAL/'` -- Timestamp blank."
fi
status=`echo "$command" | grep -o '\(OK\|WARNING\|CRITICAL\|UNKNOWN\)'`
case $status in
OK)
echo "$command"
exit 0
;;
WARNING)
echo "$command"
exit 1
;;
CRITICAL)
echo "$command"
exit 2
;;
UNKNOWN)
echo "$command"
exit 3
;;
esac
}
while test $# -ge 0; do
case "$1" in
-H | --hostname)
shift
address="`echo $1`"
;;
-f | --file)
shift
file="`echo $1`"
get_status
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
check_disk2check_disk2
"this plugin checks the usage of a specified filesystem."
this script uses df to approximate basic functionality of the check_disk plugin. its output is modified for use with either check_by_ftp or check_by_http.
- check_disk2
-
#!/bin/sh
#
# check_disk2
#
# Nagios plugin to check the usage of a specified filesystem.
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -c critical% -w warning% -f filesystem"
exit 3
}
help() {
echo "This plugin checks the usage of a specified filesystem."
echo ""
echo "Usage: `basename $0` -c critical% -w warning% -f filesystem"
echo ""
echo "Options:"
echo " -c, --critical"
echo " Critical threshold percentage."
echo " -w, --warning"
echo " Warning threshold percentage."
echo " -f, --filesystem"
echo " Mounted filesystem to check."
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
check_usage() {
#if [ "$critical" = "" ] || [ "$warning" = "" ] || [ "$filesystem" = "" ] || [ ! -f "$filesystem" ]; then
# help
#fi
usage=`df $filesystem | grep -o '[[:digit:]]\{1,3\}%'`
if [ "`echo $usage | tr -d '%'`" -gt "`echo $critical | tr -d '%'`" ]; then
echo "Filesystem CRITICAL - '$filesystem' is $usage used. | `date +'%s'`"
exit 2
elif [ "`echo $usage | tr -d '%'`" -gt "`echo $warning | tr -d '%'`" ]; then
echo "Filesystem WARNING - '$filesystem' is $usage used. | `date +'%s'`"
exit 1
else
echo "Filesystem OK - '$filesystem' is $usage used. | `date +'%s'`"
exit 0
fi
}
while test $# -ge 0; do
case "$1" in
-c | --critical)
shift
critical="`echo $1`"
;;
-w | --warning)
shift
warning="`echo $1`"
;;
-f | --filesystem)
shift
filesystem="`echo $1`"
check_usage
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
check_ea3500_hostscheck_ea3500_hosts
"this plugin checks for 'rogue' dhcp hosts connected to a linksys ea3500 router by comparing against a list of known dhcp hosts."
this script uses wget to log into a linksys ea3500 wireless router to return the hostnames of granted dhcp leases. these hostnames are checked against a predefined list of known/authorized hostnames, alerting to unknown/unauthorized, or, "rogue" hostnames.
as far as i known, this script only works with firmware version 1.0.30. it's very well likely that previous firmware versions are also compatible. i do know it's incompatible with any firmware version which supports "linksys smart wi-fi".
- check_ea3500_hosts
-
#!/bin/sh
#
# check_ea3500_hosts
#
# Nagios plugin to check DHCP hosts on a Linksys EA3500 router.
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -H host[:port] -s 0|1 -u username -p password -f file"
exit 3
}
help() {
echo "This plugin checks for \"rogue\" DHCP hosts connected to a Linksys EA3500"
echo "router by comparing against a list of known DHCP hosts."
echo ""
echo "Usage: `basename $0` -H host[:port] -s 0|1 -u username -p password -f file"
echo ""
echo "Options:"
echo " -H, --hostname"
echo " Host to check."
echo " -s, --ssl"
echo " SSL: 0 = disabled; 1 = enabled"
echo " -u, --username"
echo " Web GUI username."
echo " -p, --password"
echo " Web GUI password."
echo " -f, --file"
echo " File of hosts to check against."
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
find_hosts() {
if [ "$address" = "" ] || [ "$ssl" = "" ] || [ "$username" = "" ] || [ "$password" = "" ] || [ "$file" = "" ] || [ ! -f "$file" ]; then
help
fi
rogues=""
if [ "$ssl" = 1 ]; then
command=`wget https://$address/DHCPTable.asp --http-user=$username --http-password=$password -t 1 -T 10 --no-check-certificate -qO-`
elif [ "$ssl" = 0 ]; then
command=`wget http://$address/DHCPTable.asp --http-user=$username --http-password=$password -t 1 T 10 -qO-`
else
help
fi
if [ "$command" = "" ]; then
echo "DHCP Hosts CRITICAL - Authentication failure."
exit 2
fi
unknowns=`echo "$command" | grep "^table\[[[:digit:]]\{1,255\}\] = new AAA" | grep -o "('\(\*\|[-_[:digit:][:alpha:]]\{1,63\}\)'," | sed 's/\*/<none>/g' | tr -d "('," | tr '\r\n' ' ' && echo`
knowns=$unknowns
IFS=' ' read -a hosts <<< $unknowns
for host in ${unknowns[@]}; do
grep \\b$host\\b $file > /dev/null 2>&1
if [ $? = 1 ]; then
rogues+="$host "
fi
done
if [ "$rogues" = "" ]; then
if [ "$unknowns" = "" ]; then
echo "DHCP Hosts OK - No DHCP hosts found."
exit 0
else
echo "DHCP Hosts OK - Known DHCP host(s) found (`echo $knowns | sed 's/ /\n/g' | grep -c '\(<none>\|[-[:digit:][:alpha:]]\{1,63\}\)'`): `echo $knowns | sed 's/ *$//g' | sed 's/ /, /g'`"
exit 0
fi
else
echo "DHCP Hosts WARNING - Rogue DHCP host(s) found (`echo $rogues | sed 's/ /\n/g' | grep -c '\(<none>\|[-[:digit:][:alpha:]]\{1,63\}\)'`): `echo $rogues | sed 's/ *$//g' | sed 's/ /, /g'`"
exit 1
fi
}
while test $# -ge 0; do
case "$1" in
-H | --hostname)
shift
address="`echo $1`"
;;
-s | --ssl)
shift
ssl="`echo $1`"
;;
-u | --username)
shift
username="`echo $1`"
;;
-p | --password)
shift
password="`echo $1`"
;;
-f | --file)
shift
file="`echo $1`"
find_hosts
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
check_load2check_load2
"this plugin checks the current system load average."
this script uses uptime to approximate basic functionality of the check_load plugin. its output is modified for use with either check_by_ftp or check_by_http.
- check_load2
-
#!/bin/sh
#
# check_load2
#
# Nagios plugin to check the current system load average.
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -c #.##,#.##,#.## -w #.##,#.##,#.##"
exit 3
}
help() {
echo "This plugin checks the current system load average."
echo ""
echo "Usage: `basename $0` -c #.##,#.##,#.## -w #.##,#.##,#.##"
echo ""
echo "Options:"
echo " -c, --critical"
echo " Critical load average."
echo " -w, --warning"
echo " Warning load average."
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
check_load() {
if [ "$critical" = "" ] || [ "$warning" = "" ]; then
help
fi
command=`uptime | grep -o '[[:digit:]]\{1,\}\.[[:digit:]]\{2\}, [[:digit:]]\{1,\}\.[[:digit:]]\{2\}, [[:digit:]]\{1,\}\.[[:digit:]]\{2\}' | tr -d ','`
load=`echo "$command" | tr -d '.'`
critical=`echo "$critical" | sed 's/\.//g;s/,/ /g'`
warning=`echo "$warning" | sed 's/\.//g;s/,/ /g'`
n=0
for l in $load; do
eval l$n=$l
n=`expr "$n" + 1`
done
n=0
for c in $critical; do
if [ "`eval \"echo \\$l$n\"`" -gt "$c" ]; then
echo "Load CRITICAL - Load average: '`echo $command | sed 's/ /, /g'`'. | `date +'%s'`"
exit 2
fi
n=`expr "$n" + 1`
done
n=0
for w in $warning; do
if [ "`eval \"echo \\$l$n\"`" -gt "$w" ]; then
echo "Load WARNING - Load average: '`echo $command | sed 's/ /, /g'`'. | `date +'%s'`"
exit 1
fi
n=`expr "$n" + 1`
done
echo "Load OK - Load average: '`echo $command | sed 's/ /, /g'`'. | `date +'%s'`"
exit 0
}
while test $# -ge 0; do
case "$1" in
-c | --critical)
shift
critical="`echo $1`"
;;
-w | --warning)
shift
warning="`echo $1`"
check_load
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
check_mrtg2check_mrtg2
"nagios plugin to check the status of mrtg."
this script uses pf to determine if the mrtg daemon is running. it will also verify that a specified log file has been modified within 10 minutes, otherwise alerting on a stale log.
- check_mrtg2
-
#!/bin/sh
#
# check_mrtg2
#
# Nagios plugin to check the status of MRTG.
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -b binary -l log"
exit 3
}
help() {
echo "Nagios plugin to check the status of MRTG."
echo ""
echo "Usage: `basename $0` -b binary -l log"
echo ""
echo "Options:"
echo " -b, --binary"
echo " MRTG binary."
echo " -l, --log"
echo " An MRTG log to check."
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
check_mrtg() {
if [ "$binary" = "" ] || [ "$log" = "" ]; then
help
fi
command=`ps -ef | grep -m 1 $binary`
if [ -x "$binary" ]; then
if [ "$command" != "" ]; then
result=1
else
result=0
fi
else
result=0
fi
if [ -f "$log" ]; then
now=`date +'%s'`
modified=`stat -c %Y $log`
command=`expr $now - $modified`
if [ "$command" -gt "600" ]; then
result=$result
else
result=$(( $result + 1 ))
fi
else
result=$result
fi
case "$result" in
0)
echo "MRTG CRITICAL - MRTG daemon not running and log file 10+ minutes old."
exit 2
;;
1)
echo "MRTG WARNING - MRTG daemon not running or log file 10+ minutes old."
exit 1
;;
2)
echo "MRTG OK - MRTG daemon running and log file -10 minutes old."
exit 0
;;
*)
echo "MRTG UNKNOWN - Unknown error."
exit 3
;;
esac
}
while test $# -ge 0; do
case "$1" in
-b | --binary)
shift
binary="`echo $1`"
;;
-l | --log)
shift
log="`echo $1`"
check_mrtg
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
check_mysqlcheck_mysql
"this plugin checks the current status of the mysql server running on the specified host."
this script, written in php, logs into a mysql server and executes the equivalent of the status and \s commands, returning the last line of output (containing metrics).
- check_mysql
-
#!/usr/bin/php
<?php
/*
check_mysql
Nagios plugin to check MySQL.
(C)MMXIV Ickis <ickis@nerpter77.com>. All rights reserved.
http://nerpter77.com/
Permission to use, copy, modify, and distribute this software and its
documentation for non-commercial or commercial purposes and without fee is
hereby granted. This software and its documentation is provided "as is".
Sorry, I don't like to comment ^_^
*/
error_reporting(0);
$short_options = '';
$short_options .= 'H:';
$short_options .= 'u:';
$short_options .= 'p:';
$short_options .= 'h::';
$long_options = array(
"hostname:",
"username:",
"password:",
"help::",
);
$options = getopt($short_options, $long_options);
function elapsed($n)
{
$days = 86400;
$hours = 3600;
$minutes = 60;
$seconds = 1;
$d = intval($n / $days);
$h = intval(($n % $days) / $hours);
$m = intval((($n % $days) % $hours) / $minutes);
$s = intval(((($n % $days) % $hours) % $minutes) / $seconds);
$int_vals = array($d, $h, $m, $s);
$int_names = array('day', 'hour', 'minute', 'second');
$s = '';
for ($i = 0; $i <= (count($int_vals) - 1); $i++)
{
if ($int_vals[$i] > 0)
{
if ($s == '') $s = $int_vals[$i] . ' ' . plural($int_names[$i], $int_vals[$i]);
else $s .= ', ' . $int_vals[$i] . ' ' . plural($int_names[$i], $int_vals[$i]);
}
}
if ($s == '') $s = '0 minutes';
$commas = substr_count($s, ',');
if ($commas > 1): $s = substr($s, 0, strrpos($s, ',') + 1) . ' and' . substr($s, strrpos($s, ',') + 1, strlen($s) - 1);
elseif ($commas == 1): $s = str_replace(',', ' and', $s);
endif;
return $s;
}
function plural($s, $v)
{
if ($v != 1) $s .= 's';
return $s;
}
if (empty($options))
{
print('Usage: ' . basename($argv[0]) . ' -H hostname -u user -p password' . "\n");
exit(3);
}
elseif (isset($options['h']) || isset($options['help']))
{
print('This plugin checks the current status of the MySQL server running on the' . "\n" .
'specified host.' . "\n" .
"\n" .
'Usage: ' . basename($argv[0]) . ' -H hostname -u user -p password' . "\n" .
"\n" .
'Options:' . "\n" .
' -H, --hostname' . "\n" .
' MySQL server to check.' . "\n" .
' -u, --username' . "\n" .
' MySQL user.' . "\n" .
' -p, --password' . "\n" .
' MySQL password.' . "\n" .
' -h, --help' . "\n" .
' Print help/usage information.' . "\n");
exit(3);
}
$hostname = $options['H'];
if ($hostname == '') $hostname = $options['hostname'];
$username = $options['u'];
if ($username == '') $username = $options['username'];
$password = $options['p'];
if ($password == '') $password = $options['password'];
if ($link = mysql_connect($hostname, $username, $password))
{
$stats = explode(' ', mysql_stat($link));
mysql_close($link);
$a = explode(' ', $stats[0]);
$a[1] = elapsed($a[1]);
$stats[0] = implode(' ', $a);
$stats = implode(' ', $stats);
print('MySQL OK - ' . $stats . "\n");
exit(0);
}
else
{
print('MySQL CRITICAL - MySQL server inaccessible.' . "\n");
exit(2);
}
print('MySQL UNKNOWN - Unspecified error.' . "\n");
exit(3);
?>
check_ntp2check_ntp2
"this plugin tests to see if ntp is running on the specified host by testing the status of udp port 123 on the specified host. (deprecated)"
this script uses nmap, via sudo, to check the status, open or closed, of udp port 123 (ntp).
deprecated, use check_nudp instead.
- check_ntp2
-
#!/bin/sh
#
# check_ntp
#
# Nagios plugin to check NTP. (DEPRECATED)
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -H host (DEPRECATED)"
exit 0
}
help() {
echo "This plugin tests to see if NTP is running on the specified host by testing"
echo "the status of UDP port 123 on the specified host. (DEPRECATED)"
echo ""
echo "Usage: `basename $0` -H host"
echo "Options:"
echo " -H, --hostname=ADDRESS"
echo " Host to check."
echo " -h, --help"
echo " Print help/usage information."
exit 0
}
check_status() {
command="`sudo /usr/bin/nmap -sU -p 123 $address 2>&1 | grep -o '123/udp[[:space:]][[:print:]]*'`"
status="`echo $command | grep -o '\(open\|closed\)'`"
case $status in
open)
echo "NTP OK - UDP port 123 open."
exit 0
;;
closed)
echo "NTP CRITICAL - UDP port 123 closed."
exit 2
;;
*)
echo "NTP UNKNOWN - Unknown/malformed host or nmap not installed."
exit 3
;;
esac
}
while test $# -ge 0; do
case "$1" in
-H | --hostname)
shift
address="`echo $1`"
if [ "$address" = "" ]; then
help
fi
check_status
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
check_nudpcheck_nudp
"nagios plugin to check the status of a specified udp port using nmap."
this script uses nmap, via sudo, to check the status, open or closed, of any udp port.
the check_udp plugin requires a string to be sent and a string to expect in response. this fails with udp services such as syslog.
- check_nudp
-
#!/bin/sh
#
# check_nudp
#
# Nagios plugin to check the status of a specified UDP port using Nmap.
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -H host -p port"
exit 3
}
help() {
echo "Nagios plugin to check the status of a specified UDP port using Nmap."
echo ""
echo "Usage: `basename $0` -H host -p port"
echo ""
echo "Options:"
echo " -H, --hostname"
echo " Host to check."
echo " -p, --port"
echo " UDP port to check."
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
check_port() {
if [ ! -x /usr/bin/nmap ]; then
echo "UDP UNKNOWN - Nmap not found."
exit 3
elif [ "$address" = "" ] || [ "$port" = "" ]; then
help
fi
command="`sudo -S nmap -sU -p $port $address`"
if [ "$command" = "" ]; then
echo "UDP UNKNOWN - Nmap may require root privileges."
exit 3
fi
result="`echo $command | grep -o '\(open\|closed\)'`"
response="`echo $command | grep -o '[[:digit:]]\{1,\}\.[[:digit:]]\{2\} second[s]\?'`"
if [ "$result" = "closed" ]; then
echo "UDP CRITICAL - $response response time on $address port $port."
exit 2
elif [ "$result" = "open" ]; then
echo "UDP OK - $response response time on $address port $port."
exit 0
else
echo "UDP UNKNOWN - Sudo may require a TTY to run Nmap."
exit 3
fi
}
while test $# -ge 0; do
case "$1" in
-H | --hostname)
shift
address="`echo $1`"
;;
-p | --port)
shift
port="`echo $1`"
check_port
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
check_oscheck_os
"this plugin checks the linux distribution and kernel version."
this plugin uses uname and uptime to find the operating system, if centos, fedora, redhat, or slackware, and if of such, release/version information, kernel version and processor architecture, as well as uptime (obvi). this plugin will only ever report okay/up.
i can never keep track of which version of which kernel is on which host, so, this saves me the time of having to log in and check.
- check_os
-
#!/bin/sh
#
# check_os
#
# Nagios plugin to check the Linux distribution and kernel version.
#
# (C)MMXIV Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0`"
exit 3
}
help() {
echo "This plugin checks the Linux distribution and kernel version."
echo ""
echo "Usage: `basename $0`"
echo ""
echo "Options:"
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
get_os() {
distro=`ls /etc | grep '\(-version\|-release\)' | grep -m 1 '\(centos\|fedora\|redhat\|slackware\)'`
uname=`uname -s -r -m`
uptime=`uptime | grep -o '\([[:digit:]]\{1,2\}:[[:digit:]]\{2\},\|[[:digit:]]\{1,\} \(day\|days\),[[:space:]]\{1,2\}\([[:digit:]]\{1,\} min\|[[:digit:]]\{1,2\}:[[:digit:]]\{2\}\),\)' | tr -d ','`
if [ "$distro" != "" ] && [ -f "/etc/$distro" ]; then
echo "OS OK - `cat /etc/$distro` [$uname] / Uptime: $uptime"
exit 0
else
echo "OS OK - $uname / Uptime: $uptime"
exit 0
fi
}
while test $# -ge 0; do
if [ "$1" = "" ]; then
get_os
else
case "$1" in
-h | --help)
help
;;
*)
usage
;;
esac
fi
shift
done
check_os2check_os2
"this plugin checks the linux distribution and kernel version."
this script is the check_os plugin with its output is modified for use with either check_by_ftp or check_by_http.
- check_os2
-
#!/bin/sh
#
# check_os2
#
# Nagios plugin to check the Linux distribution and kernel version.
#
# (C)MMXIV Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0`"
exit 3
}
help() {
echo "This plugin checks the Linux distribution and kernel version."
echo ""
echo "Usage: `basename $0`"
echo ""
echo "Options:"
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
get_os() {
distro=`ls /etc | grep '\(-version\|-release\)' | grep -m 1 '\(centos\|fedora\|redhat\|slackware\)'`
uname=`uname -s -r -m`
uptime=`uptime | grep -o '\([[:digit:]]\{1,2\}:[[:digit:]]\{2\},\|[[:digit:]]\{1,\} \(day\|days\),[[:space:]]\{1,2\}\([[:digit:]]\{1,\} min\|[[:digit:]]\{1,2\}:[[:digit:]]\{2\}\),\)' | tr -d ','`
if [ "$distro" != "" ] && [ -f "/etc/$distro" ]; then
echo "OS OK - `cat /etc/$distro` [$uname] / Uptime: $uptime | `date +'%s'`"
exit 0
else
echo "OS OK - $uname / Uptime: $uptime | `date +'%s'`"
exit 0
fi
}
while test $# -ge 0; do
if [ "$1" = "" ]; then
get_os
else
case "$1" in
-h | --help)
help
;;
*)
usage
;;
esac
fi
shift
done
check_snmp2check_snmp2
"this plugin tests to see if snmp is running on the specified host by testing the status of udp port 161 on the specified host. (deprecated)"
this script uses nmap, via sudo, to check the status, open or closed, of udp port 161 (snmp).
deprecated, use check_nudp instead.
- check_snmp2
-
#!/bin/sh
#
# check_snmp
#
# Nagios plugin to check SNMP. (DEPRECATED)
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -H host (DEPRECATED)"
exit 0
}
help() {
echo "This plugin tests to see if SNMP is running on the specified host by testing"
echo "the status of UDP port 161 on the specified host. (DEPRECATED)"
echo ""
echo "Usage: `basename $0` -H host"
echo "Options:"
echo " -H, --hostname=ADDRESS"
echo " Host to check."
echo " -h, --help"
echo " Print help/usage information."
exit 0
}
check_status() {
command="`sudo /usr/bin/nmap -sU -p 161 $address 2>&1 | grep -o '161/udp[[:space:]][[:print:]]*'`"
status="`echo $command | grep -o '\(open\|closed\)'`"
case $status in
open)
echo "SNMP OK - UDP port 161 open."
exit 0
;;
closed)
echo "SNMP CRITICAL - UDP port 161 closed."
exit 2
;;
*)
echo "SNMP UNKNOWN - Unknown/malformed host or nmap not installed."
exit 3
;;
esac
}
while test $# -ge 0; do
case "$1" in
-H | --hostname)
shift
address="`echo $1`"
if [ "$address" = "" ]; then
help
fi
check_status
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
check_ssl_expirationcheck_ssl_expiration
"this plugin checks the expiration date of an ssl certificate."
this script uses openssl to find the expiration date of the leaf ssl certificate.
i use this to check the expiration date of this site's ssl certificate. i tried using check_http to do the same but it only would return the expiration date of the root certificate.
- check_ssl_expiration
-
#!/bin/sh
#
# check_ssl_expiration
#
# Nagios plugin to check the expiration date of an SSL certificate
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -H host -c critical -w warning"
exit 3
}
help() {
echo "This plugin checks the expiration date of an SSL certificate."
echo ""
echo "Usage: `basename $0` -H host -c critical -w warning"
echo ""
echo "Options:"
echo " -H, --hostname"
echo " Host to check."
echo " -c, --critical"
echo " Critical days left to expire."
echo " -w, --warning"
echo " Warning days left to expire."
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
check_expiry() {
if [ "$address" = "" ] || [ "$critical" = "" ] || [ "$warning" = "" ]; then
help
fi
expiry_date=`openssl s_client -showcerts -servername $address -connect $address:443 < /dev/null 2>&1 | openssl x509 -noout -dates | grep 'notAfter=' | grep -o '[[:alpha:]]\{3\}[[:space:]]\{1,\}[[:digit:]]\{1,2\}[[:space:]]\{1\}[[:digit:]]\{2\}:[[:digit:]]\{2\}:[[:digit:]]\{2\}[[:space:]]\{1\}[[:digit:]]\{4\}[[:space:]]\{1\}[[:alpha:]]\{3\}'`
expiry_date=`date -d "$expiry_date" +%s`
current_date=`date +%s`
days_left=`expr $expiry_date - $current_date`
days_left=`expr $days_left / 86400`
if [ "$days_left" -le "$critical" ]; then
echo "SSL certificate expiration CRITICAL - $days_left days until expiration."
exit 2
elif [ "$days_left" -le "$warning" ]; then
echo "SSL certificate expiration WARNING - $days_left days until expiration."
exit 1
else
echo "SSL certificate expiration OK - $days_left days until expiration."
exit 0
fi
}
while test $# -ge 0; do
case "$1" in
-H | --hostname)
shift
address="`echo $1`"
;;
-c | --critical)
shift
critical="`echo $1`"
;;
-w | --warning)
shift
warning="`echo $1`"
check_expiry
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
check_syslogcheck_syslog
"this plugin tests to see if syslog is running on the specified host by testing the status of udp port 514 on the specified host. (deprecated)"
this script uses nmap, via sudo, to check the status, open or closed, of udp port 514 (syslog).
deprecated, use check_nudp instead.
- check_syslog
-
#!/bin/sh
#
# check_syslog
#
# Nagios plugin to check syslog. (DEPRECATED)
#
# (C)MMXVI Ickis <ickis "at" ickis.ulost.net>. All rights reserved.
# http://ickis.ulost.net/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -H host (DEPRECATED)"
exit 0
}
help() {
echo "This plugin tests to see if syslog is running on the specified host by testing"
echo "the status of UDP port 514 on the specified host. (DEPRECATED)"
echo ""
echo "Usage: `basename $0` -H host"
echo "Options:"
echo " -H, --hostname=ADDRESS"
echo " Host to check."
echo " -h, --help"
echo " Print help/usage information."
exit 0
}
check_status() {
command="`sudo /usr/bin/nmap -sU -p 514 $address 2>&1 | grep -o '514/udp[[:space:]][[:print:]]*'`"
status="`echo $command | grep -o '\(open\|closed\)'`"
case $status in
open)
echo "syslog OK - UDP port 514 open."
exit 0
;;
closed)
echo "syslog CRITICAL - UDP port 514 closed."
exit 2
;;
*)
echo "syslog UNKNOWN - Unknown/malformed host or nmap not installed."
exit 3
;;
esac
}
while test $# -ge 0; do
case "$1" in
-H | --hostname)
shift
address="`echo $1`"
if [ "$address" = "" ]; then
help
fi
check_status
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
check_wrt54g_hostscheck_wrt54g_hosts
"this plugin checks for 'rogue' dhcp hosts connected to a linksys wrt54g router by comparing against a list of known dhcp hosts."
this script uses wget to log into a linksys wrt54g wireless router to return the hostnames of granted dhcp leases. these hostnames are checked against a predefined list of known/authorized hostnames, alerting to unknown/unauthorized, or, "rogue" hostnames.
as far as i known, this script only works with firmware version v8.00.8. it's very well likely that previous firmware versions are also compatible.
- check_wrt54g_hosts
-
#!/bin/sh
#
# check_wrt54g_hosts
#
# Nagios plugin to check DHCP hosts on a Linksys WRT54G router.
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -H host[:port] -s 0|1 -u username -p password -f file"
exit 3
}
help() {
echo "This plugin checks for \"rogue\" DHCP hosts connected to a Linksys WRT54G"
echo "router by comparing against a list of known DHCP hosts."
echo ""
echo "Usage: `basename $0` -H host[:port] -s 0|1 -u username -p password -f file"
echo ""
echo "Options:"
echo " -H, --hostname"
echo " Host to check."
echo " -s, --ssl"
echo " SSL: 0 = disabled; 1 = enabled"
echo " -u, --username"
echo " Web GUI username."
echo " -p, --password"
echo " Web GUI password."
echo " -f, --file"
echo " File of hosts to check against."
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
find_hosts() {
if [ "$address" = "" ] || [ "$ssl" = "" ] || [ "$username" = "" ] || [ "$password" = "" ] || [ "$file" = "" ] || [ ! -f "$file" ]; then
help
fi
rogues=""
if [ "$ssl" = 1 ]; then
command=`wget https://$address/DHCPTable.htm --http-user=$username --http-password=$password -t 1 -T 10 --no-check-certificate -qO-`
elif [ "$ssl" = 0 ]; then
command=`wget http://$address/DHCPTable.htm --http-user=$username --http-password=$password -t 1 T 10 -qO-`
else
help
fi
if [ "$command" = "" ]; then
echo "DHCP Hosts CRITICAL - Authentication failure."
exit 2
fi
unknowns=`echo "$command" | grep '^\s<td>.*\s<\/td>' | grep -v '[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}' | sed 's/<td>//g' | sed 's/ <\/td>//g' | grep -o '\(<none>\|[-_[:digit:][:alpha:]]\{1,63\}\)' | tr '\r\n' ' ' && echo`
knowns=$unknowns
IFS=' ' read -a hosts <<< $unknowns
for host in ${unknowns[@]}; do
grep \\b$host\\b $file > /dev/null 2>&1
if [ $? = 1 ]; then
rogues+="$host "
fi
done
if [ "$rogues" = "" ]; then
if [ "$unknowns" = "" ]; then
echo "DHCP Hosts OK - No DHCP hosts found."
exit 0
else
echo "DHCP Hosts OK - Known DHCP host(s) found (`echo $knowns | sed 's/ /\n/g' | grep -c '\(<none>\|[-[:digit:][:alpha:]]\{1,63\}\)'`): `echo $knowns | sed 's/ *$//g' | sed 's/ /, /g'`"
exit 0
fi
else
echo "DHCP Hosts WARNING - Rogue DHCP host(s) found (`echo $rogues | sed 's/ /\n/g' | grep -c '\(<none>\|[-[:digit:][:alpha:]]\{1,63\}\)'`): `echo $rogues | sed 's/ *$//g' | sed 's/ /, /g'`"
exit 1
fi
}
while test $# -ge 0; do
case "$1" in
-H | --hostname)
shift
address="`echo $1`"
;;
-s | --ssl)
shift
ssl="`echo $1`"
;;
-u | --username)
shift
username="`echo $1`"
;;
-p | --password)
shift
password="`echo $1`"
;;
-f | --file)
shift
file="`echo $1`"
find_hosts
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
check_xfinitycheck_xfinity
"this plugin checks the dhcp assigned ip addresses from xfinity (comcast) through a d-link ebr-2310 router."
this script uses wget to log into a d-link ebr-2310 router to return the dhcp assigned ip address, gateway address, and any dns addresses.
i use this to keep track of dhcp assigned addresses from my isp (comcast) without having to log into the router to retrieve them.
- check_xfinity
-
#!/bin/sh
#
# check_xfinity
#
# Nagios plugin to check the DHCP assigned IP addresses from Xfinity (Comcast)
# through a D-Link EBR-2310 router.
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -H host[:port] -s 0|1 -u username -p password"
exit 3
}
help() {
echo "This plugin checks the DHCP assigned IP addresses from Xfinity (Comcast)"
echo "through a D-Link EBR-2310 router."
echo ""
echo "Usage: `basename $0` -H host[:port] -s 0|1 -u username -p password"
echo ""
echo "Options:"
echo " -H, --hostname"
echo " Host to check."
echo " -s, --ssl"
echo " SSL: 0 = disabled; 1 = enabled"
echo " -u, --username"
echo " Web GUI username."
echo " -p, --password"
echo " Web GUI password."
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
check_addresses() {
if [ "$address" = "" ] || [ "$ssl" = "" ] || [ "$username" = "" ] || [ "$password" = "" ]; then
help
fi
if [ "$ssl" = 1 ]; then
command=`wget https://$address/st_device.html --post-data "login_name=$username&login_pass=$password" -t 1 --no-check-certificate -qO-`
elif [ "$ssl" = 0 ]; then
command=`wget http://$address/st_device.html --post-data "login_name=$username&login_pass=$password" -t 1 -qO-`
else
help
fi
if [ "$command" = "" ]; then
echo "Xfinity CRITICAL - Authentication failure."
exit 2
fi
address=`echo "$address" | sed 's/\./\\\./g'` # Possibly redundant/unnecessary for pattern matching with grep (due to vriable expansion).
addresses=`echo "$command" | grep '\s<td> .*</td>' | grep -o '[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}' | grep -v "\($address\|255\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\)" | tr '\r\n' ' ' && echo`
IFS=' ' read -a address <<< $addresses
output=""
count=0
while [ "x${address[count]}" != "x" ]; do
case "$count" in
0)
output+="IP Address: ${address[0]}"
;;
1)
output+=", Gateway: ${address[1]}"
;;
2)
output+=", DNS: ${address[2]}"
;;
3)
if [ "${address[3]}" != "" ]; then
output+=", ${address[3]}"
fi
;;
4)
if [ "${address[4]}" != "" ]; then
output+=", ${address[4]}"
fi
;;
5)
if [ "${address[5]}" != "" ]; then
output+=", ${address[5]}"
fi
;;
esac
count=$(( $count + 1 ))
done
if [ "${address[0]}" != "" ] && [ "${address[1]}" != "" ] && [ "${address[2]}" != "" ]; then
echo "Xfinity OK - $output"
exit 0
elif [ "${address[0]}" != "" ] && [ "${address[1]}" != "" ] && [ "${address[2]}" = "" ]; then
echo "Xfinity WARNING - No DHCP address assigned."
exit 1
else
echo "Xfinity CRITICAL - No IP address and/or gateway assigned."
exit 2
fi
}
while test $# -ge 0; do
case "$1" in
-H | --hostname)
shift
address="`echo $1`"
;;
-s | --ssl)
shift
ssl="`echo $1`"
;;
-u | --username)
shift
username="`echo $1`"
;;
-p | --password)
shift
password="`echo $1`"
check_addresses
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
check_xfinity_gatewaycheck_xfinity_gateway
"this plugin "pings" the dhcp assigned gateway from xfinity (comcast) through a d-link ebr-2310 router."
this script uses wget to log into a d-link ebr-2310 router to return the dhcp assigned gateway address. while it's meant to replace check_ping for checking the availability of this specific host, since its address information is dynamically assigned via dhcp, it still utilizes check_ping. essentially, it finds the gateway address for my cable modem and passes that along to check_ping to determine the availability of my cable modem, or rather, my connectivity to the internet (via comcast).
i use this since check_ping only works with statically assigned ip addresses, not dynamically assigned ones. other than sending traffic to traverse my cable modem, i have no other way, from a monitoring standpoint, to reliably determine my connectivity to the internet... shy of selecting multiple hosts on multiple domains on multiple tier one networks to ping or probe or otherwise ascertain availability. and even then, the former, under special circumstances, may not be a dependable method for verifying internet connectivity.
- check_xfinity_gateway
-
#!/bin/sh
#
# check_xfinity_gateway
#
# Nagios plugin to "ping" the DHCP assigned gateway from Xfinity (Comcast)
# through a D-Link EBR-2310 router.
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -H host[:port] -s 0|1 -u username -p password -P check_ping"
exit 3
}
help() {
echo "This plugin \"pings\" the DHCP assigned gateway from Xfinity (Comcast) through"
echo "a D-Link EBR-2310 router."
echo ""
echo "Usage: `basename $0` -H host[:port] -s 0|1 -u username -p password -P check_ping"
echo ""
echo "Options:"
echo " -H, --hostname"
echo " Host to check."
echo " -s, --ssl"
echo " SSL: 0 = disabled; 1 = enabled"
echo " -u, --username"
echo " Web GUI username."
echo " -p, --password"
echo " Web GUI password."
echo " -P, --ping"
echo " Path to Nagios check_ping plugin."
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
ping_gateway() {
if [ "$address" = "" ] || [ "$ssl" = "" ] || [ "$username" = "" ] || [ "$password" = "" ] || [ "$ping" = "" ] || [ ! -x "$ping" ]; then
help
fi
if [ "$ssl" = 1 ]; then
command=`wget https://$address/st_device.html --post-data "login_name=$username&login_pass=$password" -t 1 --no-check-certificate -qO-`
elif [ "$ssl" = 0 ]; then
command=`wget http://$address/st_device.html --post-data "login_name=$username&login_pass=$password" -t 1 -qO-`
else
help
fi
if [ "$command" = "" ]; then
echo "Xfinity Gateway CRITICAL - Authentication failure."
exit 2
fi
address=`echo "$address" | sed 's/\./\\\./g'` # Possibly redundant/unnecessary for pattern matching with grep (due to vriable expansion).
addresses=`echo "$command" | grep '\s<td> .*</td>' | grep -o '[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}' | grep -v "\($address\|255\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\.[[:digit:]]\{1,3\}\)" | tr '\r\n' ' ' && echo`
IFS=' ' read -a address <<< $addresses
if [ "${address[1]}" != "" ]; then
echo "`$ping -H ${address[1]} -w 3000.0,80% -c 5000.0,100% -p 5 | sed 's/PING/Xfinity Gateway/g'`"
exit $?
else
echo "Xfinity Gateway CRITICAL - Authentication failure."
exit 2
fi
}
while test $# -ge 0; do
case "$1" in
-H | --hostname)
shift
address="`echo $1`"
;;
-s | --ssl)
shift
ssl="`echo $1`"
;;
-u | --username)
shift
username="`echo $1`"
;;
-p | --password)
shift
password="`echo $1`"
;;
-P | --ping)
shift
ping="`echo $1`"
ping_gateway
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
ebr2310_loginebr2310_login
"this event handler logs into a d-link ebr-2310 router."
this script uses wget to log into a d-link ebr-2310 router. the ebr-2310, when power cycled, requires a login and access of the root index page before any other pages are accessible, which prevents proper function of the "check xfinity" plugins.
- ebr2310_login
-
#!/bin/sh
#
# ebr2310_login
#
# Nagios event handler to login to a D-Link EBR-2310 router.
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -H host -u username -p password -m state,type,attempts"
exit 3
}
help() {
echo "This event handler logs into a D-Link EBR-2310 router."
echo ""
echo "Usage: `basename $0` -H host -u username -p password -m state,type,attempts"
echo ""
echo "Options:"
echo " -H, --hostname"
echo " Host to login to."
echo " -u, --username"
echo " Web GUI username."
echo " -p, --password"
echo " Web GUI password."
echo " -m, --macros"
echo " Services: \$SERVICESTATE\$,\$SERVICESTATETYPE\$,\$SERVICEATTEMPT\$"
echo " Hosts: \$HOSTSTATE\$,\$HOSTSTATETYPE\$,\$HOSTATTEMPT\$"
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
do_login() {
if [ "$address" = "" ] || [ "$username" = "" ] || [ "$password" = "" ] || [ "$macros" = "" ]; then
help
fi
IFS=', ' read -a macro <<< $macros
if [ "${macro[0]}" = "CRITICAL" ] || [ "${macro[0]}" = "DOWN" ]; then
if [ "${macro[1]}" = "HARD" ]; then
wget --post-data "login_name=$username&login_pass=$password" http://$address/login.cgi -qO- > /dev/null
wget --post-data "login_name=$username&login_pass=$password" http://$address/index.htm -qO- > /dev/null
elif [ "${macro[1]}" = "SOFT" ]; then
if [ "${macro[2]}" -gt "1" ]; then
wget --post-data "login_name=$username&login_pass=$password" http://$address/login.cgi -qO- > /dev/null
wget --post-data "login_name=$username&login_pass=$password" http://$address/index.htm -qO- > /dev/null
fi
fi
fi
exit 0
}
while test $# -ge 0; do
case "$1" in
-H | --hostname)
shift
address="`echo $1`"
;;
-u | --username)
shift
username="`echo $1`"
;;
-p | --password)
shift
password="`echo $1`"
;;
-m | --macros)
shift
macros="`echo $1`"
do_login
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
mrtg_startmrtg_start
"this event handler starts mrtg."
this script starts mrtg. it looks for the mrtg process id (pid) file, the pid file only exists while the mrtg daemon is running. if the pid isn't found, it starts the mrtg daemon.
i don't have a proper control script for mrtg... i used to know why this is but have since forgotten. what this means is that when my box running nagios power cycles, mrtg fails to run which affects check_mrtg2 and check_mrtgtraf from working with fresh logs. though, it's not that easy as i had to change ownership of various files and folders... and even then, logging behaves unusually. but, the daemon does run... so, yay?
- mrtg_start
-
#!/bin/sh
#
# mrtg_start
#
# Nagios event handler to start MRTG.
#
# (C)MMXVI Ickis <ickis@nerpter77.com>. All rights reserved.
# http://nerpter77.com/
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for non-commercial or commercial purposes and without fee is
# hereby granted. This software and its documentation is provided "as is".
# Sorry, I don't like to comment ^_^
usage() {
echo "Usage: `basename $0` -m state,type,attempts"
exit 3
}
help() {
echo "This event handler starts MRTG."
echo ""
echo "Usage: `basename $0` -m state,type,attempts"
echo ""
echo "Options:"
echo " -m, --macros"
echo " Services: \$SERVICESTATE\$,\$SERVICESTATETYPE\$,\$SERVICEATTEMPT\$"
echo " Hosts: \$HOSTSTATE\$,\$HOSTSTATETYPE\$,\$HOSTATTEMPT\$"
echo " -h, --help"
echo " Print help/usage information."
exit 3
}
do_start() {
if [ "$macros" = "" ]; then
help
fi
if [ ! -f /etc/mrtg/mrtg.pid ]; then
IFS=', ' read -a macro <<< $macros
if [ "${macro[0]}" = "WARNING" ]; then
if [ "${macro[1]}" = "HARD" ]; then
env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok --pid-file=/etc/mrtg/mrtg.pid --logging /var/log/mrtg.log
elif [ "${macro[1]}" = "SOFT" ]; then
if [ "${macro[2]}" -gt "1" ]; then
env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok --pid-file=/etc/mrtg/mrtg.pid --logging /var/log/mrtg.log
fi
fi
fi
fi
exit 0
}
while test $# -ge 0; do
case "$1" in
-m | --macros)
shift
macros="`echo $1`"
do_start
;;
-h | --help)
help
;;
*)
usage
;;
esac
shift
done
|