One pass through spellcheck.net. Hiccup on line: set --
This commit is contained in:
parent
0999905ff0
commit
8358bd7f09
40
check_domain
40
check_domain
@ -23,8 +23,8 @@
|
|||||||
# https://github.com/Elyrith/check_domain #
|
# https://github.com/Elyrith/check_domain #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
VERSION="Version 0.93"
|
# VERSION: Version 0.94
|
||||||
AUTHOR="See README. This version updated by Ryan Loudfoot (elyrith@gmail.com)"
|
# AUTHOR: See README. This version updated by Ryan Loudfoot (elyrith@gmail.com)
|
||||||
|
|
||||||
PROGRAM=${0##*/}
|
PROGRAM=${0##*/}
|
||||||
PROGPATH=${0%/*}
|
PROGPATH=${0%/*}
|
||||||
@ -33,24 +33,24 @@ PROGPATH=${0%/*}
|
|||||||
# Check if utils.sh exists. This lets you use check_domain in a testing environment
|
# Check if utils.sh exists. This lets you use check_domain in a testing environment
|
||||||
# or outside of Nagios.
|
# or outside of Nagios.
|
||||||
if [ -a utils.sh ]; then
|
if [ -a utils.sh ]; then
|
||||||
. $PROGPATH/utils.sh
|
. "$PROGPATH/utils.sh"
|
||||||
else
|
else
|
||||||
STATE_OK=0
|
STATE_OK=0
|
||||||
STATE_WARNING=1
|
STATE_WARNING=1
|
||||||
STATE_CRITICAL=2
|
STATE_CRITICAL=2
|
||||||
STATE_UNKNOWN=3
|
STATE_UNKNOWN=3
|
||||||
STATE_DEPENDENT=4
|
# STATE_DEPENDENT=4 (Commented because it's unused.)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Default values (days):
|
# Default values (days):
|
||||||
critical=7
|
critical=7
|
||||||
warning=30
|
warning=30
|
||||||
|
|
||||||
# Array for converting 3-letter month into number
|
# Array for converting 3-letter month into number (currently unused)
|
||||||
MONTH=("jan" "feb" "mar" "apr" "may" "jun" "jul" "aug" "sep" "oct" "nov" "dec")
|
#MONTH=("jan" "feb" "mar" "apr" "may" "jun" "jul" "aug" "sep" "oct" "nov" "dec")
|
||||||
|
|
||||||
# Parse arguments
|
# Parse arguments
|
||||||
args=$(getopt -o hd:w:c:P: --long help,domain:,warning:,critical:,path: -u -n $PROGRAM -- "$@")
|
args=$(getopt -o hd:w:c:P: --long help,domain:,warning:,critical:,path: -u -n "$PROGRAM" -- "$@")
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo >&2 "$PROGRAM: Could not parse arguments"
|
echo >&2 "$PROGRAM: Could not parse arguments"
|
||||||
echo "Usage: $PROGRAM -h | -d <domain> [-c <critical>] [-w <warning>]"
|
echo "Usage: $PROGRAM -h | -d <domain> [-c <critical>] [-w <warning>]"
|
||||||
@ -61,8 +61,8 @@ set -- $args
|
|||||||
die() {
|
die() {
|
||||||
local rc=$1
|
local rc=$1
|
||||||
local msg=$2
|
local msg=$2
|
||||||
echo $msg
|
echo "$msg"
|
||||||
exit $rc
|
exit "$rc"
|
||||||
}
|
}
|
||||||
|
|
||||||
fullusage() {
|
fullusage() {
|
||||||
@ -105,12 +105,12 @@ while :; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -z $domain ]; then
|
if [ -z "$domain" ]; then
|
||||||
die $STATE_UNKNOWN "UNKNOWN - There is no domain name to check"
|
die $STATE_UNKNOWN "UNKNOWN - There is no domain name to check"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Looking for whois binary
|
# Looking for whois binary
|
||||||
if [ -z $whoispath ]; then
|
if [ -z "$whoispath" ]; then
|
||||||
type whois > /dev/null 2>&1 || die $STATE_UNKNOWN "UNKNOWN - Unable to find whois binary in your path. Is it installed? Please specify path."
|
type whois > /dev/null 2>&1 || die $STATE_UNKNOWN "UNKNOWN - Unable to find whois binary in your path. Is it installed? Please specify path."
|
||||||
whois=whois
|
whois=whois
|
||||||
else
|
else
|
||||||
@ -121,10 +121,10 @@ fi
|
|||||||
# Use GoDaddy if domain is a .ca
|
# Use GoDaddy if domain is a .ca
|
||||||
case "$domain" in
|
case "$domain" in
|
||||||
*.ca)
|
*.ca)
|
||||||
out=$($whois -h whois.godaddy.com $domain)
|
out=$("$whois" -h whois.godaddy.com "$domain")
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
out=$($whois $domain)
|
out=$("$whois" "$domain")
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@ -152,12 +152,12 @@ case "$domain" in
|
|||||||
*.se)
|
*.se)
|
||||||
expiration=$(echo "$out" | awk '/expires:/{split($2, a, "-"); printf("%s-%s-%s\n", a[1], a[2], a[3])}')
|
expiration=$(echo "$out" | awk '/expires:/{split($2, a, "-"); printf("%s-%s-%s\n", a[1], a[2], a[3])}')
|
||||||
;;
|
;;
|
||||||
*.nu)
|
#*.nu)
|
||||||
# This doesn't work, yet. Need to convert 3-letter month into number. -Ryan, Aug 21, 2013
|
# This doesn't work, yet. Need to convert 3-letter month into number. -Ryan, Aug 21, 2013
|
||||||
expmonth=$(echo "$out" | awk -F '/Record expires on/{print substr($4, length($1) + 2)}'}
|
# expmonth=$(echo "$out" | awk -F '/Record expires on/{print substr($4, length($1) + 2)}'}
|
||||||
echo $expmonth
|
# echo $expmonth
|
||||||
expiration=$(echo "$out" | awk '/Record expires on/{split($4, a, "-"); printf("%s-%s-%s\n", a[2], a[3], a[1]);}')
|
# expiration=$(echo "$out" | awk '/Record expires on/{split($4, a, "-"); printf("%s-%s-%s\n", a[2], a[3], a[1]);}')
|
||||||
;;
|
# ;;
|
||||||
*)
|
*)
|
||||||
expiration=$(echo "$out" | awk -F: '/Expiration Date:/{print substr($0, length($1) + 2)}')
|
expiration=$(echo "$out" | awk -F: '/Expiration Date:/{print substr($0, length($1) + 2)}')
|
||||||
;;
|
;;
|
||||||
@ -176,8 +176,8 @@ expdays=$((diffseconds/86400))
|
|||||||
|
|
||||||
# Trigger alarms if applicable
|
# Trigger alarms if applicable
|
||||||
[ $expdays -lt 0 ] && die $STATE_CRITICAL "CRITICAL - Domain expired on $expiration. | Warning: $warning, Critical: $critical"
|
[ $expdays -lt 0 ] && die $STATE_CRITICAL "CRITICAL - Domain expired on $expiration. | Warning: $warning, Critical: $critical"
|
||||||
[ $expdays -lt $critical ] && die $STATE_CRITICAL "CRITICAL - Domain will expire in $expdays days ($expdate). | Warning: $warning, Critical: $critical"
|
[ $expdays -lt "$critical" ] && die $STATE_CRITICAL "CRITICAL - Domain will expire in $expdays days ($expdate). | Warning: $warning, Critical: $critical"
|
||||||
[ $expdays -lt $warning ] && die $STATE_WARNING "WARNING - Domain will expire in $expdays days ($expdate). | Warning: $warning, Critical: $critical"
|
[ $expdays -lt "$warning" ] && die $STATE_WARNING "WARNING - Domain will expire in $expdays days ($expdate). | Warning: $warning, Critical: $critical"
|
||||||
|
|
||||||
# No alarms? Ok, everything is right.
|
# No alarms? Ok, everything is right.
|
||||||
echo "OK - Domain will expire in $expdays days ($expdate). | Warning: $warning, Critical: $critical"
|
echo "OK - Domain will expire in $expdays days ($expdate). | Warning: $warning, Critical: $critical"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user