Skip to content

Commit 02451d8

Browse files
shtromsumpfralle
authored andcommitted
[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 <[email protected]>
1 parent ca8ce74 commit 02451d8

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

plugins/network/whois

+19-11
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ only query the WHOIS database C<cache_expiry_mins> minutes.
1313
1414
=head1 CONFIGURATION
1515
16-
First, create a section in your munin-node configuration files. The domain envvar
17-
is mandatory, others are optional.
16+
First, create a section in your munin-node configuration files. The domain
17+
envvar is mandatory, others are optional. Optionally, a specific WHOIS server
18+
to query for a given domain can be specified with the @WHOIS_SERVER suffix
1819
1920
[whois]
20-
env.domains example.com example.org
21+
env.domains example.com example.org@whois.example.net
2122
env.extract_re s/PATTERN/REPL/
2223
env.warning_days <default: 7 days>
2324
env.critical_days <default: 3 days>
@@ -41,7 +42,7 @@ Then create a symlink to enable this plugin:
4142
4243
Olivier Mehani
4344
44-
Copyright (C) 2020 Olivier Mehani <[email protected]>
45+
Copyright (C) 2020,2021 Olivier Mehani <[email protected]>
4546
4647
=head1 LICENSE
4748
@@ -74,6 +75,7 @@ graph_config() {
7475
graph_title Domain registration expiry
7576
graph_category network
7677
graph_vlabel days
78+
graph_args --units-exponent 0
7779
EOF
7880
}
7981

@@ -84,6 +86,8 @@ config() {
8486
local FIELDNAME
8587
for NAME in $DOMAINS
8688
do
89+
NAME="$(echo "${NAME}" | cut -d @ -f 1)"
90+
8791
FIELDNAME="$(clean_fieldname "${NAME}")"
8892

8993
cat << EOF
@@ -98,17 +102,24 @@ EOF
98102
# Args: domain name
99103
fetch() {
100104
local NAME
105+
local SERVER
101106
local FIELDNAME
102107
local CACHEFILE
103108

104109
for NAME in $DOMAINS
105110
do
111+
SERVER=''
112+
if echo "${NAME}" | grep -q '@'; then
113+
SERVER="$(echo "${NAME}" | cut -d @ -f 2)"
114+
NAME="$(echo "${NAME}" | cut -d @ -f 1)"
115+
fi
116+
106117
FIELDNAME="$(clean_fieldname "${NAME}")"
107118

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

110121
if [ -z "$(find "${CACHEFILE}" -mmin -"${CACHE_EXPIRY}" 2>/dev/null)" ]; then
111-
EXPIRY="$(whois "${NAME}" 2>/dev/null | sed -n "${EXTRACT_RE}p;T;q")" # T;q exits after printing the first match
122+
EXPIRY="$(whois "${NAME}" "${SERVER:+-h${SERVER}}" 2>/dev/null | sed -n "${EXTRACT_RE}p;T;q")" # T;q exits after printing the first match
112123
DELTA_TS=U
113124
if [ -n "${EXPIRY}" ]; then
114125
EXPIRY_TS="$(date +%s -d "${EXPIRY}")"
@@ -126,17 +137,14 @@ fetch() {
126137

127138
main() {
128139
local MODE="${1:-}"
129-
local NAME
130-
131-
NAME="$(echo "${0}" | sed 's/.*_//')"
132140

133141
case "${MODE}" in
134142
'config')
135-
graph_config "${NAME}"
136-
config "${NAME}"
143+
graph_config
144+
config
137145
;;
138146
*)
139-
fetch "${NAME}"
147+
fetch
140148
;;
141149
esac
142150
}

0 commit comments

Comments
 (0)