forked from fsinf/munin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapt
executable file
·158 lines (147 loc) · 3.39 KB
/
apt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/perl -w
#
# Plugin to monitor packages that should be installed on systems using
# apt-get (mostly Debian, but also RedHat)
#
# This plugin needs a cronjob that runs apt-get update every hour or so
#
# This is a slightly modified version of the original plugin shipping with
# munin. For a diff from the original please see the svn changelog.
#
# ex
#
# /etc/cron.d/munin-plugin-apt
# 53 * * * * root apt-get update > /dev/null 2>&1
# 23 08 * * * root apt-get update > /dev/null
#
# Remember to randomize when these cronjobs are run on your servers
#
# Usage: place in /etc/munin/plugins (or link it there using ln -s)
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-config)
#
# $Log$
# Revision 1.6 2013/04/08 23:57:12 Mati
# critical is now at 20 by default
#
# Revision 1.5 2010/04/03 12:26:00 Mati
# remove graph=no, replaced warning with critical range
#
# Revision 1.4 2004/12/10 18:51:44 jimmyo
# linux/apt* has been forced to LANG=C, to get predictable output.
#
# Revision 1.3 2004/11/26 15:16:42 jimmyo
# Force plugin linux/apt to use C locale (SF#1072470).
#
# Revision 1.2 2004/11/04 19:07:01 jimmyo
# Adapt linux/apt plugin to work properly with Debian testing/unstable
# (patch from Rune N. Skillingstad).
#
# Revision 1.1 2004/01/02 18:50:01 jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1 2004/01/02 15:18:07 jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.3 2003/11/07 17:43:16 jimmyo
# Cleanups and log entries
#
#
#
# Magic markers - optional - used by installation scripts and
# munin-config:
#
#%# family=manual
#%# capabilities=autoconf
#
# Now for the real work...
use strict;
$ENV{'LANG'}="C";
$ENV{'LC_ALL'}="C";
my $statefile = "/var/lib/munin/plugin-state/plugin-apt.state";
if ($ARGV[0] and $ARGV[0] eq "autoconf")
{
`apt-get -v >/dev/null 2>/dev/null`;
if ($? eq "0")
{
print "yes\n";
exit 0;
}
else
{
print "no (apt-get not found)\n";
exit 1;
}
}
if ($ARGV[0] and $ARGV[0] eq "config")
{
print "graph_title Pending packages\n";
print "pending.label pending\n";
print "pending.critical :20 \n";
print "hold.label hold\n";
exit 0;
}
open (APT, "apt-get -u dist-upgrade --print-uris --yes |") or exit 22;
my @pending = ();
my $hold = 0;
my @remove = ();
my @install = ();
while (<APT>)
{
if (/^The following packages will be REMOVED:/)
{
my $where = 0;
while (<APT>)
{
last if (/^\S/);
foreach my $package (split /\s+/)
{
next unless ($package =~ /\S/);
push (@remove, "-$package");
}
}
}
if (/^The following NEW packages will be installed:/)
{
my $where = 0;
while (<APT>)
{
last if (/^\S/);
foreach my $package (split /\s+/)
{
next unless ($package =~ /\S/);
push (@install, "+$package");
}
}
}
if (/^The following packages will be upgraded/)
{
my $where = 0;
while (<APT>)
{
last if (/^\S/);
foreach my $package (split /\s+/)
{
next unless ($package =~ /\S/);
push (@pending, $package);
}
}
}
if (/^\d+\supgraded,\s\d+\snewly installed, \d+ to remove and (\d+) not upgraded/) {
$hold = $1;
}
}
push (@pending, @install) if @install;
push (@pending, @remove ) if @remove;
close APT;
print "pending.value ", scalar (@pending), "\n";
if (@pending)
{
print "pending.extinfo ", join (' ', @pending), "\n";
}
print "hold.value $hold\n";
exit 0;
# vim:syntax=perl