Révision 63505c50
Add support for multi-domain check
| plugins/network/whois | ||
|---|---|---|
| 6 | 6 |
|
| 7 | 7 |
=head1 NAME |
| 8 | 8 |
|
| 9 |
whois_ - Plugin to monitor expiry dates of domain in the WHOIS database
|
|
| 9 |
whois - Plugin to monitor expiry dates of domain in the WHOIS database |
|
| 10 | 10 |
|
| 11 | 11 |
Though the plugin will be called every 5 minutes, it will keep a cache, and |
| 12 |
only query the WHOIS database every hour.
|
|
| 12 |
only query the WHOIS database C<cache_expiry_mins> minutes.
|
|
| 13 | 13 |
|
| 14 | 14 |
=head1 CONFIGURATION |
| 15 | 15 |
|
| 16 |
None is needed, just |
|
| 16 |
First, create a section in your munin-node configuration files. The domain envvar |
|
| 17 |
is mandatory, others are optional. |
|
| 17 | 18 |
|
| 18 |
ln -s /path/to/whois_ whois_domain.tld |
|
| 19 |
|
|
| 20 |
in Munin's installed plugins directory will suffice to start monitoring |
|
| 21 |
C<domain.tld>. |
|
| 22 |
|
|
| 23 |
However, a few parameters, all optional, can be set if needed |
|
| 24 |
|
|
| 25 |
[whois_domain.tld] |
|
| 19 |
[whois] |
|
| 20 |
env.domains example.com example.org |
|
| 26 | 21 |
env.extract_re s/PATTERN/REPL/ |
| 27 | 22 |
env.warning_days <default: 7 days> |
| 28 | 23 |
env.critical_days <default: 3 days> |
| 29 | 24 |
env.cache_expiry_mins <default: 60 minutes> |
| 30 | 25 |
|
| 26 |
|
|
| 27 |
C<domains> is a space-separated list of domains to be checked. |
|
| 31 | 28 |
The C<extract_re> will be used in C<sed> to extract the relevant expiry date. It |
| 32 | 29 |
default to C<s/^.*[Ee]xpir.*: //>. Only lines for which a replacement has |
| 33 | 30 |
happened will be considered, and the pattern should take care to only output |
| ... | ... | |
| 35 | 32 |
it is possible to write more complex logic to format the date. The extracted |
| 36 | 33 |
date needs to be in a format supported by C<date(1)>'s C<--date> parameter. |
| 37 | 34 |
|
| 35 |
Then create a symlink to enable this plugin: |
|
| 36 |
|
|
| 37 |
ln -s /path/to/whois /etc/munin/plugins/ |
|
| 38 |
|
|
| 39 |
|
|
| 38 | 40 |
=head1 AUTHOR |
| 39 | 41 |
|
| 40 | 42 |
Olivier Mehani |
| ... | ... | |
| 53 | 55 |
|
| 54 | 56 |
set -eu |
| 55 | 57 |
|
| 56 |
# shellcheck disable=SC1090
|
|
| 58 |
# shellcheck disable=SC1091
|
|
| 57 | 59 |
. "${MUNIN_LIBDIR}/plugins/plugin.sh"
|
| 58 | 60 |
|
| 59 | 61 |
if [ "${MUNIN_DEBUG:-0}" = 1 ]; then
|
| 60 | 62 |
set -x |
| 61 | 63 |
fi |
| 62 | 64 |
|
| 65 |
DOMAINS=${domains:-""}
|
|
| 63 | 66 |
EXTRACT_RE=${extract_re:-'s/^.*[Ee]xpir.*: //'}
|
| 64 | 67 |
WARNING=${warning_days:-7}
|
| 65 | 68 |
CRITICAL=${critical_days:-3}
|
| ... | ... | |
| 67 | 70 |
|
| 68 | 71 |
# Args: domain name (optional, for title) |
| 69 | 72 |
graph_config() {
|
| 70 |
NAMETITLE=${1:+ for ${1}}
|
|
| 71 | 73 |
cat << EOF |
| 72 |
graph_title Domain registration expiry${NAMETITLE}
|
|
| 74 |
graph_title Domain registration expiry |
|
| 73 | 75 |
graph_category network |
| 74 | 76 |
graph_vlabel days |
| 75 | 77 |
EOF |
| ... | ... | |
| 78 | 80 |
# Args: domain name |
| 79 | 81 |
# Separated from graph_config so we can easily extend the plugin to support multiple domains. |
| 80 | 82 |
config() {
|
| 81 |
local NAME=${1}
|
|
| 83 |
local NAME |
|
| 82 | 84 |
local FIELDNAME |
| 85 |
for NAME in $DOMAINS |
|
| 86 |
do |
|
| 87 |
FIELDNAME="$(clean_fieldname "${NAME}")"
|
|
| 83 | 88 |
|
| 84 |
FIELDNAME="$(clean_fieldname "${NAME}")"
|
|
| 85 |
|
|
| 86 |
cat << EOF |
|
| 87 |
${FIELDNAME}.label expiry
|
|
| 89 |
cat << EOF |
|
| 90 |
${FIELDNAME}.label ${NAME}
|
|
| 88 | 91 |
${FIELDNAME}.cdef ${FIELDNAME},86400,/
|
| 89 | 92 |
${FIELDNAME}.warning ${WARNING}:
|
| 90 | 93 |
${FIELDNAME}.critical ${CRITICAL}:
|
| 91 | 94 |
EOF |
| 95 |
done |
|
| 92 | 96 |
} |
| 93 | 97 |
|
| 94 | 98 |
# Args: domain name |
| 95 | 99 |
fetch() {
|
| 96 |
local NAME=${1}
|
|
| 100 |
local NAME |
|
| 97 | 101 |
local FIELDNAME |
| 98 | 102 |
local CACHEFILE |
| 99 | 103 |
|
| 100 |
FIELDNAME="$(clean_fieldname "${NAME}")"
|
|
| 104 |
for NAME in $DOMAINS |
|
| 105 |
do |
|
| 106 |
FIELDNAME="$(clean_fieldname "${NAME}")"
|
|
| 101 | 107 |
|
| 102 |
CACHEFILE="${MUNIN_PLUGSTATE}/$(basename "${0}").${FIELDNAME}.cache"
|
|
| 108 |
CACHEFILE="${MUNIN_PLUGSTATE}/$(basename "${0}").${FIELDNAME}.cache"
|
|
| 103 | 109 |
|
| 104 |
if [ -z "$(find "${CACHEFILE}" -mmin -"${CACHE_EXPIRY}" 2>/dev/null)" ]; then
|
|
| 105 |
EXPIRY="$(whois "${NAME}" 2>/dev/null | sed -n "${EXTRACT_RE}p;T;q")" # T;q exits after printing the first match
|
|
| 106 |
DELTA_TS=U |
|
| 107 |
if [ -n "${EXPIRY}" ]; then
|
|
| 108 |
EXPIRY_TS="$(date +%s -d "${EXPIRY}")"
|
|
| 110 |
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
|
|
| 112 |
DELTA_TS=U
|
|
| 113 |
if [ -n "${EXPIRY}" ]; then
|
|
| 114 |
EXPIRY_TS="$(date +%s -d "${EXPIRY}")"
|
|
| 109 | 115 |
|
| 110 |
NOW_TS="$(date +%s)" |
|
| 111 |
DELTA_TS=$((EXPIRY_TS-NOW_TS)) |
|
| 112 |
fi |
|
| 116 |
NOW_TS="$(date +%s)"
|
|
| 117 |
DELTA_TS=$((EXPIRY_TS-NOW_TS))
|
|
| 118 |
fi
|
|
| 113 | 119 |
|
| 114 |
echo "${FIELDNAME}.value ${DELTA_TS}" > "${CACHEFILE}"
|
|
| 115 |
fi |
|
| 120 |
echo "${FIELDNAME}.value ${DELTA_TS}" > "${CACHEFILE}"
|
|
| 121 |
fi
|
|
| 116 | 122 |
|
| 117 |
cat "${CACHEFILE}"
|
|
| 123 |
cat "${CACHEFILE}"
|
|
| 124 |
done |
|
| 118 | 125 |
} |
| 119 | 126 |
|
| 120 | 127 |
main() {
|
Formats disponibles : Unified diff