1 | 1 | simandl | <?php |
2 | | | |
3 | | | class 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 | 85 | simandl | function ReadData($targetstring, &$map, &$item) |
39 | 1 | simandl | { |
40 | | | |
41 | 85 | simandl | $data[IN] = NULL; |
42 | | | $data[OUT] = NULL; |
43 | 1 | simandl | $data_time = 0; |
44 | | | |
45 | | | if(preg_match("/^cactihost:(\d+)$/",$targetstring,$matches)) |
46 | | | { |
47 | | | $cacti_id = intval($matches[1]); |
48 | | | |
49 | 85 | simandl | $SQL = "select * from host where id=$cacti_id"; |
50 | 1 | simandl | // 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 | 85 | simandl | $data[IN] = $state; |
66 | | | $data[OUT] = $state; |
67 | 1 | simandl | $item->add_note("state",$statename); |
68 | 85 | simandl | $item->add_note("cacti_description",$result['description']); |
69 | | | |
70 | | | $item->add_note("cacti_hostname",$result['hostname']); |
71 | | | $item->add_note("cacti_curtime",$result['cur_time']); |
72 | | | $item->add_note("cacti_avgtime",$result['avg_time']); |
73 | | | $item->add_note("cacti_mintime",$result['min_time']); |
74 | | | $item->add_note("cacti_maxtime",$result['max_time']); |
75 | | | $item->add_note("cacti_availability",$result['availability']); |
76 | | | |
77 | | | $item->add_note("cacti_faildate",$result['status_fail_date']); |
78 | | | $item->add_note("cacti_recdate",$result['status_rec_date']); |
79 | 1 | simandl | } |
80 | | | } |
81 | | | |
82 | 85 | simandl | debug ("CactiHost ReadData: Returning (".($data[IN]===NULL?'NULL':$data[IN]).",".($data[OUT]===NULL?'NULL':$data[OUT]).",$data_time)\n"); |
83 | 1 | simandl | |
84 | 85 | simandl | return( array($data[IN], $data[OUT], $data_time) ); |
85 | 1 | simandl | } |
86 | | | } |
87 | | | |
88 | | | |
89 | | | // vim:ts=4:sw=4: |
90 | | | ?> |