Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class WeatherMapDataSource_rtg extends WeatherMapDataSource {
- function Init(&$map)
- {
- if(! function_exists("mysql_real_escape_string") ) return FALSE;
- if(! function_exists("mysql_connect") ) return FALSE;
- return(TRUE);
- }
- function Recognise($targetstring)
- {
- if(preg_match("/^rtg:([\-a-zA-Z0-9_]+):([\-a-zA-Z0-9_]+)$/",$targetstring,$matches))
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- function ReadData($targetstring, &$map, &$item)
- {
- $data[IN] = NULL;
- $data[OUT] = NULL;
- $data_time = 0;
- if(preg_match("/^rtg:([\-a-zA-Z0-9_]+):([\-a-zA-Z0-9_]+)$/",$targetstring,$matches))
- {
- $database_user = '(DB USER)';
- $database_pass = '(DB PASSWORD)';
- $database_name = '(DB)';
- $database_host = '(DB HOST)';
- $rid = $matches[1];
- $iid= $matches[2];
- $mysqldate = date( 'Y-m-d H:i:s', (strtotime("15 minutes ago")));
- //echo $mysqldate;
- $SQL_IN = "select counter from ifInOctets_$rid where id=$iid and dtime >= '$mysqldate' order by dtime desc limit 1";
- $SQL_OUT = "select counter from ifOutOctets_$rid where id=$iid and dtime >= '$mysqldate' order by dtime desc limit 1";
- if(mysql_connect($database_host,$database_user,$database_pass))
- {
- if(mysql_select_db($database_name))
- {
- $result_IN = mysql_query($SQL_IN);
- if (!$result_IN)
- {
- warn("RTG ReadData: Invalid query for IN Value: " . mysql_error()."\n");
- }
- else
- {
- $row_IN = mysql_fetch_assoc($result_IN);
- $data[IN] = $row_IN['counter'] / 8;
- }
- $result_OUT = mysql_query($SQL_OUT);
- if (!$result_OUT)
- {
- warn("RTG ReadData: Invalid query for OUT Value: " . mysql_error()."\n");
- }
- else
- {
- $row_OUT = mysql_fetch_assoc($result_OUT);
- $data[OUT] = $row_OUT['counter'] / 8;
- //$data_time = $row_OUT['dtime'];
- }
- }
- else
- {
- warn("RTG ReadData: failed to select database ($database_name): ".mysql_error()."\n");
- }
- }
- else
- {
- warn("RTG ReadData: failed to connect to database server: ".mysql_error()."\n");
- }
- // $data_time = now();
- }
- debug ("RTG ReadData: Returning (".($data[IN]===NULL?'NULL':$data[IN]).",".($data[OUT]===NULL?'NULL':$data[IN]).",$data_time)\n");
- return( array($data[IN], $data[OUT], $data_time) );
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement