Move from Bitbucket to GitHub
This commit is contained in:
commit
bb78e81d15
161
check_domain
Executable file
161
check_domain
Executable file
@ -0,0 +1,161 @@
|
||||
#!/bin/bash
|
||||
|
||||
################################################################################
|
||||
# #
|
||||
# This program is free software; you can redistribute it and/or modify #
|
||||
# it under the terms of the GNU General Public License as published by #
|
||||
# the Free Software Foundation; either version 2 of the License, or #
|
||||
# (at your option) any later version. #
|
||||
# #
|
||||
# This program is distributed in the hope that it will be useful, #
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||
# GNU General Public License for more details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU General Public License #
|
||||
# along with this program; if not, write to the Free Software #
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
# #
|
||||
################################################################################
|
||||
|
||||
# This is a Nagios plugin to check the expiration date of a domain name.
|
||||
# It uses the "whois" command, which usually comes as a "whois" package.
|
||||
# Debian/Ubuntu: apt-get install whois
|
||||
#
|
||||
# Original version had this copyright notice in it:
|
||||
# Copyright (c) 2005 Tomàs Núñez Lirola <tnunez@criptos.com>,
|
||||
# 2009-2012 Elan Ruusamäe <glen@delfi.ee>, under GPL License
|
||||
#
|
||||
# Ryan found it hosted at:
|
||||
# http://git.pld-linux.org/gitweb.cgi/?p=packages/nagios-plugin-check_domain.git
|
||||
#
|
||||
# This is a modified version, hosted at https://bitbucket.org/elyrith/check_domain
|
||||
# Currently supports .com, .ca, .tv, .ee, .ru
|
||||
# Support for .ca and .se by Ryan Loudfoot (ryan@loudfoot.ca)
|
||||
# Support for Performance Data by Ryan Loudfoot
|
||||
|
||||
PROGRAM=${0##*/}
|
||||
PROGPATH=${0%/*}
|
||||
|
||||
# Ryan's note: utils.sh is installed with nagios-plugins in with the plugins
|
||||
. $PROGPATH/utils.sh
|
||||
|
||||
# Default values (days):
|
||||
critical=7
|
||||
warning=30
|
||||
|
||||
# Parse arguments
|
||||
args=$(getopt -o hd:w:c:P: --long help,domain:,warning:,critical:,path: -u -n $PROGRAM -- "$@")
|
||||
if [ $? != 0 ]; then
|
||||
echo >&2 "$PROGRAM: Could not parse arguments"
|
||||
echo "Usage: $PROGRAM -h | -d <domain> [-c <critical>] [-w <warning>]"
|
||||
exit 1
|
||||
fi
|
||||
set -- $args
|
||||
|
||||
die() {
|
||||
local rc=$1
|
||||
local msg=$2
|
||||
echo $msg
|
||||
exit $rc
|
||||
}
|
||||
|
||||
fullusage() {
|
||||
cat <<EOF
|
||||
check_domain - v1.2.1
|
||||
|
||||
This plugin checks the expiration date of a domain name.
|
||||
|
||||
Usage: $PROGRAM -h | -d <domain> [-c <critical>] [-w <warning>]
|
||||
NOTE: -d must be specified
|
||||
|
||||
Options:
|
||||
-h
|
||||
Print detailed help
|
||||
-d
|
||||
Domain name to check
|
||||
-w
|
||||
Response time to result in warning status (days)
|
||||
-c
|
||||
Response time to result in critical status (days)
|
||||
|
||||
This plugin will use whois service to get the expiration date for the domain name.
|
||||
Example:
|
||||
$PROGRAM -d domain.tld -w 30 -c 10
|
||||
|
||||
Currently supports .com, .ca, .tv, .ee, .ru
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
while :; do
|
||||
case "$1" in
|
||||
-c|--critical) critical=$2; shift 2;;
|
||||
-w|--warning) warning=$2; shift 2;;
|
||||
-d|--domain) domain=$2; shift 2;;
|
||||
-P|--path) whoispath=$2; shift 2;;
|
||||
-h|--help) fullusage; exit;;
|
||||
--) shift; break;;
|
||||
*) die $STATE_UNKNOWN "Internal error!";;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z $domain ]; then
|
||||
die $STATE_UNKNOWN "UNKNOWN - There is no domain name to check"
|
||||
fi
|
||||
|
||||
# Looking for whois binary
|
||||
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."
|
||||
whois=whois
|
||||
else
|
||||
[ -x "$whoispath/whois" ] || die $STATE_UNKNOWN "UNKNOWN - Unable to find whois binary, you specified an incorrect path"
|
||||
whois="$whoispath/whois"
|
||||
fi
|
||||
|
||||
out=$($whois $domain)
|
||||
|
||||
# Calculate days until expiration
|
||||
case "$domain" in
|
||||
*.com)
|
||||
expiration=$(echo "$out" | awk -F: '/Expiration Date:/{print substr($0, length($1) + 2)}')
|
||||
;;
|
||||
*.ru)
|
||||
expiration=$(echo "$out" | awk '/paid-till:/{split($2, a, "."); printf("%s-%s-%s\n", a[1], a[2], a[3])}')
|
||||
;;
|
||||
*.ee)
|
||||
expiration=$(echo "$out" | awk '/expire:/{split($2, a, "."); printf("%s-%s-%s\n", a[3], a[2], a[1])}')
|
||||
;;
|
||||
*.tv)
|
||||
expiration=$(echo "$out" | awk -F: '/Expiration Date:/{print substr($0, length($1) + 3, 10)}')
|
||||
;;
|
||||
*.ca)
|
||||
expiration=$(echo "$out" | awk '/Expiry date:/{split($3, a, "/"); printf("%s/%s/%s\n", a[2], a[3], a[1])}')
|
||||
;;
|
||||
*.se)
|
||||
expiration=$(echo "$out" | awk '/expires:/{split($2, a, "-"); printf("%s-%s-%s\n", a[1], a[2], a[3])}')
|
||||
;;
|
||||
*)
|
||||
expiration=$(echo "$out" | awk -F: '/Expiration Date:/{print substr($0, length($1) + 2)}')
|
||||
;;
|
||||
esac
|
||||
|
||||
# For debugging only:
|
||||
# echo $expiration
|
||||
|
||||
[ -z "$expiration" ] && die $STATE_UNKNOWN "UNKNOWN - Domain doesn't exist or no WHOIS server available."
|
||||
|
||||
expseconds=$(date +%s --date="$expiration")
|
||||
expdate=$(date +'%Y-%m-%d' --date="$expiration")
|
||||
nowseconds=$(date +%s)
|
||||
diffseconds=$((expseconds-nowseconds))
|
||||
expdays=$((diffseconds/86400))
|
||||
|
||||
# Trigger alarms if applicable
|
||||
#[ $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 $warning ] && die $STATE_WARNING "WARNING - Domain will expire in $expdays days ($expdate). | Warning: $warning, Critical: $critical"
|
||||
|
||||
# No alarms? Ok, everything is right.
|
||||
echo "OK - Domain will expire in $expdays days ($expdate). | Warning: $warning, Critical: $critical"
|
||||
exit $STATE_OK
|
Loading…
x
Reference in New Issue
Block a user