From 02451d8f6eee76a3270dba46cc5096cf6a716aa2 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Wed, 29 Dec 2021 15:46:00 +1100 Subject: [PATCH] [whois] Allow to specificy whois server per domain Also, clean up some old code that pre-dates multi-domain handling Signed-off-by: Olivier Mehani --- plugins/network/whois | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/plugins/network/whois b/plugins/network/whois index 133d516f..7bb336ec 100755 --- a/plugins/network/whois +++ b/plugins/network/whois @@ -13,11 +13,12 @@ only query the WHOIS database C minutes. =head1 CONFIGURATION -First, create a section in your munin-node configuration files. The domain envvar -is mandatory, others are optional. +First, create a section in your munin-node configuration files. The domain +envvar is mandatory, others are optional. Optionally, a specific WHOIS server +to query for a given domain can be specified with the @WHOIS_SERVER suffix [whois] - env.domains example.com example.org + env.domains example.com example.org@whois.example.net env.extract_re s/PATTERN/REPL/ env.warning_days env.critical_days @@ -41,7 +42,7 @@ Then create a symlink to enable this plugin: Olivier Mehani -Copyright (C) 2020 Olivier Mehani +Copyright (C) 2020,2021 Olivier Mehani =head1 LICENSE @@ -74,6 +75,7 @@ graph_config() { graph_title Domain registration expiry graph_category network graph_vlabel days +graph_args --units-exponent 0 EOF } @@ -84,6 +86,8 @@ config() { local FIELDNAME for NAME in $DOMAINS do + NAME="$(echo "${NAME}" | cut -d @ -f 1)" + FIELDNAME="$(clean_fieldname "${NAME}")" cat << EOF @@ -98,17 +102,24 @@ EOF # Args: domain name fetch() { local NAME + local SERVER local FIELDNAME local CACHEFILE for NAME in $DOMAINS do + SERVER='' + if echo "${NAME}" | grep -q '@'; then + SERVER="$(echo "${NAME}" | cut -d @ -f 2)" + NAME="$(echo "${NAME}" | cut -d @ -f 1)" + fi + 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;T;q")" # T;q exits after printing the first match + EXPIRY="$(whois "${NAME}" "${SERVER:+-h${SERVER}}" 2>/dev/null | sed -n "${EXTRACT_RE}p;T;q")" # T;q exits after printing the first match DELTA_TS=U if [ -n "${EXPIRY}" ]; then EXPIRY_TS="$(date +%s -d "${EXPIRY}")" @@ -126,17 +137,14 @@ fetch() { main() { local MODE="${1:-}" - local NAME - - NAME="$(echo "${0}" | sed 's/.*_//')" case "${MODE}" in 'config') - graph_config "${NAME}" - config "${NAME}" + graph_config + config ;; *) - fetch "${NAME}" + fetch ;; esac }