Blame | Last modification | View Log | RSS feed
#! /usr/bin/perl -w
# sysinfo
# Author: R. W. Rodolico
# Primary client portion of sysinfo system. Will collect information about its current
# host and create a report containing the information. This report can then be processed
# by process_sysinfo.pl on the collection computer.
# output file consists of a key/value pair, with the key in square brackets, example:
# [tag]value
# where tag is the name of the function we are looking at (hostname, report date, cpu type)
# and value is the associated value.
# Also has multi line key/values, which are in the form
# [tag]
# value1
# value2
# [another tag (or end of file)]
# where value1 and value2 are considered attributes of tag. This is used where there are multiple
# values for a function, such as for installed packages, IP Addresses, hardware lists, and
# disk partitions.
# Assumes following packages installed on system:
# hostname
# uname
# procinfo
# uptime
# lspci
# lsb_release
# apt-get install procinfo lsb sysinfo
# Will search for one of the following package managers:
# dpkg (Debian and derivatives)
# rpm (RedHat and derivatives)
# yast (SuSE and derivatives) NOT IMPLEMENTED
# Also assumes following standard apps are accessible
# ifconfig
# grep
# awk
# cat
# df
# free
#
# Version 1.3 20071104
# added capability of e-mailing the results by itself and external configuration file
# Version 1.3.1 20071110
# added du -sk to explicitly do directory sizes in 'k'. Also, fixed some documentation
# Version 1.3.3 20081104
# modified hostname to hostname -f, and allowed user to place custom value in configuration file
# also, modified to go with Debian standards in preparation to creating a debian package.
# Version 2.0 20081208
# Modified to use different libraries for different OS's in preparation to porting to Windows
# Uses different packages based on which OS it is on.
# Following are global variables overridden if configuration file exists
my $APPLICATION_ROOT;
my $client_name;
my $CUSTOM_PACKAGE_FINDER ;
my @directoriesToWatch;
my $hostname;
# only required if reports are sent from process_sysinfo.pl. Not the norm.
my $iMailResults = 0; # if 0 (false), ignore following variables
my $mailTo;
my $mailCC;
my $mailBCC;
my $mailServer;
my $mailServerPort;
my $mailFrom;
my $mailSubject = `hostname` . ' sysinfo ' . `date +"%F"`;
my $SENDMAIL;
my $TESTING = 0;
my $VERSION = '2.0.0';
sub loadConfigurationFile {
my $configuration_file;
if ($TESTING) {
$configuration_file = './sysinfo.conf';
} else {
$configuration_file = '/etc/sysinfo/sysinfo.conf';
}
open CONFFILE, "<$configuration_file" or die "Can not open configuration file $configuration_file";
my $confFileContents = join( '', <CONFFILE> );
close CONFFILE;
return $confFileContents;
}
# generic routine to send an e-mail
sub sendmessage {
my ( $from, $to, $subject, $message, $cc, $bcc, $server, $port ) = @_;
open SENDMAIL, "|$SENDMAIL" or die "Could not open sendmail";
print SENDMAIL "From: $from\nTo: $to\nSubject: $subject\n";
print SENDMAIL "cc: $cc\n" if $cc;
print SENDMAIL "bcc: $bcc\n" if $bcc;
print SENDMAIL "\n$message\n";
print SENDMAIL ".\n";
close SENDMAIL;
}
BEGIN { # block to find home grown libraries.
push @INC, '.'; # here is where local library is
}
if ($TESTING) {
use Data::Dumper;
}
# Windows: ppm install XML::Simple
# Debian: apt-get install libxml-simple-perl
use XML::Simple;
use SysinfoLinux;
eval( &loadConfigurationFile ); # load the configuration file
# parameters are assumed to override configuration file details. If we have parameters
# they are of the form varname=value, where value is the new value to assign to varname
# the command has a dollar sign prepended (for the variable) and a semi-colon appended
# to create a command that may be executed by eval. Thus, this must be a single line
# no embedded spaces parameter.
#while ($parameter = shift ) {
# eval ( '$' . $parameter . ';');
#}
die "You must configure this package in /etc/sysinfo/sysinfo.conf" unless $client_name;
my $commandLine;
if (@ARGV) {
$commandLine = join("\n", @ARGV) . "\n\n";
}
my $System;
$$System{'report'}{'version'} = $VERSION;
$$System{'report'}{'date'} = `date '+%Y-%m-%d %H:%M'`;
$$System{'report'}{'client'} = $client_name;
chomp $$System{'report'}{'date'};
$$System{'network'} = &SysinfoLinux::getNetwork;
$$System{'diskinfo'} = &SysinfoLinux::getDiskInfo(@directoriesToWatch);
$$System{'software'} = &SysinfoLinux::getSoftware($CUSTOM_PACKAGE_FINDER);
$$System{'operatingsystem'} = &SysinfoLinux::getOperatingSystem;
$$System{'system'} = &SysinfoLinux::getSystemInformation($hostname);
$$System{'pci'} = &SysinfoLinux::getPCI;
my $output = XML::Simple->new(AttrIndent => 1, KeepRoot => 1, NoAttr => 1, RootName => "sysinfo$VERSION" ); # NoIndent => 1
#print Data::Dumper->Dump([$System],['System']);
if ($iMailResults) {
&sendmessage( $mailFrom, $mailTo, $mailSubject, $output->XMLout($System), $mailCC, $mailBCC, $mailServer, $mailServerPort );
} else {
print $output->XMLout($System);
}
1;