forked from mludvig/nagios-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-yum-update.pl
executable file
·104 lines (86 loc) · 2.49 KB
/
check-yum-update.pl
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
#!/usr/bin/env perl
use strict;
use Getopt::Long;
my ($file, $run_yum);
my $critical = 0;
my $num_upg = 0;
my $filelist;
my $filelist_s;
$ENV{LC_ALL} = 'C';
GetOptions ('file=s' => \$file,
'run-yum' => \$run_yum,
'help' => sub { &usage() } );
if (defined($run_yum)) {
open STDIN, "yum check-update |" or die "UNKNOWN - yum check-update : $!\n";
} elsif (defined($file)) {
open STDIN, "< $file" or die "UNKNOWN - $file : $!\n";
}
my $pkglist_switch = 0;
while (<>) {
if ($pkglist_switch == 0) {
$pkglist_switch = 1 if (/^\s*$/);
next;
}
if (/^([^\s]+)\s+([^\s]+)\s+([^\s]+)/) {
my $package = $1;
my $version = $2;
my $repository = $3;
$package =~ s/\.[^\.]+$//;
$filelist .= $package." ";
$num_upg ++;
}
}
if (defined($run_yum)) {
open STDIN, "yum check-update --security|" or die "UNKNOWN - Please install yum security plugin : $!\n";
}
my $pkglist_switch = 0;
while (<>) {
if ($pkglist_switch == 0) {
$pkglist_switch = 1 if (/^\s*$/);
next;
}
if (/^([^\s]+)\s+([^\s]+)\s+([^\s]+)/) {
my $package = $1;
my $version = $2;
my $repository = $3;
$package =~ s/\.[^\.]+$//;
$filelist_s .= $package." ";
$critical ++;
}
}
my $ret;
if ($num_upg == 0 and $pkglist_switch == 1) {
print ("UNKNOWN - could not parse \"yum check-update\" output\n");
$ret = 3;
} elsif ($critical > 0) {
print ("CRITICAL - $critical security updates available: $filelist_s\n");
$ret = 2;
} elsif ($num_upg > 0) {
print ("WARNING - $num_upg updates available: $filelist\n");
$ret = 1;
} else {
print ("OK - system is up to date\n");
$ret = 0;
}
exit $ret;
# ===========
sub usage() {
printf("
Nagios SNMP check for RH / Centos package updates
Author: Michal Ludvig <michal\@logix.cz> (c) 2007
http://www.logix.cz/michal/devel/nagios
Usage: check-yum-update.pl [options]
--help Guess what's it for ;-)
--file=<file> File with output of \"yum check-update\"
--run-yum Run \"yum check-update\" directly.
Option --run-yum has precedence over --file, i.e. no file is
read if yum is run internally. If none of these options
is given use standard input by default (e.g. to read from
external command through a pipe).
Return value (according to Nagios expectations):
* If no updates are found, returns OK.
* If there are only non-security updates, return WARNING.
* If there are security updates, return CRITICAL.
");
exit (1);
}