weathermap |
Subversion Repositories: |
Compare with Previous - Blame - Download
<?php
// Sample Pluggable datasource for PHP Weathermap 0.9
// - read a pair of values from a database, and return it
// TARGET dbplug:databasename:username:pass:hostkey
class WeatherMapDataSource_mrtg extends WeatherMapDataSource {
function Recognise($targetstring)
{
if(preg_match("/\.(htm|html)$/",$targetstring,$matches))
{
return TRUE;
}
else
{
return FALSE;
}
}
function ReadData($targetstring, &$map, &$item)
{
$inbw=-1;
$outbw=-1;
$data_time = 0;
$matches=0;
// $fd=fopen($targetstring, "r");
$timeout = 2;
$old = ini_set('default_socket_timeout', $timeout);
$fd = fopen($targetstring, 'r');
ini_set('default_socket_timeout', $old);
stream_set_timeout($fd, $timeout);
stream_set_blocking($fd, 0);
if ($fd)
{
while (!feof($fd))
{
$buffer=fgets($fd, 4096);
if (preg_match("/<\!-- cuin d (\d+) -->/", $buffer, $matches)) { $inbw=$matches[1] * 8; }
if (preg_match("/<\!-- cuout d (\d+) -->/", $buffer, $matches)) { $outbw=$matches[1] * 8; }
}
fclose($fd);
# $data_time = filemtime($targetstring);
}
else {
// some error code to go in here
debug ("MRTG ReadData: Couldn't open ($targetstring). \n"); }
debug ("MRTG ReadData: Returning ($inbw,$outbw,$data_time)\n");
return ( array($inbw,$outbw,$data_time) );
}
}
// vim:ts=4:sw=4:
?>