jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [lib/] [datasources/] [WeatherMapDataSource_mrtg.php] - Diff between revs 83 and 85

Show entire file Ignore whitespace

Rev 83 Rev 85
Line 18... Line 18...
} }
} }
   
function ReadData($targetstring, &$map, &$item) function ReadData($targetstring, &$map, &$item)
{ {
$inbw=-1; $data[IN] = NULL;
$outbw=-1; $data[OUT] = NULL;
$data_time = 0; $data_time = 0;
   
$matches=0; $matchvalue= $item->get_hint('mrtg_value');
  $matchperiod = $item->get_hint('mrtg_period');
// $fd=fopen($targetstring, "r"); $swap = intval($item->get_hint('mrtg_swap'));
$timeout = 2; $negate = intval($item->get_hint('mrtg_negate'));
$old = ini_set('default_socket_timeout', $timeout);  
$fd = fopen($targetstring, 'r'); if($matchvalue =='') $matchvalue = "cu";
ini_set('default_socket_timeout', $old); if($matchperiod =='') $matchperiod = "d";
stream_set_timeout($fd, $timeout);  
stream_set_blocking($fd, 0); $fd=fopen($targetstring, "r");
   
   
   
   
if ($fd) if ($fd)
{ {
while (!feof($fd)) while (!feof($fd))
{ {
$buffer=fgets($fd, 4096); $buffer=fgets($fd, 4096);
  debug("MRTG ReadData: Matching on '${matchvalue}in $matchperiod' and '${matchvalue}out $matchperiod'\n");
   
if (preg_match("/<\!-- cuin d (\d+) -->/", $buffer, $matches)) { $inbw=$matches[1] * 8; } if (preg_match("/<\!-- ${matchvalue}in $matchperiod ([-+]?\d+\.?\d*) -->/", $buffer, $matches)) { $data[IN] = $matches[1] * 8; }
  if (preg_match("/<\!-- ${matchvalue}out $matchperiod ([-+]?\d+\.?\d*) -->/", $buffer, $matches)) { $data[OUT] = $matches[1] * 8; }
if (preg_match("/<\!-- cuout d (\d+) -->/", $buffer, $matches)) { $outbw=$matches[1] * 8; }  
} }
fclose($fd); fclose($fd);
# $data_time = filemtime($targetstring); # don't bother with the modified time if the target is a URL
  if(! preg_match('/^[a-z]+:\/\//',$targetstring) )
  {
  $data_time = filemtime($targetstring);
  }
} }
else { else
  {
// some error code to go in here // some error code to go in here
debug ("MRTG ReadData: Couldn't open ($targetstring). \n"); } debug ("MRTG ReadData: Couldn't open ($targetstring). \n");
  }
debug ("MRTG ReadData: Returning ($inbw,$outbw,$data_time)\n");  
  if($swap==1)
  {
  debug("MRTG ReadData: Swapping IN and OUT\n");
  $t = $data[OUT];
  $data[OUT] = $data[IN];
  $data[IN] = $t;
  }
   
  if($negate)
  {
  debug("MRTG ReadData: Negating values\n");
  $data[OUT] = -$data[OUT];
  $data[IN] = -$data[IN];
  }
   
  debug ("MRTG ReadData: Returning (".($data[IN]===NULL?'NULL':$data[IN]).",".($data[OUT]===NULL?'NULL':$data[OUT]).",$data_time)\n");
   
return ( array($inbw,$outbw,$data_time) ); return( array($data[IN], $data[OUT], $data_time) );
} }
} }
   
// vim:ts=4:sw=4: // vim:ts=4:sw=4:
?> ?>

Powered by WebSVN 2.2.1