Jacarta.pm: 'Switch' imported and not used, this module is also deprecated.
[torrus-plus.git] / src / perllib / Torrus / DevDiscover / Jacarta.pm
blobc4310a2d33b0d86e688e0a024896fe08b760edee
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 Torrus::Log;
26 use Data::Dumper;
28 our $VERSION = 1.0;
30 $Torrus::DevDiscover::registry{'Jacarta'} = {
31 'sequence' => 500,
32 'checkdevtype' => \&checkdevtype,
33 'discover' => \&discover,
34 'buildConfig' => \&buildConfig
38 our %oiddef =
40 'jacarta' => '1.3.6.1.4.1.19011',
41 'sensorEntry' => '1.3.6.1.4.1.19011.2.3.1.1',
42 'sensorIndex' => '1.3.6.1.4.1.19011.2.3.1.1.1',
43 'sensorDescription' => '1.3.6.1.4.1.19011.2.3.1.1.2',
44 'sensorType' => '1.3.6.1.4.1.19011.2.3.1.1.3',
45 'sensorValue' => '1.3.6.1.4.1.19011.2.3.1.1.4',
46 'sensorUnit' => '1.3.6.1.4.1.19011.2.3.1.1.5',
50 our %sensor_types =
52 2 => {
53 'template' => 'Jacarta::imeter-humi-sensor',
54 'max' => 'NetBotz::humi-max',
56 3 => {
57 'template' => 'Jacarta::imeter-temp-sensor',
58 'max' => 'NetBotz::dew-max',
60 5 => {
61 'template' => 'Jacarta::imeter-amps-sensor',
62 'max' => 'NetBotz::dew-max',
63 },
69 sub checkdevtype
71 my $dd = shift;
72 my $devdetails = shift;
74 if( not $dd->oidBaseMatch
75 ( 'jacarta',
76 $devdetails->snmpVar( $dd->oiddef('sysObjectID') ) ) )
78 return 0;
81 $devdetails->setCap('interfaceIndexingPersistent');
83 return 1;
87 sub discover
89 my $dd = shift;
90 my $devdetails = shift;
92 my $data = $devdetails->data();
93 my $session = $dd->session();
95 $data->{'Jacarta'} = {};
97 my $sensorTable =
98 $session->get_table( -baseoid => $oiddef{'sensorEntry'} );
100 if( not defined( $sensorTable ) )
102 return 1;
105 $devdetails->storeSnmpVars( $sensorTable );
107 # store the sensor names to guarantee uniqueness
108 my %sensorNames;
110 for my $INDEX
111 ($devdetails->getSnmpIndices( $oiddef{'sensorIndex'} ))
113 my $sensorType =
114 $devdetails->snmpVar( $oiddef{'sensorType'} . '.' .
115 $INDEX);
116 my $sensorName =
117 $devdetails->snmpVar( $oiddef{'sensorDescription'} . '.' .
118 $INDEX);
120 if( not defined( $sensor_types{$sensorType} ) )
122 Error('Sensor ' . $INDEX . ' of unknown type: ' . $sensorType);
123 next;
126 if( $sensorNames{$sensorName} )
128 Warn('Duplicate sensor names: ' . $sensorName);
129 $sensorNames{$sensorName}++;
131 else
133 $sensorNames{$sensorName} = 1;
136 if( $sensorNames{$sensorName} > 1 )
138 $sensorName .= sprintf(' %d', $INDEX);
141 my $leafName = $sensorName;
142 $leafName =~ s/\W/_/g;
144 my $param = {
145 'imeter-sensor-index' => $INDEX,
146 'node-display-name' => $sensorName,
147 'graph-title' => $sensorName,
148 'precedence' => sprintf('%d', 1000 - $INDEX)
152 if( defined( $sensor_types{$sensorType}{'max'} ) )
154 my $max =
155 $devdetails->param($sensor_types{$sensorType}{'max'});
157 if( defined($max) and $max > 0 )
159 $param->{'upper-limit'} = $max;
163 $data->{'Jacarta'}{$INDEX} = {
164 'param' => $param,
165 'leafName' => $leafName,
166 'template' => $sensor_types{$sensorType}{'template'}};
168 Debug('Found Sensor ' . $INDEX . ' of type ' . $sensorType .
169 ', named ' . $sensorName );
172 return 1;
176 sub buildConfig
178 my $devdetails = shift;
179 my $cb = shift;
180 my $devNode = shift;
182 my $data = $devdetails->data();
184 my $param = {
185 'node-display-name' => 'Sensors',
186 'comment' => 'All sensors connected via this iMeter Master',
189 my $sensorTree =
190 $cb->addSubtree( $devNode, 'Sensors', $param );
192 for my $INDEX ( sort {$a<=>$b} keys %{$data->{'Jacarta'}} )
194 my $ref = $data->{'Jacarta'}{$INDEX};
196 $cb->addLeaf( $sensorTree, $ref->{'leafName'}, $ref->{'param'},
197 [$ref->{'template'}] );
206 # Local Variables:
207 # mode: perl
208 # indent-tabs-mode: nil
209 # perl-indent-level: 4
210 # End: