Plugin check_backuppc (Nagios) [RESOLVIDO]

1. Plugin check_backuppc (Nagios) [RESOLVIDO]

Jorge Augusto Rabello Pinto
jorgerabello

(usa Ubuntu)

Enviado em 10/04/2010 - 14:14h

Senhores, bom dia.
Há um mês venho tentando fazer funcionar um plugin do Nagios, muito interessante chamdo check_backuppc.
O que ele faz é verificar o log do último backup do backuppc (Excelente ferramente de backup) e procura por ERR (Flag de Erro no log), então se o Backup foi bem sucedido (se ele não encontrou erros) o status do monitoramento no Nagios fica Verde, caso contrario fica Vermelho).
Emfim eu fiz download dos fontes do plugin check_backuppc de

http://sourceforge.net/projects/n-backuppc/files/check_backuppc/1.1.0/check_backuppc-1.1.0.tar.gz/do...

Dentro dele vem um arquivo INSTALL e um arquivo README:

INSTALL:

Automated Install Steps:
------------------------
1) Set NAGIOS_LIB to the directory containing Nagios's util.pm
2) Set BACKUPPC_LIB to the directory containing BackupPC's Perl libraries
3) Set PREFIX to the desired installation location
4) make install

Manual Install Steps:
---------------------
1) Edit check_backuppc and adjust the two "use lib" lines to refer to the
correct location for Nagios's utils.pm and BackupPC's Perl libraries.
2) Copy check_backuppc into where you want this plugin.

Configuration:
--------------
1) Add a sudoers entry to allow Nagios to run this plugin as the BackupPC user.
2) Configure Nagios to run this plugin through sudo as the BackupPC user.
3) Test
4) Add to Nagios service checks

README:
This plugin must be run as the same user that BackupPC runs under. For a host
to be considered an archive host by the --backup-only and --archive-only options
at least one archive must be run by the host.

Sample configuration for NRPE with Ubuntu hosts:
1) Add the following line to /etc/sudoers on the backup host
nagios ALL = (backuppc) NOPASSWD: /usr/local/lib/nagios/plugins/check_backuppc

2) Add the following line to /etc/nagios/nrpe.cfg
command[check_backuppc]=/usr/bin/sudo -u backuppc \
/usr/local/lib/nagios/plugins/check_backuppc

3) Add the appropriate stanza to your Nagios configuration to use this check
with NRPE.

E o check_backuppc propriamente dito que na verdade é um script, segue:

check_backuppc:

#!/usr/bin/perl
#
# check_backuppc: a Nagios plugin to check the status of BackupPC
#
# Tested against BackupPC 2.1.2 and Nagios 1.3
# <http://backuppc.sourceforge.net>
# <http://nagios.org>
#
# AUTHORS
# Seneca Cunningham <tetragon@users.sourceforge.net>
#
# COPYRIGHT
# Copyright (C) 2006,2007 Seneca Cunningham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#

use strict;
no utf8;

# Nagios
use lib "NAGIOS_LIB";
use utils qw(%ERRORS $TIMEOUT);
use POSIX qw(strftime difftime);
use Getopt::Long;
Getopt::Long::Configure('bundling');

# BackupPC
use lib "BACKUPPC_LIB";
use BackupPC::Lib;

my $version = '1.1.0';
my $warnLevel = 0;
my $daysOld = 7;
my $verbose = 0;
my $opt_V = 0;
my $opt_h = 0;
my $goodOpt = 0;
my $reduce = 0;
my $backupOnly = 0;
my $archiveOnly = 0;
my $statusOnly = 0;
my @hostsDesired;
my @hostsExcluded;

# Process options
$goodOpt = GetOptions(
'v+' => \$verbose, 'verbose+' => \$verbose,
'c=f' => \$daysOld, 'critical=f' => \$daysOld,
'w=f' => \$warnLevel, 'warning=f' => \$warnLevel,
'V' => \$opt_V, 'version' => \$opt_V,
'h' => \$opt_h, 'help' => \$opt_h,
'r=i' => \$reduce, 'reduce' => \$reduce,
'b' => \$backupOnly, 'backup-only' => \$backupOnly,
'a' => \$archiveOnly, 'archive-only' => \$archiveOnly,
's' => \$statusOnly, 'status-only' => \$statusOnly,
'H=s' => \@hostsDesired, 'hostname=s' => \@hostsDesired,
'x=s' => \@hostsExcluded, 'exclude=s' => \@hostsExcluded);

@hostsDesired = () if $#hostsDesired < 0;
@hostsExcluded = () if $#hostsExcluded < 0;

if ($opt_V)
{
print "check_backuppc - " . $version . "\n";
exit $ERRORS{'OK'};
}
if ($backupOnly and $archiveOnly)
{
$goodOpt = 0;
print "Cannot apply both --backup-only and --archive-only, contradictory\n\n";
}
if ($opt_h or not $goodOpt)
{
print "check_backuppc - " . $version . "\n";
print "A Nagios plugin to check on BackupPC backup status.\n\n";
print "Options:\n";
print " --hostname,-H only check the specified host\n";
print " --exclude,-x do not check the specified host\n";
print " --archive-only,-a only check the archive hosts\n";
print " --backup-only,-b only check the backup hosts\n";
print " --status-only,-s only check backup status, omit connection failures that are\n";
print " less than \$Conf{FullPeriod} old\n";
print " --warning,-w days old an errored host must be to cause a warning\n";
print " --critical,-c number of days old an errored backup must be to be critical\n";
print " --reduce,-r maximum number of failed hosts for severity reduction\n";
print " --verbose,-v increase verbosity\n";
print " --version,-V display plugin version\n";
print " --help,-h display this message\n\n";
exit $ERRORS{'OK'} if $goodOpt;
exit $ERRORS{'UNKNOWN'};
}
if ($warnLevel > $daysOld)
{
print("BACKUPPC UNKNOWN - Warning threshold must be <= critical\n");
exit $ERRORS{'UNKNOWN'};
}

