cpliakas / nagiostatus

PHP parser library for the Nagios status.dat file.
GNU General Public License v2.0
1 stars 0 forks source link

Nagios Status Parser

Converting Status To Machine Readable Formats


// Registers the autoloader.
require_once '../library/Nagiostatus/Loader.php';
Nagiostatus_Loader::register();

// Render the status.dat file as XML.
$parser = new Nagiostatus_Parser('/usr/local/nagios/var/status.dat');
$xml = $parser->render('xml', true);

// Output XML directly.
// $parser->render('xml');

// Output JSON directly.
// $parser->render('json');

Working With XML


$document = new SimpleXMLElement($xml);

// Find all hoststatus reports.
$results = $document->xpath('//status[@type="hoststatus"]/report');

// Find all CPU Status reports.
$results = $document->xpath('///report[service_description="CPU Stats"]');
foreach ($results as $result) {
    $data = $result->plugin_output;
}