Skip to content

Commit

Permalink
[whois_] Plugin to monitor domain registration expiries
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
  • Loading branch information
shtrom committed Sep 3, 2020
1 parent 97555c0 commit 5031e4a
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions plugins/network/whois_
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/sh

set -eu

# shellcheck disable=SC1090
. "${MUNIN_LIBDIR}/plugins/plugin.sh"

if [ "${MUNIN_DEBUG:-0}" = 1 ]; then
set -x
fi

EXTRACT_RE='s/^.*[Ee]xpir.*: //'
CACHE_EXPIRY=60 # minutes

config() {
NAME=${1}
FIELDNAME="$(clean_fieldname "${NAME}")"
cat << EOF
graph_title "Domain registration expiry for ${NAME}"
graph_category network
graph_vlabel days
${FIELDNAME}.label expiry
${FIELDNAME}.cdef ${FIELDNAME},86400,/
${FIELDNAME}.warning 7:
${FIELDNAME}.critical 3:
EOF
}

fetch() {
NAME=${1}
FIELDNAME="$(clean_fieldname "${NAME}")"

CACHEFILE="${MUNIN_PLUGSTATE}/$(basename "${0}").${FIELDNAME}.cache"

if [ -z "$(find "${CACHEFILE}" -mmin -${CACHE_EXPIRY} 2>/dev/null)" ]; then
EXPIRY="$(whois "${NAME} 2>/dev/null" | sed -n "${EXTRACT_RE}p")"
EXPIRY_TS="$(date +%s -d "${EXPIRY}")"

NOW_TS="$(date +%s)"
DELTA_TS=$((EXPIRY_TS-NOW_TS))

echo "${FIELDNAME}.value ${DELTA_TS}" > "${CACHEFILE}"
fi

cat "${CACHEFILE}"
}

main() {
NAME="$(echo "${0}" | sed 's/.*_//')"
MODE="${1:-}"

case "${MODE}" in
'config')
config "${NAME}"
;;
*)
fetch "${NAME}"
;;
esac
}

main "$@"

# vim: ft=sh

0 comments on commit 5031e4a

Please sign in to comment.