Subversion Repositories camp_sysinfo_client_3

Rev

Rev 237 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
29 rodolico 1
#!/usr/bin/env perl
2
use warnings;
31 rodolico 3
use strict;
29 rodolico 4
 
37 rodolico 5
# Description: Get IPMI network information
29 rodolico 6
 
203 rodolico 7
our $VERSION = '1.3.0';
37 rodolico 8
 
29 rodolico 9
# IPMI network module for sysinfo client
10
# Author: R. W. Rodolico
11
# Date:   2016-09-17 
12
 
57 rodolico 13
# 20171124 RWR
14
# Fixed where STDERR now goes to /dev/null
15
#
149 rodolico 16
# 20191118 RWR v1.2.1
17
# in some cases, ipmitool is used only to access other devices over the network
18
# so it will not have information. Fixed so that if @temp is empty, will just exit
19
#
203 rodolico 20
# 20230204 RWR v1.3.0
21
# look for specific IPMI files to determine if the driver is installed
22
# better than just checking @temp afterwards
23
#
29 rodolico 24
# module to get network interface information for ipmi
25
# requires ipmitool (runs ipmitool lan print)
26
# NOTE: this takes the ipmitool output and parses it, so changes to 
27
#       this output invalidates this module
28
 
29
BEGIN {
30
   push @INC, shift;
31
}
32
 
33
use library;
34
 
35
my $command = &validCommandOnSystem('ipmitool');
36
 
37
exit 1 unless $command;
38
 
203 rodolico 39
# some systems have ipmitool installed simply for managing other machines
40
# but do not have ipmi themselves
41
exit 1 unless -e '/dev/ipmi0' || -e '/dev/ipmi/0' || -e '/dev/ipmidev/0';
42
 
29 rodolico 43
my %storage = ( 
44
                'address' => { 'key' => 'IP Address' }, 
45
                'netmask' => { 'key' => 'Subnet Mask' },
46
                'mac' => { 'key' => 'MAC Address' }
47
              );
48
 
49
my $CATEGORY = 'network';
197 rodolico 50
my @temp = qx( $command lan print 2> /dev/null );
149 rodolico 51
exit 2 unless @temp; # ipmitool installed, but driver not. Probably using to connect someplace else.
29 rodolico 52
chomp @temp;
53
 
54
foreach my $line ( @temp ) {
55
   my ( $key, $value ) = split( /\s+:\s+/, $line );
56
   foreach my $test ( keys %storage ) {
57
      next if defined( $storage{$test}{'value'} );
58
      if ( $key eq $storage{$test}{'key'} ) {
59
         $storage{$test}{'value'} = $value;
60
         last;
61
      } # if
62
   } # foreach 
63
}
64
 
65
foreach my $key ( keys %storage ) {
66
   print "$CATEGORY\tipmi\t$key\t$storage{$key}{'value'}\n";
67
}
68
 
69
1;