1 # Copyright (C) 2009 Stanislav Sinyagin
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 # $Id: NetBotz.pm,v 1.1 2010-12-27 00:03:47 ivan Exp $
19 # NetBotz modular sensors
21 package Torrus::DevDiscover::NetBotz;
27 $Torrus::DevDiscover::registry{'NetBotz'} = {
29 'checkdevtype' => \&checkdevtype,
30 'discover' => \&discover,
31 'buildConfig' => \&buildConfig
37 'netBotzV2Products' => '1.3.6.1.4.1.5528.100.20',
43 'oid' => '1.3.6.1.4.1.5528.100.4.1.1.1',
44 'template' => 'NetBotz::netbotz-temp-sensor',
45 'max' => 'NetBotz::temp-max',
48 'oid' => '1.3.6.1.4.1.5528.100.4.1.2.1',
49 'template' => 'NetBotz::netbotz-humi-sensor',
50 'max' => 'NetBotz::humi-max',
53 'oid' => '1.3.6.1.4.1.5528.100.4.1.3.1',
54 'template' => 'NetBotz::netbotz-dew-sensor',
55 'max' => 'NetBotz::dew-max',
58 'oid' => '1.3.6.1.4.1.5528.100.4.1.4.1',
59 'template' => 'NetBotz::netbotz-audio-sensor'
62 'oid' => '1.3.6.1.4.1.5528.100.4.1.5.1',
63 'template' => 'NetBotz::netbotz-air-sensor'
66 'oid' => '1.3.6.1.4.1.5528.100.4.2.2.1',
67 'template' => 'NetBotz::netbotz-door-sensor'
76 my $devdetails = shift;
78 if( not $dd->oidBaseMatch
79 ( 'netBotzV2Products',
80 $devdetails->snmpVar( $dd->oiddef('sysObjectID') ) ) )
85 $devdetails->setCap('interfaceIndexingPersistent');
94 my $devdetails = shift;
96 my $data = $devdetails->data();
97 my $session = $dd->session();
99 foreach my $stype (sort keys %sensor_types)
101 my $oid = $sensor_types{$stype}{'oid'};
103 my $sensorTable = $session->get_table( -baseoid => $oid );
105 if( defined( $sensorTable ) )
107 $devdetails->storeSnmpVars( $sensorTable );
109 # store the sensor names to guarantee uniqueness
112 foreach my $INDEX ($devdetails->getSnmpIndices($oid . '.1'))
114 my $label = $devdetails->snmpVar( $oid . '.4.' . $INDEX );
116 if( $sensorNames{$label} )
118 Warn('Duplicate sensor names: ' . $label);
119 $sensorNames{$label}++;
123 $sensorNames{$label} = 1;
126 if( $sensorNames{$label} > 1 )
128 $label .= sprintf(' %d', $sensorNames{$label});
131 my $leafName = $label;
132 $leafName =~ s/\W/_/g;
135 'netbotz-sensor-index' => $INDEX,
136 'node-display-name' => $label,
137 'graph-title' => $label,
138 'precedence' => sprintf('%d', 1000 - $INDEX)
141 if( defined( $sensor_types{$stype}{'max'} ) )
144 $devdetails->param($sensor_types{$stype}{'max'});
146 if( defined($max) and $max > 0 )
148 $param->{'upper-limit'} = $max;
153 $data->{'NetBotz'}{$INDEX} = {
155 'leafName' => $leafName,
156 'template' => $sensor_types{$stype}{'template'}};
161 if( not defined($data->{'param'}{'comment'}) or
162 length($data->{'param'}{'comment'}) == 0 )
164 $data->{'param'}{'comment'} = 'NetBotz environment sensors';
173 my $devdetails = shift;
177 my $data = $devdetails->data();
179 foreach my $INDEX ( sort {$a<=>$b} keys %{$data->{'NetBotz'}} )
181 my $ref = $data->{'NetBotz'}{$INDEX};
183 $cb->addLeaf( $devNode, $ref->{'leafName'}, $ref->{'param'},
184 [$ref->{'template'}] );
195 # indent-tabs-mode: nil
196 # perl-indent-level: 4