├── check_domain.cfg ├── nagios-plugin-check_domain.spec ├── README.md └── check_domain.sh /check_domain.cfg: -------------------------------------------------------------------------------- 1 | # Usage: 2 | # check_domain!DOMAINNAME 3 | define command { 4 | command_name check_domain 5 | command_line @plugindir@/check_domain -w 30 -c 10 -d $ARG1$ 6 | } 7 | 8 | 9 | # Check DNS domain 10 | define service { 11 | use generic-service 12 | name check_domain 13 | service_description check_domain 14 | register 0 15 | 16 | ; check every 12h is sufficent, notify daily 17 | normal_check_interval 720 18 | notification_interval 1440 19 | 20 | check_command check_domain 21 | } 22 | -------------------------------------------------------------------------------- /nagios-plugin-check_domain.spec: -------------------------------------------------------------------------------- 1 | %define plugin check_domain 2 | Summary: Nagios plugin for checking a domain name expiration date 3 | Name: nagios-plugin-%{plugin} 4 | Version: 1.2.6 5 | Release: 1 6 | License: GPL 7 | Group: Networking 8 | Source0: %{plugin}.sh 9 | Source1: %{plugin}.cfg 10 | URL: http://www.tomas.cat/blog/en/checking-domain-name-expiration-date-checkdomain 11 | Requires: whois 12 | BuildArch: noarch 13 | BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n) 14 | 15 | %define _sysconfdir /etc/nagios/plugins 16 | %define plugindir %{_prefix}/lib/nagios/plugins 17 | 18 | %description 19 | Nagios pluging for checking a domain name expiration date. 20 | 21 | %prep 22 | %setup -qcT 23 | install -p %{SOURCE0} %{plugin} 24 | 25 | %install 26 | rm -rf $RPM_BUILD_ROOT 27 | install -d $RPM_BUILD_ROOT{%{_sysconfdir},%{plugindir}} 28 | install -p %{plugin} $RPM_BUILD_ROOT%{plugindir}/%{plugin} 29 | sed -e 's,@plugindir@,%{plugindir},' %{SOURCE1} > $RPM_BUILD_ROOT%{_sysconfdir}/%{plugin}.cfg 30 | 31 | %clean 32 | rm -rf $RPM_BUILD_ROOT 33 | 34 | %files 35 | %defattr(644,root,root,755) 36 | %config(noreplace) %verify(not md5 mtime size) %{_sysconfdir}/%{plugin}.cfg 37 | %attr(755,root,root) %{plugindir}/%{plugin} 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Nagios/Icinga Plugin: check\_domain 2 | =================================== 3 | 4 | [![Build Status](https://travis-ci.org/glensc/monitoring-plugin-check_domain.svg?branch=master)](https://travis-ci.org/glensc/monitoring-plugin-check_domain) 5 | 6 | Nagios/Icinga plugin for checking a domain name expiration date 7 | 8 | ### Usage 9 | 10 | ``` 11 | $ ./check_domain.sh -d github.io 12 | OK - Domain github.io will expire in 43 days (2014-03-08). 13 | ``` 14 | 15 | ### Caching 16 | 17 | This tool excels at monitoring a small number of domains, but because of whois rate limiting, it becomes infeasible to use for a large number of domains. For this to work around, there's support for caching positive lookups for defined time period. A failed lookup will cause the domain cache file to be removed so it should be as responsive as a normal check when the critical/warning threshold is reached. 18 | 19 | An example to configure to cache positive lookups for one day: 20 | * `--cache-dir /var/cache/check_domain --cache-age 1` 21 | 22 | The cache dir must exist and must be writable for user running the checks. 23 | 24 | ## Pull requests 25 | 26 | 1. Fork it. 27 | 2. Create your feature branch (`git checkout -b fixing-blah`). 28 | 3. Commit your changes (`git commit -am 'Fixed blah'`). 29 | 4. Run `./test.sh domain.tld` to test the domain 30 | 5. Add the example domain name to [domains](domains) for CI to test them, commit it 31 | 6. Push to the branch (`git push origin fixing-blah`). 32 | 7. Create a new pull request. 33 | 34 | Do not update changelog or attempt to change version. 35 | 36 | 37 | ## Installing whois 38 | 39 | This plugin uses the "whois" command. It is usually installed by default, but if not, you can get it via your favourite package manager. 40 | 41 | Debian/Ubuntu: 42 | ``` 43 | # apt-get install whois 44 | ``` 45 | 46 | RHEL/CentOS: 47 | ``` 48 | # yum install whois 49 | ``` 50 | 51 | 52 | ## Directory Listings 53 | 54 | * [Nagios Exchange](http://exchange.nagios.org/directory/Plugins/Internet-Domains-and-WHOIS/check_domain/details) 55 | -------------------------------------------------------------------------------- /check_domain.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Nagios plugin for checking a domain name expiration date 3 | # 4 | # Copyright (c) 2005 Tomàs Núñez Lirola (Original Author), 5 | # Copyright (c) 2009-2016 Elan Ruusamäe (Current Maintainer) 6 | # 7 | # Licensed under GPL v2 License 8 | # URL: https://github.com/glensc/nagios-plugin-check_domain 9 | 10 | # License: GPL v2 11 | # Homepage: https://github.com/glensc/nagios-plugin-check_domain 12 | # Changes: https://github.com/glensc/nagios-plugin-check_domain/commits/master 13 | # Nagios Exchange Entry: http://exchange.nagios.org/directory/Plugins/Internet-Domains-and-WHOIS/check_domain/details 14 | # Reporting Bugs: https://github.com/glensc/nagios-plugin-check_domain/issues/new 15 | 16 | # fail on first error, do not continue 17 | set -e 18 | 19 | PROGRAM=${0##*/} 20 | VERSION=1.7.1 21 | 22 | STATE_OK=0 23 | STATE_WARNING=1 24 | STATE_CRITICAL=2 25 | STATE_UNKNOWN=3 26 | 27 | die() { 28 | # shellcheck disable=SC2039 29 | local rc="$1" 30 | # shellcheck disable=SC2039 31 | local msg="$2" 32 | echo "$msg" 33 | 34 | if [ "$rc" = 0 ]; then 35 | # remove outfile if not caching 36 | [ -z "$cache_dir" ] && rm -f "$outfile" 37 | else 38 | # always remove output even if caching to force re-check in case on errors 39 | rm -f "$outfile" 40 | fi 41 | 42 | exit "$rc" 43 | } 44 | 45 | # return true if argument is numeric 46 | # http://stackoverflow.com/a/3951175/2314626 47 | is_numeric() { 48 | case "$1" in 49 | ''|*[!0-9]*) 50 | return 1 51 | ;; 52 | esac 53 | return 0 54 | } 55 | 56 | version() { 57 | echo "check_domain - v$VERSION" 58 | } 59 | 60 | usage() { 61 | echo "Usage: $PROGRAM -h | -d [-c ] [-w ] [-P ] [-s ]" 62 | } 63 | 64 | fullusage() { 65 | cat < (Original Author), 68 | Copyright (c) 2009-2017 Elan Ruusamäe (Current Maintainer) 69 | Under GPL v2 License 70 | 71 | This plugin checks the expiration date of a domain name. 72 | 73 | Usage: $PROGRAM -h | -d [-c ] [-w ] [-P ] [-s ] 74 | NOTE: -d must be specified 75 | 76 | Options: 77 | -h, --help 78 | Print detailed help 79 | -V, --version 80 | Print version information 81 | -d, --domain 82 | Domain name to check 83 | -w, --warning 84 | Response time to result in warning status (days) 85 | -c, --critical 86 | Response time to result in critical status (days) 87 | -P, --path 88 | Path to whois binary 89 | -s, --server 90 | Specific Whois server for domain name check 91 | -a, --cache-age 92 | How many days should each WHOIS lookup be cached for (default 0). Requires cache dir. 93 | -C, --cache-dir 94 | Directory where to cache lookups 95 | 96 | This plugin will use whois service to get the expiration date for the domain name. 97 | Example: 98 | $PROGRAM -d domain.tld -w 30 -c 10 99 | 100 | EOF 101 | } 102 | 103 | set_defaults() { 104 | # Default values (days): 105 | critical=7 106 | warning=30 107 | 108 | cache_age=0 109 | cache_dir= 110 | 111 | awk=${AWK:-awk} 112 | } 113 | 114 | # Parse command line arguments 115 | parse_arguments() { 116 | # shellcheck disable=SC2039 117 | local args 118 | args=$(getopt -o hVd:w:c:P:s:a:C: --long help,version,domain:,warning:,critical:,path:,server:,cache-age:,cache-dir: -u -n "$PROGRAM" -- "$@") 119 | eval set -- "$args" 120 | 121 | while :; do 122 | case "$1" in 123 | -c|--critical) 124 | shift 125 | critical=$1 126 | ;; 127 | -w|--warning) 128 | shift 129 | warning=$1 130 | ;; 131 | -d|--domain) 132 | shift 133 | domain=$1 134 | ;; 135 | -P|--path) 136 | shift 137 | whoispath=$1 138 | ;; 139 | -s|--server) 140 | shift 141 | server=$1 142 | ;; 143 | -V|--version) 144 | version 145 | exit 146 | ;; 147 | -a|--cache-age) 148 | shift 149 | cache_age=$1 150 | ;; 151 | -C|--cache-dir) 152 | shift 153 | cache_dir=$1 154 | ;; 155 | -h|--help) 156 | fullusage 157 | exit 158 | ;; 159 | --) 160 | shift 161 | break 162 | ;; 163 | *) 164 | die "$STATE_UNKNOWN" "Internal error!" 165 | ;; 166 | esac 167 | shift 168 | done 169 | 170 | if [ -z "$domain" ]; then 171 | die "$STATE_UNKNOWN" "UNKNOWN - There is no domain name to check" 172 | fi 173 | 174 | # validate cache args 175 | if [ -n "$cache_dir" ] && [ ! -d "$cache_dir" ]; then 176 | die "$STATE_UNKNOWN" "Cache dir: '$cache_dir' does not exist" 177 | fi 178 | if [ -n "$cache_age" ] && ! is_numeric "$cache_age"; then 179 | die "$STATE_UNKNOWN" "Cache age is not numeric: '$cache_age'" 180 | fi 181 | if [ -n "$cache_dir" ] && [ "$cache_age" -le 0 ]; then 182 | die "$STATE_UNKNOWN" "Cache dir set, but age not" 183 | fi 184 | } 185 | 186 | # create temporary file. as secure as possible 187 | # tempfile name is returned to stdout 188 | temporary_file() { 189 | # shellcheck disable=SC2039 190 | # shellcheck disable=SC2169 191 | mktemp --tmpdir -t check_domainXXXXXX 2>/dev/null || echo "${TMPDIR:-/tmp}/check_domain.$RANDOM.$$" 192 | } 193 | 194 | # Looking for whois binary 195 | setup_whois() { 196 | if [ -n "$whoispath" ]; then 197 | if [ -x "$whoispath" ]; then 198 | whois=$whoispath 199 | elif [ -x "$whoispath/whois" ]; then 200 | whois=$whoispath/whois 201 | fi 202 | [ -n "$whois" ] || die "$STATE_UNKNOWN" "UNKNOWN - Unable to find whois binary, you specified an incorrect path" 203 | else 204 | # shellcheck disable=SC2039 205 | type whois > /dev/null 2>&1 || die "$STATE_UNKNOWN" "UNKNOWN - Unable to find whois binary in your path. Is it installed? Please specify path." 206 | whois=whois 207 | fi 208 | } 209 | 210 | # Run whois(1) 211 | run_whois() { 212 | # shellcheck disable=SC2039 213 | local error 214 | 215 | setup_whois 216 | 217 | $whois ${server:+-h $server} "$domain" > "$outfile" 2>&1 && error=$? || error=$? 218 | [ -s "$outfile" ] || die "$STATE_UNKNOWN" "UNKNOWN - Domain $domain doesn't exist or no WHOIS server available." 219 | 220 | if grep -q -e "No match for" -e "NOT FOUND" -e "NO DOMAIN" "$outfile"; then 221 | die "$STATE_UNKNOWN" "UNKNOWN - Domain $domain doesn't exist." 222 | fi 223 | 224 | # check for common errors 225 | if grep -q -e "Query rate limit exceeded. Reduced information." -e "WHOIS LIMIT EXCEEDED" "$outfile"; then 226 | die "$STATE_UNKNOWN" "UNKNOWN - Rate limited WHOIS response" 227 | fi 228 | if grep -q -e "fgets: Connection reset by peer" "$outfile"; then 229 | error=0 230 | fi 231 | 232 | [ $error -eq 0 ] || die "$STATE_UNKNOWN" "UNKNOWN - WHOIS exited with error $error." 233 | } 234 | 235 | # Calculate days until expiration from whois output 236 | get_expiration() { 237 | # shellcheck disable=SC2039 238 | local outfile=$1 239 | 240 | # shellcheck disable=SC2016 241 | $awk ' 242 | BEGIN { 243 | HH_MM_DD = "[0-9][0-9]:[0-9][0-9]:[0-9][0-9]" 244 | YYYY = "[0-9][0-9][0-9][0-9]" 245 | DD = "[0-9][0-9]" 246 | MON = "[A-Za-z][a-z][a-z]" 247 | DATE_DD_MM_YYYY_DOT = "[0-9][0-9]\\.[0-9][0-9]\\.[0-9][0-9][0-9][0-9]" 248 | DATE_DD_MON_YYYY = "[0-9][0-9]-[A-Za-z][a-z][a-z]-[0-9][0-9][0-9][0-9]" 249 | DATE_ISO_FULL = "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T" 250 | DATE_ISO_LIKE = "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] " 251 | DATE_YYYY_MM_DD_DASH = "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]" 252 | DATE_YYYY_MM_DD_DOT = "[0-9][0-9][0-9][0-9]\\.[0-9][0-9]\\.[0-9][0-9]" 253 | DATE_YYYY_MM_DD_SLASH = "[0-9][0-9][0-9][0-9]/[0-9][0-9]/[0-9][0-9]" 254 | DATE_DD_MM_YYYY_SLASH = "[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]" 255 | DATE_YYYY_MM_DD_NIL = "[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" 256 | # 2015-10-03 13:36:48 257 | DATE_YYYY_MM_DD_DASH_HH_MM_SS = DATE_YYYY_MM_DD_DASH " " HH_MM_DD 258 | # 15.05.2016 13:36:48 259 | DATE_DD_MM_YYYY_DOT_HH_MM_SS = DATE_DD_MM_YYYY_DOT " " HH_MM_DD 260 | 261 | # Wed Mar 02 23:59:59 GMT 2016 262 | DATE_DAY_MON_DD_HHMMSS_TZ_YYYY = "[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9][0-9] " HH_MM_DD " GMT " YYYY 263 | # 25-Apr-2018 16:00:50 264 | DATE_DD_MON_YYYY_HHMMSS = "[0-9][0-9]-" MON "-" YYYY " " HH_MM_DD 265 | # 02-May-2018 16:12:25 UTC 266 | DATE_DD_MON_YYYY_HHMMSS_TZ = "[0-9][0-9]-" MON "-" YYYY " " HH_MM_DD " UTC" 267 | # 2016.01.14 18:47:31 268 | DATE_YYYYMMDD_HHMMSS = DATE_YYYY_MM_DD_DOT " " HH_MM_DD 269 | # 21/05/2017 00:00:00 EEST 270 | DATE_DD_MM_YYYY_SLASH_HHMMSS_TZ = DATE_DD_MM_YYYY_SLASH " " HH_MM_DD " [A-Z]+" 271 | # 14 Jan 2016 22:40:29 UTC 272 | DATE_DD_MON_YYYY_HHMMSS_TZ_SPACE = "[0-9][0-9] " MON " " YYYY " " HH_MM_DD " UTC" 273 | # myname.pchome.com.tw date format: 2023-06-03 00:00:00 (UTC+8) 274 | DATE_YYYY_MM_DD_DASH_HH_MM_SS_TZ_SPACE_OFFSET = DATE_YYYY_MM_DD_DASH " " HH_MM_DD " ""\\(UTC\\+[0-9]+\\)" 275 | 276 | # 2007-02-28 11:48:53+02 277 | DATE_YYYY_MM_DD_DASH_HH_MM_SS_TZOFFSET = DATE_YYYY_MM_DD_DASH " " HH_MM_DD "\\+[0-9]+" 278 | split("january february march april may june july august september october november december", months, " "); 279 | for (i in months) { 280 | mon = months[i] 281 | Month[mon] = i; 282 | mon = substr(mon, 1, 3) 283 | Mon[mon] = i; 284 | } 285 | } 286 | 287 | # convert short month name to month number (Month Of Year) 288 | function mon2moy(month) { 289 | return Mon[tolower(month)] 290 | } 291 | 292 | # convert long month name to month number (Month Of Year) 293 | function month2moy(month) { 294 | return Month[tolower(month)] 295 | } 296 | 297 | # get date from DATE_ISO_FULL format from `s` using field separator `fs` from index `i` and exit 298 | function get_iso_date(s, fs, i, a, d) { 299 | if (split(s, a, fs)) { 300 | if (split(a[i], d, /T/)) { 301 | print d[1]; 302 | exit; 303 | } 304 | } 305 | } 306 | 307 | # Expiry date: 05-Dec-2014 308 | /Expir(y|ation) [Dd]ate:/ && $NF ~ DATE_DD_MON_YYYY {split($3, a, "-"); printf("%s-%s-%s\n", a[3], mon2moy(a[2]), a[1]); exit} 309 | 310 | # expires: 05-Dec-2014 311 | /expires:/ && $NF ~ DATE_DD_MON_YYYY {split($3, a, "-"); printf("%s-%s-%s\n", a[3], mon2moy(a[2]), a[1]); exit} 312 | 313 | # Expiry Date: 19/11/2015 314 | /Expiry Date:/ && $NF ~ DATE_DD_MM_YYYY_SLASH {split($3, a, "/"); printf("%s-%s-%s", a[3], a[2], a[1]); exit} 315 | 316 | # Expiration date: 16.11.2013 15:30:13 317 | /Expiration date:/ && $0 ~ DATE_DD_MM_YYYY_DOT_HH_MM_SS {split($(NF-1), a, "."); printf("%s-%s-%s", a[3], a[2], a[1]); exit} 318 | 319 | # Expire Date: 2015-10-22 320 | # expire-date: 2016-02-05 321 | /[Ee]xpire[- ][Dd]ate:/ && $NF ~ DATE_YYYY_MM_DD_DASH {print $NF; exit} 322 | 323 | # expires: 20170716 324 | /expires:/ && $NF ~ DATE_YYYY_MM_DD_NIL {printf("%s-%s-%s", substr($2,0,4), substr($2,5,2), substr($2,7,2)); exit} 325 | 326 | # expires: 2015-11-18 327 | /expires:[ ]+/ && $NF ~ DATE_YYYY_MM_DD_DASH {print $NF; exit} 328 | 329 | # renewal date: 2016.01.14 18:47:31 330 | /renewal date:/ && $0 ~ DATE_YYYYMMDD_HHMMSS {split($(NF-1), a, "."); printf("%s-%s-%s", a[1], a[2], a[3]); exit} 331 | 332 | # paid-till: 2013.11.01 333 | /paid-till:/ && $NF ~ DATE_YYYY_MM_DD_DOT {split($2, a, "."); printf("%s-%s-%s", a[1], a[2], a[3]); exit} 334 | 335 | # paid-till: 2016-01-19 336 | /paid-till:/ && $NF ~ DATE_YYYY_MM_DD_DASH {print $NF; exit} 337 | 338 | # Valid Until: 2016-01-19 339 | /Valid Until:/ && $NF ~ DATE_YYYY_MM_DD_DASH {print $NF; exit} 340 | 341 | # expire: 16.11.2013 342 | /expire:/ && $NF ~ DATE_DD_MM_YYYY_DOT {split($2, a, "."); printf("%s-%s-%s", a[3], a[2], a[1]); exit} 343 | 344 | # expire: 2016-01-19 345 | /expire:/ && $NF ~ DATE_YYYY_MM_DD_DASH {print $NF; exit} 346 | 347 | # Expiration Date: 2017-01-26T10:14:11Z 348 | # Registrar Registration Expiration Date: 2015-02-22T00:00:00Z 349 | # Registrar Registration Expiration Date: 2015-01-11T23:00:00-07:00Z 350 | $0 ~ "Expiration Date: " DATE_ISO_FULL { get_iso_date($0, ":", 2) } 351 | 352 | # domain_datebilleduntil: 2015-01-11T23:00:00-07:00Z 353 | $0 ~ "billed[ ]*until: " DATE_ISO_FULL { get_iso_date($0, ":", 2) } 354 | 355 | # Registrar Registration Expiration Date: 2018-09-21 00:00:00 -0400 356 | $0 ~ "Expiration Date: " DATE_ISO_LIKE { get_iso_date($0, ":", 2) } 357 | 358 | # Data de expiração / Expiration Date (dd/mm/yyyy): 18/01/2016 359 | $0 ~ "Expiration Date .dd/mm/yyyy" {split($NF, a, "/"); printf("%s-%s-%s", a[3], a[2], a[1]); exit} 360 | 361 | # Domain Expiration Date: Wed Mar 02 23:59:59 GMT 2016 362 | $0 ~ "Expiration Date: *" DATE_DAY_MON_DD_HHMMSS_TZ_YYYY { 363 | printf("%s-%s-%s", $9, mon2moy($5), $6); 364 | } 365 | 366 | # Expiration Date:02-May-2018 16:12:25 UTC 367 | $0 ~ "Expiration Date: *" DATE_DD_MON_YYYY_HHMMSS_TZ { 368 | sub(/^.*Expiration Date: */, "") 369 | split($1, a, "-"); 370 | printf("%s-%s-%s", a[3], mon2moy(a[2]), a[1]); 371 | } 372 | 373 | # .sg domains 374 | # Expiration Date: 25-Apr-2018 16:00:50 375 | # (uses tabs between colon and date, we match tabs or spaces regardless) 376 | $0 ~ "Expiration Date:[ \t]*" DATE_DD_MON_YYYY_HHMMSS { 377 | sub(/^.*Expiration Date:[ \t]*/, "") 378 | split($1, a, "-"); 379 | printf("%s-%s-%s", a[3], mon2moy(a[2]), a[1]); 380 | } 381 | 382 | # Expiry Date: 14 Jan 2016 22:40:29 UTC 383 | $0 ~ "Expiry Date: *" DATE_DD_MON_YYYY_HHMMSS_TZ_SPACE { 384 | printf("%s-%s-%s", $5, mon2moy($4), $3); 385 | } 386 | 387 | # myname.pchome.com.tw 388 | # Record expires on 2023-06-03 00:00:00 (UTC+8) 389 | $0 ~ "Record expires on " DATE_YYYY_MM_DD_DASH_HH_MM_SS_TZ_SPACE_OFFSET { 390 | split($0, a, " "); printf a[4]; 391 | exit; 392 | } 393 | 394 | # Registry Expiry Date: 2015-08-03T04:00:00Z 395 | # Registry Expiry Date: 2017-01-26T10:14:11Z 396 | $0 ~ "Expiry Date: " DATE_ISO_FULL {split($0, a, ":"); s = a[2]; if (split(s,d,/T/)) print d[1]; exit} 397 | 398 | # Expiry date: 2017/07/16 399 | /Expiry date:/ && $NF ~ DATE_YYYY_MM_DD_SLASH {split($3, a, "/"); printf("%s-%s-%s", a[1], a[2], a[3]); exit} 400 | 401 | # Expiry Date: 19/11/2015 00:59:58 402 | /Expiry Date:/ && $(NF-1) ~ DATE_DD_MM_YYYY_SLASH {split($3, a, "/"); printf("%s-%s-%s", a[3], a[2], a[1]); exit} 403 | 404 | # Expires: 2014-01-31 405 | # Expiry : 2014-03-08 406 | # Valid-date 2014-10-21 407 | /Valid-date|Expir(es|ation|y)/ && $NF ~ DATE_YYYY_MM_DD_DASH {print $NF; exit} 408 | 409 | # [Expires on] 2014/12/01 410 | /\[Expires on\]/ && $NF ~ DATE_YYYY_MM_DD_SLASH {split($3, a, "/"); printf("%s-%s-%s", a[1], a[2], a[3]); exit} 411 | 412 | # [State] Connected (2014/12/01) 413 | /\[State\]/ && $NF ~ DATE_YYYY_MM_DD_SLASH {gsub("[()]", "", $3); split($3, a, "/"); printf("%s-%s-%s", a[1], a[2], a[3]); exit} 414 | 415 | # expires at: 21/05/2017 00:00:00 EEST 416 | $0 ~ "expires at: *" DATE_DD_MM_YYYY_SLASH_HHMMSS_TZ {split($3, a, "/"); printf("%s-%s-%s", a[3], a[2], a[1]); exit} 417 | 418 | # Renewal Date: 2016-06-25 419 | $0 ~ "Renewal Date: *" DATE_YYYY_MM_DD { print($3); exit} 420 | 421 | # Expiry Date: 31-03-2016 422 | $0 ~ "Expiry Date: *" DATE_DD_MM_YYYY {split($3, a, "-"); printf("%s-%s-%s", a[3], a[2], a[1]); exit} 423 | 424 | # .il domains 425 | # validity: 05-11-2022 426 | # .il domains registered at the dawn of Internet never expire... 427 | # validity: N/A 428 | $0 ~ "validity: *" DATE_DD_MM_YYYY {if ($2 == "N/A") {print "2100-01-01"} else {split($2, a, "-"); printf("%s-%s-%s", a[3], a[2], a[1])}; exit} 429 | 430 | # Expired: 2015-10-03 13:36:48 431 | $0 ~ "Expired: *" DATE_YYYY_MM_DD_DASH_HH_MM_SS {split($2, a, "-"); printf("%s-%s-%s", a[1], a[2], a[3]); exit} 432 | 433 | # Expiration Time: 2015-10-03 13:36:48 434 | $0 ~ "Expiration Time: *" DATE_YYYY_MM_DD_DASH_HH_MM_SS {split($3, a, "-"); printf("%s-%s-%s", a[1], a[2], a[3]); exit} 435 | 436 | # .fi domains 437 | # expires............: 4.7.2017 13:36:48 438 | /^expires\.*: +[0-9][0-9]?\.[0-9][0-9]?\.[0-9][0-9][0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9]$/ { 439 | sub(/^expires\.*: +/, "") 440 | split($1, a, "."); 441 | printf("%s-%02d-%02d", a[3], a[2], a[1]); 442 | exit; 443 | } 444 | 445 | # .ua domain 446 | # expires: 2017-09-01 17:09:32+03 447 | $0 ~ "expires: *" DATE_YYYY_MM_DD_DASH_HH_MM_SS_TZOFFSET {split($2, a, "-"); printf("%s-%s-%s", a[1], a[2], a[3]); exit} 448 | # FIXME: XXX: weak patterns 449 | 450 | # renewal: 31-March-2016 451 | /renewal:/{split($2, a, "-"); printf("%s-%s-%s\n", a[3], month2moy(a[2]), a[1]); exit} 452 | 453 | # expires: March 5 2014 454 | /expires:/{printf("%s-%s-%s\n", $4, month2moy($2), $3); exit} 455 | 456 | # Renewal date: 457 | # Monday 21st Sep 2015 458 | /Renewal date:/{renewal = 1; next} 459 | {if (renewal) { sub(/[^0-9]+/, "", $2); printf("%s-%s-%s", $4, mon2moy($3), $2); exit}} 460 | 461 | # paid-till: 2017-12-10T12:42:36Z 462 | /paid-till:/ && $NF ~ DATE_ISO_FULL {split($0, a, ":"); s = a[2]; if (split(s,d,/T/)) print d[1]; exit} 463 | ' "$outfile" 464 | } 465 | 466 | set_defaults 467 | parse_arguments "$@" 468 | 469 | if [ -n "$cache_dir" ]; then 470 | # we might consider whois server name in cache file 471 | outfile=$cache_dir/$domain 472 | 473 | # clean up cache file if it's outdated 474 | test -f "$outfile" && find "$outfile" -mtime "+$cache_age" -delete 475 | 476 | # run whois if cache is empty or missing 477 | test -s "$outfile" || run_whois 478 | else 479 | outfile=$(temporary_file) 480 | run_whois 481 | fi 482 | expiration=$(get_expiration "$outfile") 483 | 484 | [ -z "$expiration" ] && die "$STATE_UNKNOWN" "UNKNOWN - Unable to figure out expiration date for $domain Domain." 485 | 486 | expseconds=$(date +%s --date="$expiration") 487 | expdate=$(date +'%Y-%m-%d' --date="$expiration") 488 | nowseconds=$(date +%s) 489 | diffseconds=$((expseconds-nowseconds)) 490 | expdays=$((diffseconds/86400)) 491 | 492 | # Trigger alarms (if applicable) if the domain is not expired. 493 | if [ $expdays -ge 0 ]; then 494 | [ $expdays -lt "$critical" ] && die "$STATE_CRITICAL" "CRITICAL - Domain $domain will expire in $expdays days ($expdate). | domain_days_until_expiry=$expdays;$warning;$critical" 495 | [ $expdays -lt "$warning" ] && die "$STATE_WARNING" "WARNING - Domain $domain will expire in $expdays days ($expdate). | domain_days_until_expiry=$expdays;$warning;$critical" 496 | 497 | # No alarms? Ok, everything is right. 498 | die "$STATE_OK" "OK - Domain $domain will expire in $expdays days ($expdate). | domain_days_until_expiry=$expdays;$warning;$critical" 499 | fi 500 | 501 | # Trigger alarms if applicable in the case that $warning and/or $critical are negative 502 | [ $expdays -lt "$critical" ] && die "$STATE_CRITICAL" "CRITICAL - Domain $domain expired ${expdays#-} days ago ($expdate). | domain_days_until_expiry=$expdays;$warning;$critical" 503 | [ $expdays -lt "$warning" ] && die "$STATE_WARNING" "WARNING - Domain $domain expired ${expdays#-} days ago ($expdate). | domain_days_until_expiry=$expdays;$warning;$critical" 504 | # No alarms? Ok, everything is right. 505 | die "$STATE_OK" "OK - Domain $domain expired ${expdays#-} days ago ($expdate). | domain_days_until_expiry=$expdays;$warning;$critical" 506 | --------------------------------------------------------------------------------