This is a PHP script that parse file content from a file and writes this to another config file.
#!/usr/bin/php -q
< ?php
if ($_SERVER['argv'][1] == '')
{
die("Usage: ./nagiosparse filename. Sourcefile must be a list with <interface>,<vlantag>\n");
}
$strFile = $_SERVER['argv'][1];
$arrContents = explode("\n", file_get_contents($strFile));
foreach ($arrContents as $strLine)
{
if(!empty($strLine))
{
$arrCells = explode(",", $strLine);
print("
define host{
use generic-host ; Name of host template to use
host_name $arrCells[0]
alias $arrCells[1]
address $arrCells[2]
check_command check-host-alive
max_check_attempts 10
notification_interval 0
notification_period 24x7
notification_options d,u,r
contact_groups switch-admins
}
");
}
}
?></vlantag></interface>