diff --git a/plugins/mail/postfix_stats b/plugins/mail/postfix_stats index 7a2bcd5b..d3e5ae91 100755 --- a/plugins/mail/postfix_stats +++ b/plugins/mail/postfix_stats @@ -1,52 +1,135 @@ #!/bin/sh -# -# Plugin to show Postfix statistics - needs pflogsumm -# -# Contributed by David Obando (david@cryptix.de) - 16.04.2007 -# -# -# Magic markers - optional - used by installation scripts and -# munin-config: -# -#%# family=manual -#%# capabilities=autoconf +# -*- sh -*- + +: <<=cut + +=head1 NAME + +postfix_stats - Munin plugin to monitor postfix statistics. + +=head1 APPLICABLE SYSTEMS + +Any system where pflogsumm script can be executed. + +=head1 CONFIGURATION + +There is no default configuration. This is an example config for Ubuntu: + + [postfix_stats] + env.logfiles /var/log/syslog /var/log/syslog.1 + env.pflogsumm pflogsumm + +env.logfiles contains space separated syslog logfiles, usually current log +and previous log. You can add more log files if you want, but this may +increase the time required for analysis. + +env.pflogsumm The "pflogsumm" script, can be pflogsumm.pl if it was manually +downloaded and installed, or "pflogsumm" if it was installed by a package +manager (like apt-get). + +=head1 INTERPRETATION + +This plugin displays the messages: received, delivered, rejected... +Average per minute is made and it shows the total message count. +It is useful to know the load and messages being processed. + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=head1 VERSION + 0.2 plugin completely rewritten + 0.1 first release. + +=head1 BUGS + +None known + +=head1 AUTHOR + +Originally: David Obando (david@cryptix.de) +Modified by: github.com/cristiandeluxe +Thanks to: sumpfralle + +=head1 LICENSE + +GPLv2 + +=cut #set -xv +SYS_LOG="${logfiles:-/var/log/syslog /var/log/syslog.0}" -case $1 in - config) - cat <<'EOF' -system.type COUNTER -graph_title Postfix statistics -graph_vlabel Postfix statistics -graph_category Mail -graph_total Total -received.label received -delivered.label delivered -forwarded.label forwarded -deferred.label deferred -bounced.label bounced -rejected.label rejected -held.label held -discarded.label discarded -EOF - exit 0;; -esac +# shellcheck disable=SC2154 +PFLOGSUMM="${pflogsum}" +[ -z "$PFLOGSUMM" ] && PFLOGSUMM="$(which pflogsumm pflogsumm.pl | head -1)" +# Fields (Array to avoid code duplication) must be space separated +FIELDS_ARR="received delivered forwarded deferred bounced rejected held discarded" -TMP=`mktemp /tmp/tmp.XXXXXXXX` -pflogsumm.pl --smtpd_stats -d today /var/log/syslog /var/log/syslog.0 | head -n 15 > $TMP +# +# Autoconf Section +# +if [ "$1" = 'autoconf' ]; then + # Check if pflogsumm exist + if [ -z "${PFLOGSUMM}" ] + then + echo 'no (pflogsum not found in your system)' + else + echo 'yes' + fi + exit 0 +fi -cat < +Based on the debsecan plugin by Nicolas Bouthors. 2016-09-02 + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +# shellcheck disable=SC1090 +. "$MUNIN_LIBDIR/plugins/plugin.sh" + +# Auto enable if we have deborphan only +if [ "$1" = "autoconf" ] ; then + if which deborphan >/dev/null; then + echo yes + else + echo "no (deborphan is missing)" + fi + exit 0 +fi + +# Fail if we don't have deborphan +if ! which deborphan >/dev/null; then + echo "deborphan is missing" >&2 + exit 1 +fi + +OUT=$(deborphan --show-section --guess-all | sort) + +CATEGORIES="$(echo "${OUT}" | awk '{print $1}' | uniq)" + +if [ "$1" = "config" ]; then + cat < (based on disk/log_sizes) + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=manual + +=cut + +# needs shellcheck -x /usr/share/munin/plugins/plugin.sh +# shellcheck source=/usr/share/munin/plugins/plugin.sh +. "$MUNIN_LIBDIR/plugins/plugin.sh" + +NAME=$(echo "$0" | sed 's/.*_//') +TITLE=${title:-File lengths for $NAME} +CATEGORY=${category:-system} + +FILES=${files:-/var/log/messages} +# we want globbing to happen here +# shellcheck disable=SC2116 disable=SC2086 +FILES=$(echo $FILES) + + +if [ "$1" = "config" ] ; then + # shellcheck disable=SC2154 + if [ "${logarithmic}" = "1" ]; then + graph_args="-o" + else + graph_args="-l 0" + fi + cat < + +=head1 LICENSE + +GPLv2 + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +states="active \ + reloading \ + inactive \ + failed \ + activating \ + deactivating" +autoconf() { + which systemctl >/dev/null && \ + systemctl --state=failed --no-pager --no-legend >/dev/null 2>&1 && echo yes || echo "no (No systemctl or error running it)" +} + +config () { + cat << EOF +graph_title Systemd units state +graph_args -l 0 +graph_category system +graph_scale no +graph_vlabel units +EOF + for state in $states; do + echo "$state.label $state" + echo "$state.draw AREASTACK" + if [ "$state" = "failed" ]; then + echo "$state.warning 0" + echo "$state.critical 10" + fi + done +} + +fetch () { + tmp=$(systemctl --no-pager --no-legend --all | awk '{print $1, $3}') + for state in $states ; do + count=$(echo "$tmp" | grep -c "$state$") + echo "$state.value $count" + extinfo=$(echo "$tmp" | grep "$state$" | cut -d " " -f 1 | tr '\n' ' ') + if [ -n "$extinfo" ]; then + echo "$state.extinfo" "$extinfo" + fi + done +} + +case $1 in + "autoconf") + autoconf + ;; + "config") + config + ;; + *) + fetch + ;; +esac