jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [lib/] [datasources/] [WeatherMapDataSource_mrtg.php] - Blame information for rev 4

 

Line No. Rev Author Line
11simandl<?php
2// Sample Pluggable datasource for PHP Weathermap 0.9
3// - read a pair of values from a database, and return it
4 
5// TARGET dbplug:databasename:username:pass:hostkey
6 
7class WeatherMapDataSource_mrtg extends WeatherMapDataSource {
8 
9 function Recognise($targetstring)
10 {
11 if(preg_match("/\.(htm|html)$/",$targetstring,$matches))
12 {
13 return TRUE;
14 }
15 else
16 {
17 return FALSE;
18 }
19 }
20 
21 function ReadData($targetstring, &$map, &$item)
22 {
23 $inbw=-1;
24 $outbw=-1;
25 $data_time = 0;
26 
27 $matches=0;
28 
29 $fd=fopen($targetstring, "r");
30 
31 if ($fd)
32 {
33 while (!feof($fd))
34 {
35 $buffer=fgets($fd, 4096);
36 
37 if (preg_match("/<\!-- cuin d (\d+) -->/", $buffer, $matches)) { $inbw=$matches[1] * 8; }
38 
39 if (preg_match("/<\!-- cuout d (\d+) -->/", $buffer, $matches)) { $outbw=$matches[1] * 8; }
40 }
41 fclose($fd);
424simandl# $data_time = filemtime($targetstring);
43 $data_time = 0;
441simandl }
45 else {
46 // some error code to go in here
47 debug ("MRTG ReadData: Couldn't open ($targetstring). \n"); }
48 
49 debug ("MRTG ReadData: Returning ($inbw,$outbw,$data_time)\n");
50 
51 return ( array($inbw,$outbw,$data_time) );
52 }
53}
54 
55// vim:ts=4:sw=4:
56?>

Powered by WebSVN 2.2.1