- 论坛徽章:
- 0
|
#!/usr/bin/perl -w
# os_sock.pl
# Monitors the indicated file using the indicated UA Configuration
#----------------
use strict;
use UaSocketClient;
#use File;
#--------------------------
# Get Configuration File - See Sample.cfg
#--------------------------
my $configFile = $ARGV[0] || "os_sock.conf";
while ( ! ( $configFile =~ /^\S+\.conf$/ ) ) {
print "Please enter the Configuration File (Must end with .conf): ";
$configFile = <STDIN>;
chomp($configFile);
}
#print "Found conf file $configFile!\n";
#--------------------------
# Read Configuration
#--------------------------
open (MYFILEIN, $configFile) || die "cannot open $configFile to read: $!\n";
my $line = <MYFILEIN>;
#print "config file $line\n";
close (MYFILEIN);
my ($system,$appl_name,$host, $port,$sourceName,$locl, $sleep) = split(/\s+/, $line);
#--------------------------
# Initilize UA Connection
#--------------------------
#print "Before new Uasocket";
my $uaClient = new UaSocketClient();
#print "Connection $uaClient";
$uaClient->appl($system);
$uaClient->host($host);
$uaClient->port($port);
$uaClient->locl($locl);
$uaClient->loclhost($sourceName);
#print "before connecting";
$uaClient->connect();
#--------------------------
# Initilize File to be monitored
#--------------------------
#--------------------------
# Main processing loop
#--------------------------
my $scpNames = ("perl \${OSAGENTHOME}/iostat.pl",
"perl \${OSAGENTHOME}/ioinfo.pl",
"perl \${OSAGENTHOME}/diskinfo.pl",
"perl \${OSAGENTHOME}/procinfo.pl",
"perl \${OSAGENTHOME}/bitinfo.pl",
"perl \${OSAGENTHOME}/swapinfo.pl",
"perl \${OSAGENTHOME}/meminfo.pl");
my $attrNames =('IOSTAT',
'IOINFO',
'DISKINFO',
'PROCINFO',
'BITINFO',
'SWAPINFO',
'MEMINFO');
my $APPNAME='<ApplName='.$appl_name.'>';
my $running = 1;
while ( $running ) {
my $scpCount = @scpNames;
for (my $scpInd=0;$scpInd<$scpCount;$scpInd++)
{
my $exeStr = $scpNames[$scpInd];
my $attrNameStr = $attrNames[$scpInd];
#print "Before Printing $exeStr\n";
my @lines = `$exeStr`;
## adding the application name and attributeName into package
my $lineCount = @lines;
for(my $i=0; $i<$lineCount; $i++)
{
$lines[$i]=$APPNAME.'<AttrGroup='."$attrNameStr".'>'.$lines[$i];
};
$uaClient->send(@lines);
};
#begin to sleep.
#print "===================\n";
for ( my $i = 0; $i < $sleep && $running; $i++ ) {
sleep(1);
open RUNFILE, "/tivoli/os.run" or $running = undef;
close RUNFILE;
}
}
#--------------------------
# Houskeeping
#--------------------------
$uaClient->disconnect();
print "done!\n"; |
|