import torrus 1.0.9
[freeside.git] / torrus / perllib / Torrus / DevDiscover / RFC2737_ENTITY_MIB.pm
1 #  Copyright (C) 2002  Stanislav Sinyagin
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: RFC2737_ENTITY_MIB.pm,v 1.1 2010-12-27 00:03:56 ivan Exp $
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
19
20 # Discovery module for ENTITY-MIB (RFC 2737)
21 # This module does not generate any XML, but provides information
22 # for other discovery modules
23
24 package Torrus::DevDiscover::RFC2737_ENTITY_MIB;
25
26 use strict;
27 use Torrus::Log;
28
29
30 $Torrus::DevDiscover::registry{'RFC2737_ENTITY_MIB'} = {
31     'sequence'     => 100,
32     'checkdevtype' => \&checkdevtype,
33     'discover'     => \&discover,
34     'buildConfig'  => \&buildConfig
35     };
36
37
38 our %oiddef =
39     (
40      # ENTITY-MIB
41      'entPhysicalDescr'        => '1.3.6.1.2.1.47.1.1.1.1.2',
42      'entPhysicalContainedIn'  => '1.3.6.1.2.1.47.1.1.1.1.4',
43      'entPhysicalName'         => '1.3.6.1.2.1.47.1.1.1.1.7'
44      );
45
46
47
48 sub checkdevtype
49 {
50     my $dd = shift;
51     my $devdetails = shift;
52
53     my $session = $dd->session();
54     my $data = $devdetails->data();
55
56     my $descrTable =
57         $session->get_table( -baseoid =>
58                              $dd->oiddef('entPhysicalDescr') );
59     if( defined $descrTable )
60     {
61         $devdetails->storeSnmpVars( $descrTable );
62     }
63
64     my $nameTable =
65         $session->get_table( -baseoid =>
66                              $dd->oiddef('entPhysicalName') );
67     if( defined $nameTable )
68     {
69         $devdetails->storeSnmpVars( $nameTable );
70     }
71
72     return( defined($descrTable) or defined($nameTable) );
73 }
74
75
76 sub discover
77 {
78     my $dd = shift;
79     my $devdetails = shift;
80
81     my $data = $devdetails->data();
82     my $session = $dd->session();
83
84     $data->{'entityPhysical'} = {};
85
86     my $chassisIndex = 0;
87     my $oidContainedIn = $dd->oiddef('entPhysicalContainedIn');
88
89     foreach my $phyIndex
90         ( $devdetails->getSnmpIndices($dd->oiddef('entPhysicalDescr')) )
91     {
92         my $ref = {};
93         $data->{'entityPhysical'}{$phyIndex} = $ref;
94
95         # Find the chassis. It is not contained in anything.
96         if( not $chassisIndex )
97         {
98             my $oid = $oidContainedIn . '.' . $phyIndex;
99             my $result = $session->get_request( -varbindlist => [ $oid ] );
100             if( $session->error_status() == 0 and $result->{$oid} == 0 )
101             {
102                 $chassisIndex = $phyIndex;
103             }
104         }
105
106         my $descr = $devdetails->snmpVar( $dd->oiddef('entPhysicalDescr') .
107                                           '.' . $phyIndex );
108         if( $descr )
109         {
110             $ref->{'descr'} = $descr;
111         }
112
113         my $name = $devdetails->snmpVar( $dd->oiddef('entPhysicalName') .
114                                          '.' . $phyIndex );
115         if( $name )
116         {
117             $ref->{'name'} = $name;
118         }
119     }
120
121     if( $chassisIndex )
122     {
123         $data->{'entityChassisPhyIndex'} = $chassisIndex;
124         my $chassisDescr = $data->{'entityPhysical'}{$chassisIndex}{'descr'};
125         if( length( $chassisDescr ) > 0 and
126             not defined( $data->{'param'}{'comment'} ) )
127         {
128             Debug('ENTITY-MIB: found chassis description: ' . $chassisDescr);
129             $data->{'param'}{'comment'} = $chassisDescr;
130         }
131     }
132
133     return 1;
134 }
135
136
137 sub buildConfig
138 {
139     my $devdetails = shift;
140     my $cb = shift;
141     my $devNode = shift;
142 }
143
144
145 1;
146
147
148 # Local Variables:
149 # mode: perl
150 # indent-tabs-mode: nil
151 # perl-indent-level: 4
152 # End: