2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/system/deborphan
Olivier Mehani 5cfc73c3c8 [deborphan] Cleanup and add POD doc
Signed-off-by: Olivier Mehani <shtrom@ssji.net>
2016-10-29 16:21:16 +11:00

86 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
: << =cut
=head1 NAME
deborphan - Monitor orphaned Debian packages
=head1 APPLICABLE SYSTEMS
Debian-ish systems with deborphan installed.
=head1 CONFIGURATION
None needed.
=head1 AUTHOR
Olivier Mehani <shtrom+munin@ssji.net>
Based on the debsecan plugin by Nicolas Bouthors. 2016-09-02
=head1 LICENSE
GPLv2
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
# 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=$(mktemp -t munin-deborphan.XXXXXX)
TMPFILES=$OUT
trap 'rm -f $TMPFILES' EXIT
deborphan --show-section --guess-all | sed 's/\//_/' | sort > "${OUT}"
CATEGORIES="$(awk '{print $1}' "${OUT}" | uniq)"
if [ "$1" = "config" ]; then
cat <<EOF
graph_title Orphaned packages
graph_args -l 0 --base 1000
graph_vlabel number of packages
graph_category system
graph_period second
graph_info This graph show the number of orphaned packages on your system. Use deborphan to see details.
EOF
for cat in ${CATEGORIES}; do
cat <<EOF
${cat}.label ${cat/_/\/}
${cat}.type GAUGE
${cat}.draw AREASTACK
${cat}.min 0
${cat}.info The number of orphaned packages in ${cat/_/\/}
EOF
done
else
for cat in ${CATEGORIES}; do
TMP=$(mktemp -t munin-deborphan.XXXXXX)
TMPFILES="${TMPFILES} $TMP"
sed -n "s/${cat} \+//p" "${OUT}" > "${TMP}"
echo "${cat}.value $(wc -l < "${TMP}")"
# shellcheck disable=SC2005 disable=SC2046
# echo is not useless here: we want everything on one line
echo "${cat}.extinfo $(echo $(cat "${TMP}"))"
done
fi