-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcheck_rum_update.pl
104 lines (80 loc) · 2.66 KB
/
check_rum_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_rum);
my $critical = 0;
my ($filelist, @updatelist, $num_upg, $num_new, $num_del, $num_noupg);
GetOptions ('file=s' => \$file,
'run-rum' => \$run_rum,
'help' => sub { &usage() } );
# python 2.5.1 throws this nasty error message on STERR:
#/usr/lib64/python2.5/urllib2.py:662: RuntimeWarning: urllib can't handle https proxies, your https_proxy setting will not work
#we really want to supress it
if($ENV{https_proxy}) { delete $ENV{https_proxy}; }
if (defined($run_rum)) {
open STDIN, "/usr/bin/rum lu |" or die "UNKNOWN - rum lu: $!\n";
} elsif (defined($file)) {
open STDIN, "< $file" or die "UNKNOWN - $file : $!\n";
}
my $ret;
# process each line returned by rum here:
while (<>) {
next if(/^$/);
# exit if there is no update: # rum lu
#
#--- No updates found ---
#
if(/^--- No updates found ---/) {
print ("OK - system is up to date\n");
exit (0);
}
# if there are any updates, we get the list.
# example output looks like this: # rum lu
#
# Repository | Name | Current Version | Updated Version
# -----------------+-------------+-----------------+-----------------
# opensuse-updates | ipsec-tools | 0.6.5-104 | 0.6.5-104.3.i586
if (/^Repository | Name | Current Version | Updated Version/) {
# debug: print "We got updates...\n";
while (<>) {
next if(/^$/);
next if(/^--.*/);
chop($_);
(@updatelist) = split('\|', $_);
$filelist .= $updatelist[1]."Version".$updatelist[3];
$num_upg ++;
}
}
}
if (! defined($num_upg)) {
print ("UNKNOWN - could not parse \"rum lu\" output\n");
exit (3);
}
if ($num_upg > 0) {
print ("WARNING - $num_upg update(s) available:$filelist\n");
exit (1);
}
exit(-1);
# ===========
sub usage() {
printf("
Nagios SNMP check for SUSE SLES10 package updates
Author: Frank Migge <support\@frank4dd.com>
after check-yum-upgrade.pl written by
Michal Ludvig <michal\@logix.cz> (c) 2006
Usage: check_rum_upgrade.pl [options]
--help Guess what's it for ;-)
--file=<file> File with output from previous \"rum lu\"
--run-rum Run \"rum lu \" directly.
Option --run-rum has precedence over --file, i.e. no file is
read if rum-get 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).
The SNMP timeout needs to be increased bceaus ethe script
rarely finishes in the standard 1 sec. -> check_snmp_extend.sh
Return value (according to Nagios expectations):
* If no updates are found, returns OK.
* If there are any updates, return WARNING.
");
exit (1);
}