jablonka.czprosek.czf

weathermap

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

 

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 
3885simandl function ReadData($targetstring, &$map, &$item)
391simandl {
40 
4185simandl $data[IN] = NULL;
42 $data[OUT] = NULL;
431simandl $data_time = 0;
44 
45 if(preg_match("/^cactihost:(\d+)$/",$targetstring,$matches))
46 {
47 $cacti_id = intval($matches[1]);
48 
4985simandl $SQL = "select * from host where id=$cacti_id";
501simandl // 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 
6585simandl $data[IN] = $state;
66 $data[OUT] = $state;
671simandl $item->add_note("state",$statename);
6885simandl $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']);
791simandl }
80 }
81 
8285simandl debug ("CactiHost ReadData: Returning (".($data[IN]===NULL?'NULL':$data[IN]).",".($data[OUT]===NULL?'NULL':$data[OUT]).",$data_time)\n");
831simandl 
8485simandl return( array($data[IN], $data[OUT], $data_time) );
851simandl }
86}
87 
88 
89// vim:ts=4:sw=4:
90?>

Powered by WebSVN 2.2.1