Skip to content

Commit

Permalink
[whois] Allow to specificy whois server per domain
Browse files Browse the repository at this point in the history
Also, clean up some old code that pre-dates multi-domain handling

Signed-off-by: Olivier Mehani <shtrom@ssji.net>
  • Loading branch information
shtrom authored and sumpfralle committed Dec 31, 2021
1 parent ca8ce74 commit 02451d8
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions plugins/network/whois
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ only query the WHOIS database C<cache_expiry_mins> 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 <default: 7 days>
env.critical_days <default: 3 days>
Expand All @@ -41,7 +42,7 @@ Then create a symlink to enable this plugin:
Olivier Mehani
Copyright (C) 2020 Olivier Mehani <shtrom+munin@ssji.net>
Copyright (C) 2020,2021 Olivier Mehani <shtrom+munin@ssji.net>
=head1 LICENSE
Expand Down Expand Up @@ -74,6 +75,7 @@ graph_config() {
graph_title Domain registration expiry
graph_category network
graph_vlabel days
graph_args --units-exponent 0
EOF
}

Expand All @@ -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
Expand All @@ -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}")"
Expand All @@ -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
}
Expand Down

0 comments on commit 02451d8

Please sign in to comment.