1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

smtp_hello_: enable monitoring multiple ports at once

This commit is contained in:
Andreas Perhab 2022-05-04 10:20:23 +02:00 committed by Lars Kruse
parent 9bf3b9a299
commit f676ff11e9

View file

@ -41,14 +41,8 @@ if [ "${MUNIN_DEBUG:-0}" == "1" ]; then
fi fi
SMTP_COMMAND=${SMTP_COMMAND:-HELO localhost} SMTP_COMMAND=${SMTP_COMMAND:-HELO localhost}
SMTP_PORT=${SMTP_PORT:-25} SMTP_PORTS=${SMTP_PORTS:-25}
TIMEOUT_SECONDS=${TIMEOUT_SECONDS:-120} TIMEOUT_SECONDS=${TIMEOUT_SECONDS:-120}
# if we have curl all non-zero exit codes indicate an error
status_warning=${status_warning:-0:0}
# default warning time begins at half the timeout
host_warning=${host_warning:-:$((TIMEOUT_SECONDS/2))}
# default when we get values bigger than 99% of timeout we mark the value as critical
host_critical=${host_critical:-:$((TIMEOUT_SECONDS * 99 / 100))}
host=$(basename "$0" | sed 's/^smtp_hello_//g') host=$(basename "$0" | sed 's/^smtp_hello_//g')
@ -95,19 +89,36 @@ fi
if [ "$1" == "config" ]; then if [ "$1" == "config" ]; then
echo "graph_title smtp response time" echo "graph_title $host smtp response time"
echo "graph_vlabel response in sec" echo "graph_vlabel response in sec"
echo "graph_period minute" echo "graph_period minute"
echo "graph_category network" echo "graph_category network"
echo "graph_args --base 1000 --lower-limit 0" echo "graph_args --base 1000 --lower-limit 0"
echo "host.label $host" for port in $SMTP_PORTS; do
print_warning "host" if [[ $port ]] ; then
print_critical "host" if [[ $port = "25" ]] ; then
if [ "$curl_with_smtp_support" == "1" ] ; then suffix=""
echo "status.label $host smtp success" else
print_warning "status" suffix="_$port"
print_critical "status" fi
fi echo "host$suffix.label smtp port $port"
# default warning time begins at half the timeout
eval "export host${suffix}_warning=\${host${suffix}_warning:-:$((TIMEOUT_SECONDS / 2))}"
# default when we get values bigger than 99% of timeout we mark the value as critical
eval "export host${suffix}_critical=\${host${suffix}_critical:-:$((TIMEOUT_SECONDS * 99 / 100))}"
print_warning "host${suffix}"
print_critical "host${suffix}"
if [ "$curl_with_smtp_support" == "1" ] ; then
# if we have curl, all non-zero exit codes indicate an error
eval "export status${suffix}_warning=\${status${suffix}_warning:-0:0}"
echo "status$suffix.label smtp port $port check status"
print_warning "status${suffix}"
print_critical "status${suffix}"
fi
fi
done
elif [ "$1" == "autoconf" ]; then elif [ "$1" == "autoconf" ]; then
@ -119,20 +130,29 @@ elif [ "$1" == "autoconf" ]; then
exit 0 exit 0
else else
if [ "$curl_with_smtp_support" == "1" ] ; then for port in $SMTP_PORTS; do
value=$(take_the_time curl --silent -X "$SMTP_COMMAND" --max-time "$TIMEOUT_SECONDS" "smtp://$host:$SMTP_PORT/") if [[ $port ]] ; then
status=$? if [[ $port = "25" ]] ; then
else suffix=""
# Note: "HELO localhost" only works if the SMTP server terminates the connection when presenting the HELO line else
# if you have troubles here, try installing curl (with smtp support), and we will use a proper smtp client suffix="_$port"
# implementation. alternatively you can also set the SMTP_COMMAND environment variable to QUIT fi
value=$(echo "$SMTP_COMMAND" | take_the_time "$nc_executable" -C -w "$TIMEOUT_SECONDS" "$host" "$SMTP_PORT") if [ "$curl_with_smtp_support" == "1" ] ; then
# with the simple echo command we would need to check a lot of conditions to determine a successful status value=$(take_the_time curl --silent -X "$SMTP_COMMAND" --max-time "$TIMEOUT_SECONDS" "smtp://$host:$port/")
# if you want this feature, install curl instead status=$?
status="" else
fi # Note: "HELO localhost" only works if the SMTP server terminates the connection when presenting the HELO line
echo "host.value $value" # if you have troubles here, try installing curl (with smtp support), and we will use a proper smtp client
if [ -n "$status" ] ; then # implementation. alternatively you can also set the SMTP_COMMAND environment variable to QUIT
echo "status.value $status" value=$(echo "$SMTP_COMMAND" | take_the_time "$nc_executable" -C -w "$TIMEOUT_SECONDS" "$host" "$port")
fi # with the simple echo command we would need to check a lot of conditions to determine a successful status
# if you want this feature, install curl instead
status=""
fi
echo "host$suffix.value $value"
if [ -n "$status" ] ; then
echo "status$suffix.value $status"
fi
fi
done
fi fi