import torrus 1.0.9
[freeside.git] / torrus / perllib / Torrus / DevDiscover / RFC1628_UPS_MIB.pm
1 #  Copyright (C) 2008  Jon Nistor
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: RFC1628_UPS_MIB.pm,v 1.1 2010-12-27 00:03:56 ivan Exp $
18 # Jon Nistor <nistor at snickers dot org>
19
20 # Discovery module for UPS-MIB (RFC 1628)
21 #
22 # Tested with:
23 #     ConnectUPS Web/SNMP Card V4.20 [powerware 9390]
24 #
25 # Issues with:
26 #     ConnectUPS Web/SNMP Card V3.16 [powerware 9155]
27 #      - InputFrequency and InputTruePower are missing from RFC UPS-MIB
28 #
29
30 package Torrus::DevDiscover::RFC1628_UPS_MIB;
31
32 use strict;
33 use Torrus::Log;
34
35
36 $Torrus::DevDiscover::registry{'RFC1628_UPS_MIB'} = {
37     'sequence'     => 100,
38     'checkdevtype' => \&checkdevtype,
39     'discover'     => \&discover,
40     'buildConfig'  => \&buildConfig
41     };
42
43
44 our %oiddef =
45     (
46      # UPS-MIB
47      'upsIdent'                     => '1.3.6.1.2.1.33.1.1',
48      'upsIdentManufacturer'         => '1.3.6.1.2.1.33.1.1.1.0',
49      'upsIdentModel'                => '1.3.6.1.2.1.33.1.1.2.0',
50      'upsIdentUPSSoftwareVersion'   => '1.3.6.1.2.1.33.1.1.3.0',
51      'upsIdentAgentSoftwareVersion' => '1.3.6.1.2.1.33.1.1.4.0',
52      'upsIdentName'                 => '1.3.6.1.2.1.33.1.1.5.0',
53
54      'upsInputNumLines'             => '1.3.6.1.2.1.33.1.3.2.0',
55      'upsOutputNumLines'            => '1.3.6.1.2.1.33.1.4.3.0',
56      'upsBypassNumLines'            => '1.3.6.1.2.1.33.1.5.2.0'
57      );
58
59
60
61 sub checkdevtype
62 {
63     my $dd = shift;
64     my $devdetails = shift;
65
66     my $session = $dd->session();
67     my $data = $devdetails->data();
68
69     return $dd->checkSnmpTable( 'upsIdent' );
70 }
71
72
73 sub discover
74 {
75     my $dd = shift;
76     my $devdetails = shift;
77
78     my $data = $devdetails->data();
79     my $session = $dd->session();
80
81     my $upsInfo = $dd->retrieveSnmpOIDs('upsIdentManufacturer',
82                   'upsIdentModel', 'upsIdentUPSSoftwareVersion',
83                   'upsIdentAgentSoftwareVersion', 'upsIdentName',
84                   'upsInputNumLines', 'upsOutputNumLines', 'upsBypassNumLines');
85
86     $data->{'param'}{'comment'} = $upsInfo->{'upsIdentManufacturer'} . " " .
87                             $upsInfo->{'upsIdentModel'} . " " . 
88                             $upsInfo->{'upsIdentUPSSoftwareVersion'};
89
90     # PROG: Discover number of lines (in,out,bypass)...
91     $data->{'numInput'}  = $upsInfo->{'upsInputNumLines'};
92     $data->{'numOutput'} = $upsInfo->{'upsOutputNumLines'};
93     $data->{'numBypass'} = $upsInfo->{'upsBypassNumLines'};
94
95     Debug("UPS Lines  Input: " . $data->{'numInput'} .
96                   ", Output: " . $data->{'numOutput'} .
97                   ", Bypass: " . $data->{'numBypass'} );
98
99     if( $devdetails->param('RFC1628_UPS::disable-input') ne 'yes' )
100     {
101         $devdetails->setCap('UPS-input');
102     }
103
104     if( $devdetails->param('RFC1628_UPS::disable-output') ne 'yes' )
105     {
106         $devdetails->setCap('UPS-output');
107     }
108
109     if( $devdetails->param('RFC1628_UPS::disable-bypass') ne 'yes' )
110     {
111         $devdetails->setCap('UPS-bypass');
112     }
113
114     return 1;
115 }
116
117
118 sub buildConfig
119 {
120     my $devdetails = shift;
121     my $cb = shift;
122     my $devNode = shift;
123     my $data = $devdetails->data();
124
125     # PROG: Add static battery information
126     $cb->addSubtree( $devNode, 'Battery',
127                    { 'precedence' => 999 },
128                    [ 'RFC1628_UPS_MIB::battery-subtree' ] );
129     
130     if( $devdetails->hasCap('UPS-input') )
131     {
132         my $nodeInput = $cb->addSubtree( $devNode, 'Input',
133                                   { 'comment' => 'Input feeds' },
134                                   [ 'RFC1628_UPS_MIB::ups-input-subtree' ] );
135
136         foreach my $INDEX ( 1 .. $data->{'numInput'} )
137         {
138             $cb->addSubtree( $nodeInput, sprintf('Phase_%d', $INDEX),
139                              { 'ups-input-idx' => $INDEX },
140                              [ 'RFC1628_UPS::ups-input-leaf' ] );
141         }
142     }
143
144     if( $devdetails->hasCap('UPS-output') )
145     {
146         my $nodeOutput = $cb->addSubtree( $devNode, 'Output',
147                                    { 'comment' => 'Output feeds' },
148                                    [ 'RFC1628_UPS_MIB::ups-output-subtree' ] );
149
150         foreach my $INDEX ( 1 .. $data->{'numOutput'} )
151         {
152             $cb->addSubtree( $nodeOutput, sprintf('Phase_%d', $INDEX),
153                              { 'ups-output-idx' => $INDEX },
154                              [ 'RFC1628_UPS::ups-output-leaf' ] );
155         }
156     }
157
158     if( $devdetails->hasCap('UPS-bypass') )
159     {
160         my $nodeBypass = $cb->addSubtree( $devNode, 'Bypass',
161                                    { 'comment' => 'Bypass feeds' },
162                                    [ 'RFC1628_UPS_MIB::ups-bypass-subtree' ] );
163
164         foreach my $INDEX ( 1 .. $data->{'numBypass'} )
165         {
166             $cb->addSubtree( $nodeBypass, sprintf('Phase_%d', $INDEX),
167                              { 'ups-bypass-idx' => $INDEX },
168                              [ 'RFC1628_UPS::ups-bypass-leaf' ] );
169         }
170     }
171
172 }
173
174 1;
175
176 # Local Variables:
177 # mode: perl
178 # indent-tabs-mode: nil
179 # perl-indent-level: 4
180 # End: