Advertisement
Guest User

Untitled

a guest
Nov 15th, 2011
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.11 KB | None | 0 0
  1. <?php
  2.  
  3. class WeatherMapDataSource_rtg extends WeatherMapDataSource {
  4.  
  5. function Init(&$map)
  6. {
  7. if(! function_exists("mysql_real_escape_string") ) return FALSE;
  8. if(! function_exists("mysql_connect") ) return FALSE;
  9.  
  10. return(TRUE);
  11. }
  12.  
  13. function Recognise($targetstring)
  14. {
  15.  
  16. if(preg_match("/^rtg:([\-a-zA-Z0-9_]+):([\-a-zA-Z0-9_]+)$/",$targetstring,$matches))
  17.  
  18. {
  19. return TRUE;
  20. }
  21. else
  22. {
  23. return FALSE;
  24. }
  25. }
  26.  
  27. function ReadData($targetstring, &$map, &$item)
  28. {
  29. $data[IN] = NULL;
  30. $data[OUT] = NULL;
  31. $data_time = 0;
  32.  
  33. if(preg_match("/^rtg:([\-a-zA-Z0-9_]+):([\-a-zA-Z0-9_]+)$/",$targetstring,$matches))
  34. {
  35. $database_user = '(DB USER)';
  36. $database_pass = '(DB PASSWORD)';
  37. $database_name = '(DB)';
  38. $database_host = '(DB HOST)';
  39.  
  40. $rid = $matches[1];
  41. $iid= $matches[2];
  42.  
  43. $mysqldate = date( 'Y-m-d H:i:s', (strtotime("15 minutes ago")));
  44. //echo $mysqldate;
  45.  
  46. $SQL_IN = "select counter from ifInOctets_$rid where id=$iid and dtime >= '$mysqldate' order by dtime desc limit 1";
  47. $SQL_OUT = "select counter from ifOutOctets_$rid where id=$iid and dtime >= '$mysqldate' order by dtime desc limit 1";
  48.  
  49. if(mysql_connect($database_host,$database_user,$database_pass))
  50. {
  51. if(mysql_select_db($database_name))
  52. {
  53. $result_IN = mysql_query($SQL_IN);
  54. if (!$result_IN)
  55. {
  56. warn("RTG ReadData: Invalid query for IN Value: " . mysql_error()."\n");
  57. }
  58. else
  59. {
  60. $row_IN = mysql_fetch_assoc($result_IN);
  61. $data[IN] = $row_IN['counter'] / 8;
  62. }
  63. $result_OUT = mysql_query($SQL_OUT);
  64. if (!$result_OUT)
  65. {
  66. warn("RTG ReadData: Invalid query for OUT Value: " . mysql_error()."\n");
  67. }
  68. else
  69. {
  70. $row_OUT = mysql_fetch_assoc($result_OUT);
  71. $data[OUT] = $row_OUT['counter'] / 8;
  72. //$data_time = $row_OUT['dtime'];
  73. }
  74.  
  75.  
  76.  
  77. }
  78.  
  79. else
  80. {
  81. warn("RTG ReadData: failed to select database ($database_name): ".mysql_error()."\n");
  82. }
  83. }
  84. else
  85. {
  86. warn("RTG ReadData: failed to connect to database server: ".mysql_error()."\n");
  87. }
  88.  
  89. // $data_time = now();
  90. }
  91.  
  92.  
  93. debug ("RTG ReadData: Returning (".($data[IN]===NULL?'NULL':$data[IN]).",".($data[OUT]===NULL?'NULL':$data[IN]).",$data_time)\n");
  94.  
  95. return( array($data[IN], $data[OUT], $data_time) );
  96. }
  97. }
  98. ?>
  99.  
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement