Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / debian / deborphan @ b247f8f2

Historique | Voir | Annoter | Télécharger (1,64 ko)

1
#!/bin/sh
2

    
3
: << =cut
4

    
5
=head1 NAME
6

    
7
deborphan - Monitor orphaned Debian packages
8

    
9
=head1 APPLICABLE SYSTEMS
10

    
11
Debian-ish systems with deborphan installed.
12

    
13
=head1 CONFIGURATION
14

    
15
None needed.
16

    
17
=head1 AUTHOR
18

    
19
Olivier Mehani <shtrom+munin@ssji.net>
20
Based on the debsecan plugin by Nicolas Bouthors. 2016-09-02
21

    
22
=head1 LICENSE
23

    
24
GPLv2
25

    
26
=head1 MAGIC MARKERS
27

    
28
  #%# family=auto
29
  #%# capabilities=autoconf
30

    
31
=cut
32

    
33
# shellcheck disable=SC1090
34
. "$MUNIN_LIBDIR/plugins/plugin.sh"
35

    
36
# Auto enable if we have deborphan only
37
if [ "$1" = "autoconf" ] ; then
38
  if which deborphan >/dev/null; then
39
    echo yes
40
  else
41
    echo "no (deborphan is missing)"
42
  fi
43
  exit 0
44
fi
45

    
46
# Fail if we don't have deborphan
47
if ! which deborphan >/dev/null; then
48
  echo "deborphan is missing" >&2
49
  exit 1
50
fi
51

    
52
OUT=$(deborphan --show-section --guess-all | sort)
53

    
54
CATEGORIES="$(echo "${OUT}" | awk '{print $1}' | uniq)"
55

    
56
if [ "$1" = "config" ]; then
57
  cat <<EOF
58
graph_title Orphaned packages
59
graph_args -l 0 --base 1000
60
graph_vlabel number of packages
61
graph_category system
62
graph_period second
63
graph_info This graph show the number of orphaned packages on your system. Use deborphan to see details.
64
EOF
65
  for CAT in ${CATEGORIES}; do
66
    CATFIELD=$(clean_fieldname "${CAT}")
67
    cat <<EOF
68
${CATFIELD}.label ${CAT}
69
${CATFIELD}.type GAUGE
70
${CATFIELD}.draw AREASTACK
71
${CATFIELD}.min 0
72
${CATFIELD}.info The number of orphaned packages in ${CAT}
73
EOF
74
  done
75

    
76
else
77
  for CAT in ${CATEGORIES}; do
78
    CATFIELD=$(clean_fieldname "${CAT}")
79
    CATDATA=$(echo "${OUT}" | sed -n 's#'"${CAT}"' \+##p')
80
    echo "${CATFIELD}.value $(echo "${CATDATA}" | wc -l)"
81
    echo "${CATFIELD}.extinfo $(echo "${CATDATA}" | tr '\n' ' ')"
82
  done
83
fi