Merge remote-tracking branch 'upstream/master'
[torrus-plus.git] / src / lib / Torrus / DevDiscover / Jacarta.pm
blobafb626bb50038e07ae8bebc6d0b680decf68aac5
1 # Copyright (C) 2010 Roman Hochuli
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$
19 # Sensor-MIBs of Jacarta iMeter-Products
22 package Torrus::DevDiscover::Jacarta;
24 use strict;
25 use warnings;
27 use Torrus::Log;
29 our $VERSION = 1.0;
31 $Torrus::DevDiscover::registry{'Jacarta'} = {
32 'sequence' => 500,
33 'checkdevtype' => \&checkdevtype,
34 'discover' => \&discover,
35 'buildConfig' => \&buildConfig
39 our %oiddef =
41 'jacarta' => '1.3.6.1.4.1.19011',
42 'sensorEntry' => '1.3.6.1.4.1.19011.2.3.1.1',
43 'sensorIndex' => '1.3.6.1.4.1.19011.2.3.1.1.1',
44 'sensorDescription' => '1.3.6.1.4.1.19011.2.3.1.1.2',
45 'sensorType' => '1.3.6.1.4.1.19011.2.3.1.1.3',
46 'sensorValue' => '1.3.6.1.4.1.19011.2.3.1.1.4',
47 'sensorUnit' => '1.3.6.1.4.1.19011.2.3.1.1.5',
51 our %sensor_types =
53 2 => {
54 'template' => 'Jacarta::imeter-humi-sensor',
55 'max' => 'NetBotz::humi-max',
57 3 => {
58 'template' => 'Jacarta::imeter-temp-sensor',
59 'max' => 'NetBotz::dew-max',
61 5 => {
62 'template' => 'Jacarta::imeter-amps-sensor',
63 'max' => 'NetBotz::dew-max',
64 },
70 sub checkdevtype
72 my $dd = shift;
73 my $devdetails = shift;
75 if( not $dd->oidBaseMatch
76 ( 'jacarta',
77 $devdetails->snmpVar( $dd->oiddef('sysObjectID') ) ) )
79 return 0;
82 $devdetails->setCap('interfaceIndexingPersistent');
84 return 1;
88 sub discover
90 my $dd = shift;
91 my $devdetails = shift;
93 my $data = $devdetails->data();
94 my $session = $dd->session();
96 $data->{'Jacarta'} = {};
98 my $sensorTable =
99 $session->get_table( -baseoid => $oiddef{'sensorEntry'} );
101 if( not defined( $sensorTable ) )
103 return 1;
106 $devdetails->storeSnmpVars( $sensorTable );
108 # store the sensor names to guarantee uniqueness
109 my %sensorNames;
111 for my $INDEX
112 ($devdetails->getSnmpIndices( $oiddef{'sensorIndex'} ))
114 my $sensorType =
115 $devdetails->snmpVar( $oiddef{'sensorType'} . '.' .
116 $INDEX);
117 my $sensorName =
118 $devdetails->snmpVar( $oiddef{'sensorDescription'} . '.' .
119 $INDEX);
121 if( not defined( $sensor_types{$sensorType} ) )
123 Error('Sensor ' . $INDEX . ' of unknown type: ' . $sensorType);
124 next;
127 if( $sensorNames{$sensorName} )
129 Warn('Duplicate sensor names: ' . $sensorName);
130 $sensorNames{$sensorName}++;
132 else
134 $sensorNames{$sensorName} = 1;
137 if( $sensorNames{$sensorName} > 1 )
139 $sensorName .= sprintf(' %d', $INDEX);
142 my $leafName = $sensorName;
143 $leafName =~ s/\W/_/g;
145 my $param = {
146 'imeter-sensor-index' => $INDEX,
147 'node-display-name' => $sensorName,
148 'graph-title' => $sensorName,
149 'precedence' => sprintf('%d', 1000 - $INDEX)
153 if( defined( $sensor_types{$sensorType}{'max'} ) )
155 my $max =
156 $devdetails->param($sensor_types{$sensorType}{'max'});
158 if( defined($max) and $max > 0 )
160 $param->{'upper-limit'} = $max;
164 $data->{'Jacarta'}{$INDEX} = {
165 'param' => $param,
166 'leafName' => $leafName,
167 'template' => $sensor_types{$sensorType}{'template'}};
169 Debug('Found Sensor ' . $INDEX . ' of type ' . $sensorType .
170 ', named ' . $sensorName );
173 return 1;
177 sub buildConfig
179 my $devdetails = shift;
180 my $cb = shift;
181 my $devNode = shift;
183 my $data = $devdetails->data();
185 my $param = {
186 'node-display-name' => 'Sensors',
187 'comment' => 'All sensors connected via this iMeter Master',
190 my $sensorTree =
191 $cb->addSubtree( $devNode, 'Sensors', $param );
193 for my $INDEX ( sort {$a<=>$b} keys %{$data->{'Jacarta'}} )
195 my $ref = $data->{'Jacarta'}{$INDEX};
197 $cb->addLeaf( $sensorTree, $ref->{'leafName'}, $ref->{'param'},
198 [$ref->{'template'}] );
201 return;
209 # Local Variables:
210 # mode: perl
211 # indent-tabs-mode: nil
212 # perl-indent-level: 4
213 # End: