mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 22:25:23 +00:00
Add support for multi-domain check
This commit is contained in:
parent
f2261ed9d4
commit
63505c5060
1 changed files with 40 additions and 33 deletions
|
@ -6,28 +6,25 @@
|
||||||
|
|
||||||
=head1 NAME
|
=head1 NAME
|
||||||
|
|
||||||
whois_ - Plugin to monitor expiry dates of domain in the WHOIS database
|
whois - Plugin to monitor expiry dates of domain in the WHOIS database
|
||||||
|
|
||||||
Though the plugin will be called every 5 minutes, it will keep a cache, and
|
Though the plugin will be called every 5 minutes, it will keep a cache, and
|
||||||
only query the WHOIS database every hour.
|
only query the WHOIS database C<cache_expiry_mins> minutes.
|
||||||
|
|
||||||
=head1 CONFIGURATION
|
=head1 CONFIGURATION
|
||||||
|
|
||||||
None is needed, just
|
First, create a section in your munin-node configuration files. The domain envvar
|
||||||
|
is mandatory, others are optional.
|
||||||
|
|
||||||
ln -s /path/to/whois_ whois_domain.tld
|
[whois]
|
||||||
|
env.domains example.com example.org
|
||||||
in Munin's installed plugins directory will suffice to start monitoring
|
|
||||||
C<domain.tld>.
|
|
||||||
|
|
||||||
However, a few parameters, all optional, can be set if needed
|
|
||||||
|
|
||||||
[whois_domain.tld]
|
|
||||||
env.extract_re s/PATTERN/REPL/
|
env.extract_re s/PATTERN/REPL/
|
||||||
env.warning_days <default: 7 days>
|
env.warning_days <default: 7 days>
|
||||||
env.critical_days <default: 3 days>
|
env.critical_days <default: 3 days>
|
||||||
env.cache_expiry_mins <default: 60 minutes>
|
env.cache_expiry_mins <default: 60 minutes>
|
||||||
|
|
||||||
|
|
||||||
|
C<domains> is a space-separated list of domains to be checked.
|
||||||
The C<extract_re> will be used in C<sed> to extract the relevant expiry date. It
|
The C<extract_re> will be used in C<sed> to extract the relevant expiry date. It
|
||||||
default to C<s/^.*[Ee]xpir.*: //>. Only lines for which a replacement has
|
default to C<s/^.*[Ee]xpir.*: //>. Only lines for which a replacement has
|
||||||
happened will be considered, and the pattern should take care to only output
|
happened will be considered, and the pattern should take care to only output
|
||||||
|
@ -35,6 +32,11 @@ one line. While the default RegExp just finds a leader pattern and removes it,
|
||||||
it is possible to write more complex logic to format the date. The extracted
|
it is possible to write more complex logic to format the date. The extracted
|
||||||
date needs to be in a format supported by C<date(1)>'s C<--date> parameter.
|
date needs to be in a format supported by C<date(1)>'s C<--date> parameter.
|
||||||
|
|
||||||
|
Then create a symlink to enable this plugin:
|
||||||
|
|
||||||
|
ln -s /path/to/whois /etc/munin/plugins/
|
||||||
|
|
||||||
|
|
||||||
=head1 AUTHOR
|
=head1 AUTHOR
|
||||||
|
|
||||||
Olivier Mehani
|
Olivier Mehani
|
||||||
|
@ -53,13 +55,14 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1091
|
||||||
. "${MUNIN_LIBDIR}/plugins/plugin.sh"
|
. "${MUNIN_LIBDIR}/plugins/plugin.sh"
|
||||||
|
|
||||||
if [ "${MUNIN_DEBUG:-0}" = 1 ]; then
|
if [ "${MUNIN_DEBUG:-0}" = 1 ]; then
|
||||||
set -x
|
set -x
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
DOMAINS=${domains:-""}
|
||||||
EXTRACT_RE=${extract_re:-'s/^.*[Ee]xpir.*: //'}
|
EXTRACT_RE=${extract_re:-'s/^.*[Ee]xpir.*: //'}
|
||||||
WARNING=${warning_days:-7}
|
WARNING=${warning_days:-7}
|
||||||
CRITICAL=${critical_days:-3}
|
CRITICAL=${critical_days:-3}
|
||||||
|
@ -67,9 +70,8 @@ CACHE_EXPIRY=${cache_expiry_mins:-60}
|
||||||
|
|
||||||
# Args: domain name (optional, for title)
|
# Args: domain name (optional, for title)
|
||||||
graph_config() {
|
graph_config() {
|
||||||
NAMETITLE=${1:+ for ${1}}
|
|
||||||
cat << EOF
|
cat << EOF
|
||||||
graph_title Domain registration expiry${NAMETITLE}
|
graph_title Domain registration expiry
|
||||||
graph_category network
|
graph_category network
|
||||||
graph_vlabel days
|
graph_vlabel days
|
||||||
EOF
|
EOF
|
||||||
|
@ -78,43 +80,48 @@ EOF
|
||||||
# Args: domain name
|
# Args: domain name
|
||||||
# Separated from graph_config so we can easily extend the plugin to support multiple domains.
|
# Separated from graph_config so we can easily extend the plugin to support multiple domains.
|
||||||
config() {
|
config() {
|
||||||
local NAME=${1}
|
local NAME
|
||||||
local FIELDNAME
|
local FIELDNAME
|
||||||
|
for NAME in $DOMAINS
|
||||||
|
do
|
||||||
|
FIELDNAME="$(clean_fieldname "${NAME}")"
|
||||||
|
|
||||||
FIELDNAME="$(clean_fieldname "${NAME}")"
|
cat << EOF
|
||||||
|
${FIELDNAME}.label ${NAME}
|
||||||
cat << EOF
|
|
||||||
${FIELDNAME}.label expiry
|
|
||||||
${FIELDNAME}.cdef ${FIELDNAME},86400,/
|
${FIELDNAME}.cdef ${FIELDNAME},86400,/
|
||||||
${FIELDNAME}.warning ${WARNING}:
|
${FIELDNAME}.warning ${WARNING}:
|
||||||
${FIELDNAME}.critical ${CRITICAL}:
|
${FIELDNAME}.critical ${CRITICAL}:
|
||||||
EOF
|
EOF
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Args: domain name
|
# Args: domain name
|
||||||
fetch() {
|
fetch() {
|
||||||
local NAME=${1}
|
local NAME
|
||||||
local FIELDNAME
|
local FIELDNAME
|
||||||
local CACHEFILE
|
local CACHEFILE
|
||||||
|
|
||||||
FIELDNAME="$(clean_fieldname "${NAME}")"
|
for NAME in $DOMAINS
|
||||||
|
do
|
||||||
|
FIELDNAME="$(clean_fieldname "${NAME}")"
|
||||||
|
|
||||||
CACHEFILE="${MUNIN_PLUGSTATE}/$(basename "${0}").${FIELDNAME}.cache"
|
CACHEFILE="${MUNIN_PLUGSTATE}/$(basename "${0}").${FIELDNAME}.cache"
|
||||||
|
|
||||||
if [ -z "$(find "${CACHEFILE}" -mmin -"${CACHE_EXPIRY}" 2>/dev/null)" ]; then
|
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}" 2>/dev/null | sed -n "${EXTRACT_RE}p;T;q")" # T;q exits after printing the first match
|
||||||
DELTA_TS=U
|
DELTA_TS=U
|
||||||
if [ -n "${EXPIRY}" ]; then
|
if [ -n "${EXPIRY}" ]; then
|
||||||
EXPIRY_TS="$(date +%s -d "${EXPIRY}")"
|
EXPIRY_TS="$(date +%s -d "${EXPIRY}")"
|
||||||
|
|
||||||
NOW_TS="$(date +%s)"
|
NOW_TS="$(date +%s)"
|
||||||
DELTA_TS=$((EXPIRY_TS-NOW_TS))
|
DELTA_TS=$((EXPIRY_TS-NOW_TS))
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "${FIELDNAME}.value ${DELTA_TS}" > "${CACHEFILE}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${FIELDNAME}.value ${DELTA_TS}" > "${CACHEFILE}"
|
cat "${CACHEFILE}"
|
||||||
fi
|
done
|
||||||
|
|
||||||
cat "${CACHEFILE}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue