#!/usr/bin/env perl use warnings; use strict; use version ; our $VERSION = 'v1.3.0'; # IPMI network module for sysinfo client # Author: R. W. Rodolico # Date: 2016-09-17 # # Enter some information about system here # # Revision History # # 20171124 RWR # Fixed where STDERR now goes to /dev/null # # 20191118 RWR v1.2.1 # in some cases, ipmitool is used only to access other devices over the network # so it will not have information. Fixed so that if @temp is empty, will just exit # # 20230204 RWR v1.3.0 # look for specific IPMI files to determine if the driver is installed # better than just checking @temp afterwards # # module to get network interface information for ipmi # requires ipmitool (runs ipmitool lan print) # NOTE: this takes the ipmitool output and parses it, so changes to # this output invalidates this module# # find our location and use it for searching for libraries. library.pm must be in the same directory as the calling script # or, if run interactively, in the parent of the modules BEGIN { use FindBin; use File::Spec; # prepend the bin directory and its parent use lib File::Spec->catdir($FindBin::Bin), File::Spec->catdir("$FindBin::Bin/.."); eval( 'use library;' ); die sprintf( "Could not find library.pm in %s, INC is %s\n", __FILE__, join( "\n", @INC ) ) if $@; } ##### ##### Change these to match your needs ##### # Make this a list of all the modules we are going to use. You can replace undef with the version you need, if you like my $modulesList = { 'Data::Dumper' => undef, }; # hash of commands that are needed for the system. key is the name of the command and, in some cases, the value will become # the full path (from which or where) my $commandsList = { 'ipmitool' => undef, }; # list of operating systems this module can be used on. my $osList = { # 'mswin32' => undef, 'freebsd' => undef, 'linux' => undef, }; # the category the return data should go into. See sysinfo for a list my $CATEGORY = 'network'; ##### ##### End of required ##### # some variables needed for our system my $errorPrepend = 'error: in ' . __FILE__; # this is prepended to any error messages my @out; # temporary location for each line of output # Try to load the modules we need. If we can not, then make a list of missing modules for error message. for my $module ( keys %$modulesList ) { eval ( "use $module;" ); push @out, "$errorPrepend Could not load $module" if $@; } if ( ! @out && ! checkOS ( $osList ) ) { # check if we are on an acceptible operating system push @out, "$errorPrepend Invalid Operating System"; } if ( !@out && ! validCommandOnSystem ( $commandsList ) ) { push @out, "$errorPrepend Can not find some commands needed"; } if ( !@out ) { # we made it, we have everything, so do the processing ##### ##### Your code starts here. Remember to push all output onto @out ##### # some systems have ipmitool installed simply for managing other machines # but do not have ipmi themselves exit 1 unless -e '/dev/ipmi0' || -e '/dev/ipmi/0' || -e '/dev/ipmidev/0'; my %storage = ( 'address' => { 'key' => 'IP Address' }, 'netmask' => { 'key' => 'Subnet Mask' }, 'mac' => { 'key' => 'MAC Address' } ); my @temp = qx( ipmitool lan print 2> /dev/null ); exit 2 unless @temp; # ipmitool installed, but driver not. Probably using to connect someplace else. chomp @temp; foreach my $line ( @temp ) { my ( $key, $value ) = split( /\s+:\s+/, $line ); foreach my $test ( keys %storage ) { next if defined( $storage{$test}{'value'} ); if ( $key eq $storage{$test}{'key'} ) { $storage{$test}{'value'} = $value; last; } # if } # foreach } foreach my $key ( keys %storage ) { push @out, "$CATEGORY\tipmi\t$key\t$storage{$key}{'value'}"; } ##### ##### Your code ends here. ##### } # If we are testing from the command line (caller is undef), print the results for debugging print join( "\n", @out ) . "\n" unless caller; # called by do, which has a value of the last assignment made, so make the assignment. The equivilent of a return my $return = join( "\n", @out );