Merge remote-tracking branch 'upstream/master'
[torrus-plus.git] / src / lib / Torrus / DevDiscover / RFC2737_ENTITY_MIB.pm
blobfe78e6d600e746fbb2983e895bfa653bb68ba36b
1 # Copyright (C) 2002 Stanislav Sinyagin
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17 # $Id$
18 # Stanislav Sinyagin <ssinyagin@yahoo.com>
20 # Discovery module for ENTITY-MIB (RFC 2737)
21 # This module does not generate any XML, but provides information
22 # for other discovery modules
24 package Torrus::DevDiscover::RFC2737_ENTITY_MIB;
26 use strict;
27 use warnings;
29 use Torrus::Log;
31 our $VERSION = 1.0;
33 $Torrus::DevDiscover::registry{'RFC2737_ENTITY_MIB'} = {
34 'sequence' => 100,
35 'checkdevtype' => \&checkdevtype,
36 'discover' => \&discover,
37 'buildConfig' => \&buildConfig
41 our %oiddef =
43 # ENTITY-MIB
44 'entPhysicalDescr' => '1.3.6.1.2.1.47.1.1.1.1.2',
45 'entPhysicalContainedIn' => '1.3.6.1.2.1.47.1.1.1.1.4',
46 'entPhysicalName' => '1.3.6.1.2.1.47.1.1.1.1.7'
51 sub checkdevtype
53 my $dd = shift;
54 my $devdetails = shift;
56 my $session = $dd->session();
57 my $data = $devdetails->data();
59 my $descrTable =
60 $session->get_table( -baseoid =>
61 $dd->oiddef('entPhysicalDescr') );
62 if( defined $descrTable )
64 $devdetails->storeSnmpVars( $descrTable );
67 my $nameTable =
68 $session->get_table( -baseoid =>
69 $dd->oiddef('entPhysicalName') );
70 if( defined $nameTable )
72 $devdetails->storeSnmpVars( $nameTable );
75 return( defined($descrTable) or defined($nameTable) );
79 sub discover
81 my $dd = shift;
82 my $devdetails = shift;
84 my $data = $devdetails->data();
85 my $session = $dd->session();
87 $data->{'entityPhysical'} = {};
89 my $chassisIndex = 0;
90 my $oidContainedIn = $dd->oiddef('entPhysicalContainedIn');
92 for my $phyIndex
93 ( $devdetails->getSnmpIndices($dd->oiddef('entPhysicalDescr')) )
95 my $ref = {};
96 $data->{'entityPhysical'}{$phyIndex} = $ref;
98 # Find the chassis. It is not contained in anything.
99 if( not $chassisIndex )
101 my $oid = $oidContainedIn . '.' . $phyIndex;
102 my $result = $session->get_request( -varbindlist => [ $oid ] );
103 if( $session->error_status() == 0 and $result->{$oid} == 0 )
105 $chassisIndex = $phyIndex;
109 my $descr = $devdetails->snmpVar( $dd->oiddef('entPhysicalDescr') .
110 '.' . $phyIndex );
111 if( $descr )
113 $ref->{'descr'} = $descr;
116 my $name = $devdetails->snmpVar( $dd->oiddef('entPhysicalName') .
117 '.' . $phyIndex );
118 if( $name )
120 $ref->{'name'} = $name;
124 if( $chassisIndex )
126 $data->{'entityChassisPhyIndex'} = $chassisIndex;
127 my $chassisDescr = $data->{'entityPhysical'}{$chassisIndex}{'descr'};
128 if( defined($chassisDescr) and $chassisDescr ne '' and
129 not defined( $data->{'param'}{'comment'} ) )
131 Debug('ENTITY-MIB: found chassis description: ' . $chassisDescr);
132 $data->{'param'}{'comment'} = $chassisDescr;
136 return 1;
140 sub buildConfig
142 my $devdetails = shift;
143 my $cb = shift;
144 my $devNode = shift;
145 return;
152 # Local Variables:
153 # mode: perl
154 # indent-tabs-mode: nil
155 # perl-indent-level: 4
156 # End: