Blog |Follow Nick on Twitter| About
 

Recently I had a request from rex to modify my nagios ping tool (Official Nagios Exchange page); he wanted to use the tool with his nagios configuration.

Rex appeared to be using Nagios QL (Which I believe to be a nagios management tool) , now QL handles nagios config slightly differently . The Ping Tool reads the nagios hosts.cfg file, and turns it into a couple of arrays to use for ping & display, with QL they generate multiple hosts.cfg files, one for each hosts.

Perhaps a short way of saying it, Rex needed to read in multiple hosts.cfg files from a directory, and below is the hack to do it :)

Simply copy & past the below code into a file called readhosts.php, replace your readhosts.php with the new one , and set the variable \$hostfilepath in config.php, something like \$hostfilepath = "/hosts"; (assuming /hosts is where you keep the files ;-) ) should do the job.

Please update your config file

You need to add the line $hostfilepath = "/path/to/host/config/files"; to config.php

"; } } closedir($dh); } } function make_host_array() { global $lines,$ipaddress,$node_name,$counter,$counter2; foreach ($lines as $line_num => $line) { $current = trim($line); if (preg_match ("/addres/", "$current")) { $keywords = preg_split ("/[\s,]+/", "$current"); $ipaddress[$counter] = $keywords[1]; $counter++; } if (preg_match ("/host_name/", "$current")) { $keywords = preg_split ("/[\s,]+/", "$current"); $node_name[$counter2] = $keywords[1]; $counter2++; } } #print_r($ipaddress); #print_r($node_name); } ?>

rgds,

Nick

 
Nick Bettison ©