AIX-SysInfo
view release on metacpan or search on metacpan
######################################################
package AIX::SysInfo;
######################################################
#
# Author: Sergey Leonovich, sleonov@cpan.org
# Architecture: AIX
#
use strict;
our (@ISA, @EXPORT, $VERSION);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw( get_sysinfo );
$VERSION = "1.2";
#--------------------------------------------------------
# Module code begins
#--------------------------------------------------------
#
my $UNAME='/usr/bin/uname';
my $OSLEVEL='/usr/bin/oslevel';
my $PRTCONF='/usr/sbin/prtconf';
my %sysinfo = ();
my @pconf_array;
#--------------------------------------------------------
# Simple functions to populate the hash
#--------------------------------------------------------
sub prtconf_param {
my $param = shift @_;
my @result = grep {/$param/} @pconf_array;
return undef unless ( scalar @result );
($_ = pop @result) =~ /:\s*(.*)/;
return $1;
}
sub get_total_ram {
my $hash = shift @_;
my $memory = prtconf_param( '^Memory Size:' );
$memory =~ /(\d+)\D+/; $hash->{total_ram} = $1;
return 1;
}
sub get_hostname {
my $hash = shift @_;
chomp ( $hash->{hostname} = `$UNAME -n` );
return 1;
}
sub get_aix_version {
my $hash = shift @_;
chomp ( $hash->{aix_version} = `$OSLEVEL -r` );
return 1;
}
sub get_serial_num {
my $hash = shift @_;
$hash->{serial_num} = prtconf_param( '^Machine Serial Number:' );
return 1;
}
sub get_total_swap {
my $hash = shift @_;
my $swap = prtconf_param( 'Total Paging Space:' );
$swap =~ /(\d+)\D+/; $hash->{total_swap} = $1;
return 1;
}
sub get_hardware_info {
my $hash = shift @_;
chomp ( my $model_data = `$UNAME -M` );
$model_data =~ /(.*),(.*)/;
( $hash->{sys_arch}, $hash->{model_type} ) = ( $1, $2 );
return 1;
}
sub get_proc_data {
my $hash = shift @_;
$hash->{num_procs} = prtconf_param( '^Number Of Processors:' );
my $speed = prtconf_param( '^Processor Clock Speed:' );
$speed =~ /(\d+)\D+/; $hash->{proc_speed} = $1;
$hash->{proc_type} = prtconf_param( '^Processor Type:' );
return 1;
}
sub get_lpar_info {
my $hash = shift @_;
my $lpar = prtconf_param( '^LPAR Info:' );
$lpar =~ /(\S+)\s+(\S+)/;
$hash->{lpar_id} = $1;
$hash->{lpar_name} = $2;
return 1;
}
sub get_firmware_ver {
my $hash = shift @_;
$hash->{firmware_ver} = prtconf_param( '^Firmware Version:' );
return 1;
}
sub get_kernel_type {
my $hash = shift @_;
$hash->{kernel_type} = prtconf_param( '^Kernel Type:' );
return 1;
}
#-------------------------------------------------------------
# Module's function - get_sysinfo
#-------------------------------------------------------------
sub get_sysinfo {
%sysinfo = ();
my $s_ref = \%sysinfo;
return () unless( $^O eq 'aix');
return () unless ( open PCONF, "$PRTCONF |" );
chomp (@pconf_array = <PCONF>);
&get_hostname ( $s_ref );
&get_aix_version ( $s_ref );
&get_hardware_info( $s_ref );
&get_serial_num ( $s_ref );
&get_proc_data ( $s_ref );
&get_firmware_ver ( $s_ref );
&get_total_ram ( $s_ref );
&get_total_swap ( $s_ref );
&get_lpar_info ( $s_ref );
&get_kernel_type ( $s_ref );
return %sysinfo;
}
1;
#------------------------------------------------------
# Module code ends
#------------------------------------------------------
__END__
=pod
=head1 NAME
AIX::SysInfo - A Perl module for retrieving information about an AIX pSeries system
=head1 SYNOPSIS
use AIX::SysInfo;
my %sysinfo = get_sysinfo;
=head1 DESCRIPTION
You can install it using the usual Perl fashion:
perl Makefile.PL
make
make test
make install
This module provides a Perl interface for accessing information about a pSeries machine running the AIX operating system. It makes available a single function, B<get_sysinfo>, which returns a hash containing the following keys:
=over
=item B<hostname>
The value of this key contains the hostname of the system.
=item B<serial_num>
The value of this key contains the unique ID number for the system.
=item B<num_procs>
The value of this key contains the number of processors in the system.
( run in 0.592 second using v1.01-cache-2.11-cpan-39bf76dae61 )