import torrus 1.0.9
[freeside.git] / torrus / perllib / Torrus / DevDiscover / CompaqCIM.pm
1 #  Copyright (C) 2003  Shawn Ferry
2 #
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.
7 #
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.
12 #
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16
17 # $Id: CompaqCIM.pm,v 1.1 2010-12-27 00:03:47 ivan Exp $
18 # Shawn Ferry <sferry at sevenspace dot com> <lalartu at obscure dot org>
19
20 # Compaq Insight Manager
21 # MIB files available at
22 # http://h18023.www1.hp.com/support/files/server/us/download/19885.html
23
24 package Torrus::DevDiscover::CompaqCIM;
25
26 use strict;
27 use Torrus::Log;
28
29
30 $Torrus::DevDiscover::registry{'CompaqCIM'} = {
31     'sequence'     => 500,
32     'checkdevtype' => \&checkdevtype,
33     'discover'     => \&discover,
34     'buildConfig'  => \&buildConfig
35     };
36
37 our %oiddef =
38     (
39      # Compaq Insite Manager
40      'cpqcim'                           => '1.3.6.1.4.1.232',
41
42      # CPQHLTH-MIB
43      'cpqHeTemperatureTable'            => '1.3.6.1.4.1.232.6.2.6.8',
44      'cpqHeTemperatureChassis'          => '1.3.6.1.4.1.232.6.2.6.8.1.1',
45      'cpqHeTemperatureIndex'            => '1.3.6.1.4.1.232.6.2.6.8.1.2',
46      'cpqHeTemperatureLocale'           => '1.3.6.1.4.1.232.6.2.6.8.1.3',
47      'cpqHeTemperatureCelsius'          => '1.3.6.1.4.1.232.6.2.6.8.1.4',
48      'cpqHeTemperatureHwLocation'       => '1.3.6.1.4.1.232.6.2.6.8.1.8',
49
50      'cpqHeCorrMemTotalErrs'            => '1.3.6.1.4.1.232.6.2.3.3.0',
51
52      # This is not a complete implementation  of the HLTH MIB
53
54      );
55
56 sub checkdevtype
57 {
58     my $dd = shift;
59     my $devdetails = shift;
60
61     return $dd->checkSnmpTable( 'cpqcim' );
62 }
63
64 my $enumLocale = {
65     1   => 'other',
66     2   => 'unknown',
67     3   => 'system',
68     4   => 'systemBoard',
69     5   => 'ioBoard',
70     6   => 'cpu',
71     7   => 'memory',
72     8   => 'storage',
73     9   => 'removableMedia',
74     10  => 'powerSupply',
75     11  => 'ambient',
76     12  => 'chassis',
77     13  => 'bridgeCard',
78 };
79
80
81 sub discover
82 {
83     my $dd = shift;
84     my $devdetails = shift;
85
86     my $session = $dd->session();
87     my $data = $devdetails->data();
88
89     my @checkOids = ( 'cpqHeCorrMemTotalErrs' );
90
91     foreach my $oid ( @checkOids )
92     {
93         if( $dd->checkSnmpOID($oid) )
94         { 
95             $devdetails->setCap( $oid );
96         }
97     }
98
99     my $TemperatureTable =
100         $session->get_table( -baseoid =>
101                              $dd->oiddef('cpqHeTemperatureTable') );
102
103     if( defined( $TemperatureTable ) )
104     {
105         $devdetails->storeSnmpVars( $TemperatureTable );
106         $devdetails->setCap( 'cpqHeTemperatureTable' );
107
108         my $ref = {};
109         $ref->{'indices'} = [];
110         $data->{'TemperatureTable'} = $ref;
111
112         # Index is Chassis . Index
113         foreach my $INDEX
114             ( $devdetails->
115               getSnmpIndices( $dd->oiddef('cpqHeTemperatureIndex') ) )
116         {
117             next if ( $devdetails->snmpVar
118                       ( $dd->oiddef('cpqHeTemperatureCelsius') .
119                         '.' . $INDEX ) < 0 );
120
121             push( @{$ref->{'indices'}}, $INDEX );
122
123             my $chassis = $devdetails->snmpVar
124                 ( $dd->oiddef('cpqHeTemperatureChassis') . '.' . $INDEX );
125
126             my $sensorIdx = $devdetails->snmpVar
127                 ( $dd->oiddef('cpqHeTemperatureIndex') . '.' . $INDEX );
128
129             my $locale = $devdetails->snmpVar
130                 ( $dd->oiddef('cpqHeTemperatureLocale') . '.' . $INDEX );
131             $locale = $enumLocale->{$locale} if $enumLocale->{$locale};
132
133             my $location = $devdetails->snmpVar
134                 ( $dd->oiddef('cpqHeTemperatureHwLocation') . '.' . $INDEX );
135
136             my $nick = sprintf('Chassis%d_%s_%d',
137                                $chassis, $locale, $sensorIdx);
138
139             my $param = {};
140             $ref->{$INDEX}->{'param'} = $param;
141             $param->{'cpq-cim-sensor-index'} = $INDEX;
142             $param->{'cpq-cim-sensor-nick'} = $nick;
143             $param->{'comment'} =
144                 sprintf('Chassis: %s Location: %s Index: %s',
145                         $chassis, $locale, $sensorIdx);
146             $param->{'precedence'} = 1000 - $sensorIdx;
147         }
148     }
149
150     return 1;
151 }
152
153
154 sub buildConfig
155 {
156     my $devdetails = shift;
157     my $cb = shift;
158     my $devNode = shift;
159     my $data = $devdetails->data();
160
161     my $cimParam = {
162         'comment'           => 'Compaq Insight Manager',
163         'precedence'        => '-500',
164     };
165
166     my $cimNode = $cb->addSubtree( $devNode, 'CompaqCIM', $cimParam );
167
168     my $healthParam = {
169         'comment'           => 'Compaq CIM Health',
170         'precedence'        => '-500'
171         };
172
173     my @healthTemplates;
174     if( $devdetails->hasCap('cpqHeCorrMemTotalErrs') )
175     {
176         push( @healthTemplates, 'CompaqCIM::cpq-cim-corr-mem-errs' );
177     }
178
179     my $Health = $cb->addSubtree( $cimNode, 'Health', $healthParam,
180                                   \@healthTemplates);
181
182     if( $devdetails->hasCap('cpqHeTemperatureTable') )
183     {
184         my $tempParam = {
185             'precedence' => '-100',
186             'comment' => 'Compaq Temperature Sensors',
187             'rrd-create-dstype' => 'GAUGE',
188         };
189
190         my $tempNode =
191             $cb->addSubtree(  $Health, 'Temperature_Sensors', $tempParam );
192
193         my $ref = $data->{'TemperatureTable'};
194
195         foreach my $INDEX ( @{ $ref->{'indices'} } )
196         {
197             my $param = $ref->{$INDEX}->{'param'};
198             $cb->addLeaf( $tempNode, $param->{'cpq-cim-sensor-nick'}, $param,
199                           [ 'CompaqCIM::cpq-cim-temperature-sensor' ] );
200         }
201     }
202 }
203
204
205 1;
206
207
208 # Local Variables:
209 # mode: perl
210 # indent-tabs-mode: nil
211 # perl-indent-level: 4
212 # End: