1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00

[deborphan] Don't use tempfiles, and other fixes

Signed-off-by: Olivier Mehani <shtrom@ssji.net>
This commit is contained in:
Olivier Mehani 2016-11-05 21:48:55 +11:00
parent 5cfc73c3c8
commit ddbb4782ec

View file

@ -30,6 +30,9 @@ GPLv2
=cut =cut
# shellcheck disable=SC1090
. "$MUNIN_LIBDIR/plugins/plugin.sh"
# Auto enable if we have deborphan only # Auto enable if we have deborphan only
if [ "$1" = "autoconf" ] ; then if [ "$1" = "autoconf" ] ; then
if which deborphan >/dev/null; then if which deborphan >/dev/null; then
@ -46,12 +49,9 @@ if ! which deborphan >/dev/null; then
exit 1 exit 1
fi fi
OUT=$(mktemp -t munin-deborphan.XXXXXX) OUT=$(deborphan --show-section --guess-all | sort)
TMPFILES=$OUT
trap 'rm -f $TMPFILES' EXIT
deborphan --show-section --guess-all | sed 's/\//_/' | sort > "${OUT}"
CATEGORIES="$(awk '{print $1}' "${OUT}" | uniq)" CATEGORIES="$(echo "${OUT}" | awk '{print $1}' | uniq)"
if [ "$1" = "config" ]; then if [ "$1" = "config" ]; then
cat <<EOF cat <<EOF
@ -62,24 +62,22 @@ graph_category system
graph_period second graph_period second
graph_info This graph show the number of orphaned packages on your system. Use deborphan to see details. graph_info This graph show the number of orphaned packages on your system. Use deborphan to see details.
EOF EOF
for cat in ${CATEGORIES}; do for CAT in ${CATEGORIES}; do
CATFIELD=$(clean_fieldname "${CAT}")
cat <<EOF cat <<EOF
${cat}.label ${cat/_/\/} ${CATFIELD}.label ${CAT}
${cat}.type GAUGE ${CATFIELD}.type GAUGE
${cat}.draw AREASTACK ${CATFIELD}.draw AREASTACK
${cat}.min 0 ${CATFIELD}.min 0
${cat}.info The number of orphaned packages in ${cat/_/\/} ${CATFIELD}.info The number of orphaned packages in ${CAT}
EOF EOF
done done
else else
for cat in ${CATEGORIES}; do for CAT in ${CATEGORIES}; do
TMP=$(mktemp -t munin-deborphan.XXXXXX) CATFIELD=$(clean_fieldname "${CAT}")
TMPFILES="${TMPFILES} $TMP" CATDATA=$(echo "${OUT}" | sed -n "s#${CAT} \+##p")
sed -n "s/${cat} \+//p" "${OUT}" > "${TMP}" echo "${CATFIELD}.value $(echo "${CATDATA}" | wc -l)"
echo "${cat}.value $(wc -l < "${TMP}")" echo "${CATFIELD}.extinfo $(echo "${CATDATA}" | tr '\n' ' ')"
# shellcheck disable=SC2005 disable=SC2046
# echo is not useless here: we want everything on one line
echo "${cat}.extinfo $(echo $(cat "${TMP}"))"
done done
fi fi