Nagios / Incinga plugin for BackupPC

This plugin scrapes the BackupPC web-interface and uses it to fire off an alert if one or more jobs needs attention.

<?php
$hostname="http://localhost/backuppc/index.cgi";

$username="username"; $password="password";
$ignore = array("foobar.dk");
$auth = base64_encode("$username:$password");
$context = stream_context_create([ "http" => [ "header" => "Authorization: Basic $auth" ]]);
$homepage = file_get_contents($hostname, false, $context );

preg_match("/Failures that need attention.+<\/table/sim", $homepage, $matches);
preg_match_all("/<tr\>(.+?)<\/tr\>/sim", $matches[0], $m);

$failures = array();

foreach ($m[0] as $_)
{
        preg_match("/<a href=.+?>(.+?)</", $_, $m2);

        if (!in_array($m2[1], $ignore))
              $failures[] = $m2[1];
}

if (count($failures) == 0)
{
        print "OK: Alles ist gut\n";
        die(0);
}
else
{
        print "CRITICAL: ".count($failures)." errors: ".implode(", ", $failures)."\n";
        die(2);
}
?>
Dette indlæg blev udgivet i Nagios. Bogmærk permalinket.