FUN WITH LINUX

Monitoring Horde-Framework-Upgrades using Nagios

19 November 2014

Nagios is an awesome monitoring-tool. I give my best to check as much services as possible with nagios. Here I want to explain how I check if updates for the Horde-Framework exist…

Although horde uses pear for update-management I don’t want to check pear directly(because of permissions and of course I don’t want to create too much traffic on the horde-repository). That’s why i use the following cronjob which checks for upgrades once an hour:

45 * * * * pear list-upgrades > /var/log/pear_check_updates.log

Now this nagios-check(check_pear_updates.pl) can use this information:

#!/usr/bin/perl

###########################################################################
#
# you need a cronjob with this command:
# pear list-upgrades > /var/log/pear_check_updates.log
#
##########################################################################

my $pearchannel = 'Waynes World! Waynes World! Party time! Excellent!';
my @logarr = undef;
my $found = 0;
my $checkother = 0;
my $available_upgrades = 0;
my $ret = 2;

if($#ARGV < 0)
{
        print "usage: $0 []\n";
        exit 3;
}

my $pearlog = $ARGV[0];

$pearchannel = $ARGV[1] if($#ARGV > 0);


unless(open(PEARLOG,"< $pearlog"))
{
        print "Error: can not open logfile: $pearlog\n";
        exit 3;
}
while()
{
        my $tmp = $_;

        $available_upgrades++ if($tmp =~ /AVAILABLE UPGRADES/);
        if($tmp =~ /^Channel $pearchannel/)
        {
                print $tmp;
        }
        else
        {
                my @tmparr = split(/\s+/,$tmp);
                if($tmparr[0] eq $pearchannel)
                {
                        print "$tmparr[1] $tmparr[2] $tmparr[3] $tmparr[4] $tmparr[5] $tmparr[6],";
                        $found = 1;
                }
        }
        push(@logarr,$tmp);
}
close(PEARLOG);

exit $ret if($found == 1);

if($checkother == 1)
{
        if($available_upgrades > 0)
        {
                print "found $available_upgrades other updates than $pearchannel\n";
                exit 1;
        }
}

exit 0;

If we correctly set the permissions for the  pear-logfile, our nagios-check can read it.

Here is the download to the full source-code

[ Linux  Nagios  Programming  Perl  Horde  ]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 Unported License.

Copyright 2015-present Hoti