=pod =head1 NAME VAdmind::Plugins::System::Info.pm - Provides functions for system OS related. =head1 SYNOPSIS The code is being included by the VAdmind platform. my $plugin = System::Info->new; =head1 DESCRIPTION VAdmind::System::Info provide functions related to the OS. All the methods provided herein will fetch information from primarily /proc filesystem or /etc system configuration files. None of the methods accepts input. =head1 USES =head1 AUTHOR Urivan Flores Saaib =head1 COPYRIGHT Copyright (c) 2003-2009 Urivan Flores. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut package VAdmind::Plugins::System::Info; use strict; use warnings; =head1 METHODS =head2 CONSTRUCTORS =head2 new Creates a new System::Info plugin object. my $plugin = System::Info->new; =cut sub new { my $type = shift; my $self = {@_}; $self->{'VERSION'} = "0.1.1"; $self->{'AUTHOR'} = "Urivan Alyasid Flores Saaib "; return bless ($self, $type); } =head2 getRelease Gets system release name. =cut sub getRelease { my $self = shift; my $out = $self->{'out'}; my $file = '/etc/redhat-release'; my $fo = open (FH, $file); if (!$fo) { $out->{'error'} = "Error reading $file: $!"; } else { my $version = ; $version =~ s/[\n|\r]//g; $out->{'xml'}->{'release'}->[0] = $version; } close (FH); } =head2 getSystemInfo Retrieves the following system identification information: -System name. -Node name. -Release number. -Version. -Machine type. $plugin->getSystemInfo; =cut sub getSystemInfo { my $self = shift; my $out = $self->{'out'}; use POSIX "uname"; my ($sysname, $nodename, $release, $version, $machine ) = uname; $out->{'xml'}->{'sysname'}->[0] = $sysname; $out->{'xml'}->{'nodename'}->[0] = $nodename; $out->{'xml'}->{'release'}->[0] = $release; $out->{'xml'}->{'version'}->[0] = $version; $out->{'xml'}->{'machine'}->[0] = $machine; } =head2 getKernelVer Gets kernel version. =cut sub getKernelVer { my $self = shift; my $out = $self->{'out'}; my $file = '/proc/version'; my $fo = open (FH, $file); if (!$fo) { $out->{'error'} = 'Cant open '.$file.': '.$!; } else { my $data = ; my $version = (split (/ /,$data))[2]; $version =~ s/[\n|\r]//g; $out->{'xml'}->{'version'}->[0] = $version; } close (FH); } =head2 getLoad Provides the current system load from the system. =cut sub getLoad { my $self = shift; my $out = $self->{'out'}; my $file = "/proc/loadavg"; if (-f $file) { my $fo = open (FH,$file); if (!$fo) { $out->{'error'} = 'Can\'t open file '.$file.': '.$!; } else { my @uptime = (split (/ /, ))[0,1,2]; $out->{'xml'}->{'l5'}->[0] = $uptime[0]; $out->{'xml'}->{'l10'}->[0] = $uptime[1]; $out->{'xml'}->{'l15'}->[0] = $uptime[2]; } } else { $out->{'error'} = 'Unable to read load average'; } return $out; } 1;