[Date Prev]   [Date Next] [Thread Prev]   [Thread Next] [Date Index]   [Thread Index]

 

     [snips-users] PHP Code to Read SNIPS Data Files

If you ever wanted to read events directly from SNIPS data files with native
PHP code here is what you would use to do it.  I'm sure my code could stand
some improvements, I certainly welcome them if anyone has any.

#!/usr/local/bin/php -f
<?

if (! $file_handle = fopen("./data/ippingmon-output", "r")) die ("DIE: Could
not open file.\n");

$header = string_unpack($file_handle, "a*", 372);

while (!feof($file_handle)) {

        ++$current_event;

        $event[$current_event]['sender'] = string_unpack($file_handle, "a*",
16);
        if (!$event[$current_event]['sender']) {
unset($event[$current_event]); continue; }

        $event[$current_event]['device_name'] = string_unpack($file_handle,
"a*", 64);
        $event[$current_event]['device_addr'] = string_unpack($file_handle,
"a*", 128);
        $event[$current_event]['device_subaddr'] =
string_unpack($file_handle, "a*", 64);

        $event[$current_event]['var'] = string_unpack($file_handle, "a*",
64);
        $event[$current_event]['value'] = string_unpack($file_handle, "L",
4);
        $event[$current_event]['threshold'] = string_unpack($file_handle,
"L", 4);
        $event[$current_event]['var_units'] = string_unpack($file_handle,
"a*", 8);

        $event[$current_event]['severity'] = ord(fread($file_handle, 1));
        $event[$current_event]['loglevel'] = ord(fread($file_handle, 1));
        $event[$current_event]['state'] = ord(fread($file_handle, 1));
        $event[$current_event]['rating'] = ord(fread($file_handle, 1));

        $event[$current_event]['eventtime'] = string_unpack($file_handle,
"L", 4);
        $event[$current_event]['polltime'] = string_unpack($file_handle,
"L", 4);

        $event[$current_event]['op'] = string_unpack($file_handle, "L", 4);
        $event[$current_event]['id'] = string_unpack($file_handle, "L", 4);
}

var_dump($event);

function string_unpack ($file_handle, $method, $length) { return implode("",
unpack($method, fread($file_handle, $length))); }

?>



Jerry Wilborn, Network Operations Analyst
FASTNET - Internet Solutions
610-266-6700
www.fast.net





Zyrion Traverse Network Monitoring & Network Management Software