jablonka.czprosek.czf

weathermap

Subversion Repositories:
[/] [lib/] [datasources/] [WeatherMapDataSource_cactihost.php] - Blame information for rev 18

 

Line No. Rev Author Line
11simandl<?php
2 
3class WeatherMapDataSource_cactihost extends WeatherMapDataSource {
4 
5 function Init(&$map)
6 {
7 if($map->context == 'cacti')
8 {
9 if( function_exists('db_fetch_row') )
10 {
11 return(TRUE);
12 }
13 else
14 {
15 debug('ReadData CactiHost: Cacti database library not found.\n');
16 }
17 }
18 else
19 {
20 debug("ReadData CactiHost: Can only run from Cacti environment.\n");
21 }
22 
23 return(FALSE);
24 }
25 
26 function Recognise($targetstring)
27 {
28 if(preg_match("/^cactihost:(\d+)$/",$targetstring,$matches))
29 {
30 return TRUE;
31 }
32 else
33 {
34 return FALSE;
35 }
36 }
37 
38 function ReadData($targetstring, &$map, &$item)
39 {
40 
41 $inbw = -1;
42 $outbw = -1;
43 $data_time = 0;
44 
45 if(preg_match("/^cactihost:(\d+)$/",$targetstring,$matches))
46 {
47 $cacti_id = intval($matches[1]);
48 
49 $SQL = "select status, disabled from host where id=$cacti_id";
50 // 0=disabled
51 // 1=down
52 // 2=recovering
53 // 3=up
54 
55 $state = -1;
56 $result = db_fetch_row($SQL);
57 if(isset($result))
58 {
59 // create a note, which can be used in icon filenames or labels more nicely
60 if($result['status'] == 1) { $state = 1; $statename = 'down'; }
61 if($result['status'] == 2) { $state = 2; $statename = 'recovering'; }
62 if($result['status'] == 3) { $state = 3; $statename = 'up'; }
63 if($result['disabled']) { $state = 0; $statename = 'disabled'; }
64 
65 $inbw = $state;
66 $outbw = $state;
67 $item->add_note("state",$statename);
68 }
69 }
70 
71 debug ("CactiHost ReadData: Returning ($inbw,$outbw,$data_time)\n");
72 
73 return( array($inbw, $outbw, $data_time) );
74 }
75}
76 
77 
78// vim:ts=4:sw=4:
79?>

Powered by WebSVN 2.2.1