Function to parse contacts from nagios config

#!/usr/bin/php
<?php
$contacts = file_get_contents("/etc/nagios4/objects/auto-contacts.cfg");


function parse_contacts($cfg)
{
        preg_match_all("/define contact{(.*?)}/mis", file_get_contents($cfg), $matches);
        foreach ($matches[1] as $match)
        {
                preg_match_all("/\s+(.+?)\s+(.+?)\n/mis", $match, $m);
                for ($i=0; $i&lt;count($m[1]); $i++)
                        $contact[$m[1][$i]] = $m[2][$i];
                $contacts[] = $contact;
        }
        return $contacts;
}


print_r(parse_contacts("/etc/nagios4/objects/contacts.cfg"));
Dette indlæg blev udgivet i Uncategorized. Bogmærk permalinket.