1 | 1 | simandl | <?php |
2 | | | // Pluggable datasource for PHP Weathermap 0.9 |
3 | | | // - return a live SNMP value |
4 | | | |
5 | | | // doesn't work well with large values like interface counters (I think this is a rounding problem) |
6 | | | // - also it doesn't calculate rates. Just fetches a value. |
7 | | | |
8 | | | // useful for absolute GAUGE-style values like DHCP Lease Counts, Wireless AP Associations, Firewall Sessions |
9 | | | // which you want to use to colour a NODE |
10 | | | |
11 | | | // You could also fetch interface states from IF-MIB with it. |
12 | | | |
13 | | | // TARGET snmp:public:hostname:1.3.6.1.4.1.3711.1.1:1.3.6.1.4.1.3711.1.2 |
14 | | | // (that is, TARGET snmp:community:host:in_oid:out_oid |
15 | | | |
16 | | | class WeatherMapDataSource_snmp extends WeatherMapDataSource { |
17 | | | |
18 | | | function Init(&$map) |
19 | | | { |
20 | | | if(function_exists('snmpget')) { return(TRUE); } |
21 | | | debug("SNMP DS: snmpget() not found. Do you have the PHP SNMP module?\n"); |
22 | | | |
23 | | | return(FALSE); |
24 | | | } |
25 | | | |
26 | | | |
27 | | | function Recognise($targetstring) |
28 | | | { |
29 | | | if(preg_match("/^snmp:([^:]+):([^:]+):([^:]+):([^:]+)$/",$targetstring,$matches)) |
30 | | | { |
31 | | | return TRUE; |
32 | | | } |
33 | | | else |
34 | | | { |
35 | | | return FALSE; |
36 | | | } |
37 | | | } |
38 | | | |
39 | | | function ReadData($targetstring, &$map, &$item) |
40 | | | { |
41 | | | $inbw=-1; |
42 | | | $outbw=-1; |
43 | | | $data_time=0; |
44 | | | |
45 | | | if(preg_match("/^snmp:([^:]+):([^:]+):([^:]+):([^:]+)$/",$targetstring,$matches)) |
46 | | | { |
47 | | | $community = $matches[1]; |
48 | | | $host = $matches[2]; |
49 | | | $in_oid = $matches[3]; |
50 | | | $out_oid = $matches[4]; |
51 | | | |
52 | | | $was = snmp_get_quick_print(); |
53 | | | snmp_set_quick_print(1); |
54 | | | |
55 | | | $in_result = snmpget($host,$community,$in_oid,1000000,2); |
56 | | | $out_result = snmpget($host,$community,$out_oid,1000000,2); |
57 | | | |
58 | | | debug ("SNMP ReadData: Got $in_result and $out_result\n"); |
59 | | | |
60 | | | if($in_result) { $in_bw = $in_result; } |
61 | | | if($out_result) { $out_bw = $out_result;} |
62 | | | $data_time = time(); |
63 | | | snmp_set_quick_print($was); |
64 | | | } |
65 | | | |
66 | | | debug ("SNMP ReadData: Returning ($inbw,$outbw,$data_time)\n"); |
67 | | | |
68 | | | return ( array($inbw,$outbw,$data_time) ); |
69 | | | } |
70 | | | } |
71 | | | |
72 | | | // vim:ts=4:sw=4: |
73 | | | ?> |