# Connect to BackupPC
my $server;
if (!($server = BackupPC::Lib->new))
{
print "BACKUPPC CRITICAL - Couldn't connect to BackupPC\n";
exit $ERRORS{'CRITICAL'};
}
my %Conf = $server->Conf();

$server->ChildInit();

my $err = $server->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
if ($err)
{
print("BACKUPPC UNKNOWN - Can't connect to server ($err)\n");
exit $ERRORS{'UNKNOWN'};
}

# hashes that BackupPC uses for varios status info
my %Status;
my %Jobs;
my %Info;

# query the BackupPC server for host, job, and server info
my $info_raw = $server->ServerMesg('status info');
my $jobs_raw = $server->ServerMesg('status jobs');
my $status_raw = $server->ServerMesg('status hosts');

# undump the output... BackupPC uses Data::Dumper
eval $info_raw;
eval $jobs_raw;
eval $status_raw;

# check the dumped output
my $hostCount = 0;
my @goodHost;
my @badHost;
my @tooOld;
my @notTooOld;

foreach my $host (@hostsDesired, @hostsExcluded)
{
if (not grep {/$host/} keys(%Status))
{
print("BACKUPPC UNKNOWN - Unknown host ($host)\n");
exit $ERRORS{'UNKNOWN'};
}
}

# host status checks
foreach my $host (sort(keys(%Status)))
{
next if $host =~ /^ /;
next if (@hostsDesired and not grep {/$host/} @hostsDesired);
next if (@hostsExcluded and grep {/$host/} @hostsExcluded);
next if ($backupOnly and $Status{$host}{'type'} eq 'archive');
next if ($archiveOnly and $Status{$host}{'type'} ne 'archive');
$hostCount++;
# Debug
if ($verbose == 3)
{
print "Host $host state " . $Status{$host}{'state'};
print " with error: " . $Status{$host}{'error'} . "\n";
}
if ($Status{$host}{'error'})
{
# Check connectivity errors with greater care
if ($statusOnly && (
$Status{$host}{'error'} eq 'ping too slow' ||
$Status{$host}{'error'} eq 'no ping response' ||
$Status{$host}{'error'} eq 'host not found')) {
if ($Status{$host}{'lastGoodBackupTime'} - $Status{$host}{'startTime'} <= $Conf{FullPeriod} * 3600 * 24) {
push @goodHost, $host;
next;
}
}
push @badHost, $host;
# Check bad host ages
$Status{$host}{'lastGoodBackupTime'} = $Status{$host}{'startTime'} if (not $Status{$host}{'lastGoodBackupTime'});
if (difftime(time(), $Status{$host}{'lastGoodBackupTime'}) > ($daysOld * 3600 * 24))
{
push @tooOld, $host;
}
elsif (difftime(time(), $Status{$host}{'lastGoodBackupTime'}) > ($warnLevel * 3600 * 24))
{
push @notTooOld, $host;
}
else
{
push @goodHost, $host;
pop @badHost;
}
# Debug
if ($verbose == 2)
{
print "Host $host state " . $Status{$host}{'state'};
print " with error: " . $Status{$host}{'error'} . "\n";
}
}
else
{
push @goodHost, $host;
}
}

if ($hostCount == @goodHost or $#badHost < $reduce and not @tooOld)
{
print "BACKUPPC OK - (" . @badHost . "/" . $hostCount . ") failures\n";
exit $ERRORS{'OK'};
}

# Only failures reach this far
# WARNING
if ($#tooOld < 0 or $#badHost < $reduce)
{
print "BACKUPPC WARNING - (";
if ($verbose)
{
foreach my $host (@badHost)
{
print $host . " (" . $Status{$host}{'error'} . "), ";
}
print ")\n";
}
else
{
print $#badHost + 1 . "/" . $hostCount . ") failures\n";
}
exit $ERRORS{'WARNING'};
}

# CRITICAL
print "BACKUPPC CRITICAL - (";
if ($#notTooOld >= 0 and $verbose)
{
foreach my $host (@notTooOld)
{
print $host . " (" . $Status{$host}{'error'} . "), ";
}
print "), (";
}
if ($verbose)
{
foreach my $host (@tooOld)
{
print $host . " (" . $Status{$host}{'error'} . "), " if $verbose;
}
print ") critical\n";
}
else
{
print $#badHost + 1 . "/" . $hostCount . ") failures, ";
print $#tooOld + 1 . " critical\n";
}
exit $ERRORS{'CRITICAL'};
----------------------------------------------------------------

O Problema todo está em uma confusão da minha parte, eu não tenho a mínima idéia de como instalar e configurar este plugin e as documentações mais sólidas que eu encontrei sobre o assunto são justamente o INTALL E O README.
Não há nada na internet e enfim não estou conseguindo fazer funcionar :( essa ferramenta valiosa.

Gostaria de mais uma vez poder contar com a ajuda de vocês aqui do VOL, se alguém ja teve essa experiencia ou tem uma mente mais aberta que a minha e possa me ajudar ficarei muito Grato pela colaboração e creio que a comunidade também.

Grato !!!


  






Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts