-
Notifications
You must be signed in to change notification settings - Fork 1
/
HpMibConstants.pm
executable file
·82 lines (67 loc) · 2.44 KB
/
HpMibConstants.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package HpMibConstants;
#
# This module exists to encapsulate the 2 hashes you'll find defined
# below. They are static lists of chassis and module information that
# is buried in HP MIB files. The main ScanSwitch and SwitchMap
# programs call the initialize subroutine once when they start up.
# That subroutine parses the HP MIB files to initialize the hashes.
# Later, the programs call the "get" subroutines as needed to access
# the data in the hashes.
#
use strict;
use Log::Log4perl qw(get_logger);
#use Data::Dumper;
my %HpSwitches;
my %HpRouters;
#
# Read the HP MIB file to define the sysObject OIDs that HP uses.
# Return hashes containing the names and descriptions.
#
sub initialize () {
my $logger = get_logger('log1');
my $logger7 = get_logger('log7');
$logger->debug("called");
# load the chassis HP Products OIDs
$logger->info("reading $Constants::HpProductsMibFile");
# The MIB file came from the MIBs_V5_MIBs_V5/HP(hh3c)/MIBs directory
# of the MIBs_V5_MIBs_V5.zip file that I downloaded from
# https://h10145.www1.hp.com/Downloads/SoftwareReleases.aspx?ProductNumber=JD239A&lang=en,en&cc=us,us&prodSeriesId=4177519
# (under Other - MIBs_V5 near the bottom of the page)
open HP_PRODUCTS_MIB_FILE, "<$Constants::HpProductsMibFile" or do {
$logger->fatal("Couldn't open $Constants::HpProductsMibFile for reading, $!");
exit;
};
while (<HP_PRODUCTS_MIB_FILE>) {
chomp;
if (/(\w+)\s+OBJECT IDENTIFIER\s+::=\s+\{\s+hpSwitch\s+(\d+)\s+}/) {
my $SwitchName = $1;
my $Number = $2;
my $oid = '1.3.6.1.4.1.25506.11.1.' . $Number;
$HpSwitches{$oid} = $SwitchName;
$logger7->info("Switch: $oid = \"$SwitchName\"");
} elsif (/(\w+)\s+OBJECT IDENTIFIER\s+::=\s+\{\s+hpRouter\s+(\d+)\s+}/) {
my $RouterName = $1;
my $Number = $2;
my $oid = '1.3.6.1.4.1.25506.11.2.' . $Number;
$HpRouters{$oid} = $RouterName;
$logger7->info("Router: $oid = \"$RouterName\"");
}
}
close HP_PRODUCTS_MIB_FILE;
my $hpSwitchCount = keys %HpSwitches;
my $hpRouterCount = keys %HpRouters;
$logger->info("got $hpSwitchCount HP switch descriptions");
$logger->info("got $hpRouterCount HP router descriptions");
$logger->debug("returning");
}
sub getHpDeviceName ($) {
my $sysObjectID = shift;
if (exists $HpSwitches{$sysObjectID}) {
return $HpSwitches{$sysObjectID};
} elsif (exists $HpRouters{$sysObjectID}) {
return $HpRouters{$sysObjectID};
} else {
return '';
}
}
1;