| 29 |
rodolico |
1 |
#!/usr/bin/env perl
|
|
|
2 |
use warnings;
|
| 31 |
rodolico |
3 |
use strict;
|
| 251 |
rodolico |
4 |
use Data::Dumper;
|
| 29 |
rodolico |
5 |
|
| 37 |
rodolico |
6 |
# Description: Get IPMI network information
|
| 29 |
rodolico |
7 |
|
| 203 |
rodolico |
8 |
our $VERSION = '1.3.0';
|
| 37 |
rodolico |
9 |
|
| 29 |
rodolico |
10 |
# IPMI network module for sysinfo client
|
|
|
11 |
# Author: R. W. Rodolico
|
|
|
12 |
# Date: 2016-09-17
|
|
|
13 |
|
| 57 |
rodolico |
14 |
# 20171124 RWR
|
|
|
15 |
# Fixed where STDERR now goes to /dev/null
|
|
|
16 |
#
|
| 149 |
rodolico |
17 |
# 20191118 RWR v1.2.1
|
|
|
18 |
# in some cases, ipmitool is used only to access other devices over the network
|
|
|
19 |
# so it will not have information. Fixed so that if @temp is empty, will just exit
|
|
|
20 |
#
|
| 203 |
rodolico |
21 |
# 20230204 RWR v1.3.0
|
|
|
22 |
# look for specific IPMI files to determine if the driver is installed
|
|
|
23 |
# better than just checking @temp afterwards
|
|
|
24 |
#
|
| 29 |
rodolico |
25 |
# module to get network interface information for ipmi
|
|
|
26 |
# requires ipmitool (runs ipmitool lan print)
|
|
|
27 |
# NOTE: this takes the ipmitool output and parses it, so changes to
|
|
|
28 |
# this output invalidates this module
|
|
|
29 |
|
| 251 |
rodolico |
30 |
# find our location and use it for searching for libraries
|
| 29 |
rodolico |
31 |
BEGIN {
|
| 251 |
rodolico |
32 |
use FindBin;
|
|
|
33 |
use File::Spec;
|
|
|
34 |
use lib File::Spec->catdir($FindBin::Bin);
|
|
|
35 |
eval( 'use library;' );
|
|
|
36 |
die "Could not find library.pm in the code directory\n" if $@;
|
|
|
37 |
eval( 'use Data::Dumper;' );
|
| 29 |
rodolico |
38 |
}
|
|
|
39 |
|
| 251 |
rodolico |
40 |
# check for valid OS.
|
|
|
41 |
exit 1 unless &checkOS( { 'linux' => undef, 'freebsd' => undef } );
|
| 29 |
rodolico |
42 |
|
| 251 |
rodolico |
43 |
# check for required commands, return 2 if they don't exist. Enter an full list of all commands required. If one doesn't exist
|
|
|
44 |
# script returns a 2
|
|
|
45 |
foreach my $command ( 'ipmitool' ) {
|
|
|
46 |
exit 2 unless &validCommandOnSystem( $command );
|
|
|
47 |
}
|
| 29 |
rodolico |
48 |
|
|
|
49 |
|
| 203 |
rodolico |
50 |
# some systems have ipmitool installed simply for managing other machines
|
|
|
51 |
# but do not have ipmi themselves
|
|
|
52 |
exit 1 unless -e '/dev/ipmi0' || -e '/dev/ipmi/0' || -e '/dev/ipmidev/0';
|
|
|
53 |
|
| 29 |
rodolico |
54 |
my %storage = (
|
|
|
55 |
'address' => { 'key' => 'IP Address' },
|
|
|
56 |
'netmask' => { 'key' => 'Subnet Mask' },
|
|
|
57 |
'mac' => { 'key' => 'MAC Address' }
|
|
|
58 |
);
|
|
|
59 |
|
|
|
60 |
my $CATEGORY = 'network';
|
| 251 |
rodolico |
61 |
my @temp = qx( ipmitool lan print 2> /dev/null );
|
| 149 |
rodolico |
62 |
exit 2 unless @temp; # ipmitool installed, but driver not. Probably using to connect someplace else.
|
| 29 |
rodolico |
63 |
chomp @temp;
|
|
|
64 |
|
|
|
65 |
foreach my $line ( @temp ) {
|
|
|
66 |
my ( $key, $value ) = split( /\s+:\s+/, $line );
|
|
|
67 |
foreach my $test ( keys %storage ) {
|
|
|
68 |
next if defined( $storage{$test}{'value'} );
|
|
|
69 |
if ( $key eq $storage{$test}{'key'} ) {
|
|
|
70 |
$storage{$test}{'value'} = $value;
|
|
|
71 |
last;
|
|
|
72 |
} # if
|
|
|
73 |
} # foreach
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
foreach my $key ( keys %storage ) {
|
|
|
77 |
print "$CATEGORY\tipmi\t$key\t$storage{$key}{'value'}\n";
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
1;
|