summaryrefslogtreecommitdiff
path: root/nagios-check-apt-updates
diff options
context:
space:
mode:
Diffstat (limited to 'nagios-check-apt-updates')
-rwxr-xr-xnagios-check-apt-updates38
1 files changed, 21 insertions, 17 deletions
diff --git a/nagios-check-apt-updates b/nagios-check-apt-updates
index 346a49d..b65e6a0 100755
--- a/nagios-check-apt-updates
+++ b/nagios-check-apt-updates
@@ -34,25 +34,27 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
my $APT = '/usr/bin/apt-get';
my $VERBOSE;
-sub do_check($$$$$) {
- my ($pre_command, $timeout, $name, $updates_security, $updates_other) = @_;
+sub do_check($$$$$$) {
+ my ($pre_command, $timeout, $noupdate, $name, $updates_security, $updates_other) = @_;
my $fh;
my $pid;
my @command;
- print STDERR "Running $APT update in $name\n" if $VERBOSE;
- @command = ($APT, 'update');
- unshift @command, @$pre_command;
- $fh = new IO::Handle;
- $pid = open2($fh, \*STDIN, @command) or die ("Cannot run $APT update in $name: $!\n");
- local $SIG{ALRM} = sub { die "Timeout for apt-get update.\n" };
- alarm $timeout;
- my @ignore=<$fh>;
- alarm 0;
- close $fh;
- waitpid $pid, 0;
- if ($CHILD_ERROR) { # program failed
- die("$APT update returned with non-zero exit code in $name: ".($CHILD_ERROR / 256)."\n");
+ unless ($noupdate) {
+ print STDERR "Running $APT update in $name\n" if $VERBOSE;
+ @command = ($APT, 'update');
+ unshift @command, @$pre_command;
+ $fh = new IO::Handle;
+ $pid = open2($fh, \*STDIN, @command) or die ("Cannot run $APT update in $name: $!\n");
+ local $SIG{ALRM} = sub { die "Timeout for apt-get update.\n" };
+ alarm $timeout;
+ my @ignore=<$fh>;
+ alarm 0;
+ close $fh;
+ waitpid $pid, 0;
+ if ($CHILD_ERROR) { # program failed
+ die("$APT update returned with non-zero exit code in $name: ".($CHILD_ERROR / 256)."\n");
+ };
};
print STDERR "Running $APT --simulate upgrade in $name\n" if $VERBOSE;
@@ -107,6 +109,7 @@ if (!GetOptions (
'--help' => \$params->{'help'},
'--version' => \$params->{'version'},
'--sudo' => \$params->{'sudo'},
+ '--noupdate' => \$params->{'noupdate'},
'--nosudo' => \$params->{'nosudo'},
'--verbose' => \$params->{'verbose'},
'--warnifupdates' => \$params->{'warnifupdates'},
@@ -124,6 +127,7 @@ if ($params->{'help'}) {
print " --help Print this short help.\n";
print " --version Report version number.\n";
print " --sudo Use sudo to call apt-get (default).\n";
+ print " --noupdate Do not run apt-get update first.\n";
print " --nosudo Do not use sudo to call apt-get.\n";
print " --warnifupdates Exit with a WARNING status if any updates are available.\n";
print " --timeout=<timeout> Timeout in seconds for each of the two apt-get runs.\n";
@@ -186,7 +190,7 @@ for my $root (@chroots) {
my @pre_command = ();
unshift @pre_command, 'chroot', $root if ($root ne '/');
unshift @pre_command, 'sudo' if $use_sudo;
- do_check(\@pre_command, $params->{'timeout'}, $root, \@updates_security, \@updates_other);
+ do_check(\@pre_command, $params->{'timeout'}, $params->{'noupdate'}, $root, \@updates_security, \@updates_other);
}
# Make sure vserver names are nice;
@@ -202,7 +206,7 @@ for my $vserver (@vservers) {
my @pre_command = ();
unshift @pre_command, '/usr/sbin/vserver', $vserver, 'exec';
unshift @pre_command, 'sudo' if $use_sudo;
- do_check(\@pre_command, $params->{'timeout'}, $vserver, \@updates_security, \@updates_other);
+ do_check(\@pre_command, $params->{'timeout'}, $params->{'noupdate'}, $vserver, \@updates_security, \@updates_other);
}