AIX-SysInfo
view release on metacpan or search on metacpan
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 );
( run in 0.232 second using v1.01-cache-2.11-cpan-4d50c553e7e )