added support for logging batching events into xCAT DB
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@2695 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
4a9653f746
commit
94ade30137
@ -2943,4 +2943,47 @@ sub logEventsToDatabase{
|
||||
return (0, "");
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 CheckVersion
|
||||
Checks the two versions numbers to see which one is greater.
|
||||
Arguments:
|
||||
ver_a the version number in format of d.d.d.d...
|
||||
ver_b the version number in format of d.d.d.d...
|
||||
Returns:
|
||||
1 if ver_a is greater than ver_b
|
||||
0 if ver_a is eaqual to ver_b
|
||||
-1 if ver_a is smaller than ver_b
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
sub CheckVersion {
|
||||
my $ver_a=shift;
|
||||
if ($ver_a =~ /xCAT::Utils/) {
|
||||
$ver_a=shift;
|
||||
}
|
||||
my $ver_b=shift;
|
||||
|
||||
my @a=split(/\./,$ver_a);
|
||||
my @b=split(/\./,$ver_b);
|
||||
my $len_a=@a;
|
||||
my $len_b=@b;
|
||||
|
||||
my $index=0;
|
||||
my $max_index=($len_a>$len_b) ? $len_a : $len_b;
|
||||
|
||||
for ($index=0; $index <= $max_index; $index++) {
|
||||
my $val_a=($len_a < $index) ? 0 : $a[$index];
|
||||
my $val_b=($len_b < $index) ? 0 : $b[$index];
|
||||
if ($val_a > $val_b) { return 1;}
|
||||
if ($val_a < $val_b) { return -1;}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
@ -438,15 +438,27 @@ sub config {
|
||||
}
|
||||
|
||||
#create conditions/responses/sensors on the service node or mn
|
||||
my $result=`$::XCATROOT/sbin/rmcmon/mkrmcresources $::XCATROOT/lib/perl/xCAT_monitoring/rmc/resources/sn 2>&1`;
|
||||
my $result=`/usr/sbin/rsct/install/bin/ctversion`;
|
||||
my $rsct_ver;
|
||||
if (!$?) {
|
||||
chomp($result);
|
||||
my @tempa=split(/ /, $result);
|
||||
if (@tempa>1) {
|
||||
$rsct_ver=$tempa[1];
|
||||
}
|
||||
}
|
||||
my $version_string;
|
||||
if ($rsct_ver) {$version_string="RSCT_VER=$rsct_ver"; }
|
||||
|
||||
my $result=`$version_string $::XCATROOT/sbin/rmcmon/mkrmcresources $::XCATROOT/lib/perl/xCAT_monitoring/rmc/resources/sn 2>&1`;
|
||||
if ($?) {
|
||||
my $error= "Error when creating predefined resources on $localhostname:\n$result";
|
||||
reportError($error, $callback);
|
||||
}
|
||||
if ($isSV) {
|
||||
$result=`$::XCATROOT/sbin/rmcmon/mkrmcresources $::XCATROOT/lib/perl/xCAT_monitoring/rmc/resources/node 2>&1`;
|
||||
$result=`$version_string $::XCATROOT/sbin/rmcmon/mkrmcresources $::XCATROOT/lib/perl/xCAT_monitoring/rmc/resources/node 2>&1`;
|
||||
} else {
|
||||
$result=`$::XCATROOT/sbin/rmcmon/mkrmcresources $::XCATROOT/lib/perl/xCAT_monitoring/rmc/resources/mn 2>&1`;
|
||||
$result=`$version_string $::XCATROOT/sbin/rmcmon/mkrmcresources $::XCATROOT/lib/perl/xCAT_monitoring/rmc/resources/mn 2>&1`;
|
||||
}
|
||||
if ($?) {
|
||||
my $error= "Error when creating predefined resources on $localhostname:\n$result";
|
||||
|
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/perl
|
||||
BEGIN
|
||||
{
|
||||
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
||||
}
|
||||
use lib "$::XCATROOT/lib/perl";
|
||||
use xCAT::Utils;
|
||||
|
||||
if (exists($ENV{RSCT_VER})) {
|
||||
my $rsct_ver=$ENV{RSCT_VER};
|
||||
if (xCAT::Utils->CheckVersion($rsct_ver, "2.3.5.0") < 0) { exit 0;}
|
||||
}
|
||||
|
||||
$RES::EventResponse{'LogEventToxCATDatabase_Batch'} = {
|
||||
Name => q(LogEventToxCATDatabase_Batch),
|
||||
Locked => q(0),
|
||||
EventBatching => q(1),
|
||||
Actions => q({[updatexCAT,{127},{0},{86400},/opt/xcat/sbin/rmcmon/logeventtoxcat,3,0,0,0,{},0]}),
|
||||
};
|
||||
1;
|
@ -14,17 +14,15 @@ use Getopt::Std;
|
||||
use POSIX qw(strftime);
|
||||
use xCAT::Utils;
|
||||
use xCAT::MsgUtils;
|
||||
use IO::File;
|
||||
|
||||
#`echo "---------------" >> /tmp/ling.log`;
|
||||
#foreach(keys %ENV) {
|
||||
# my $s="$_=" . $ENV{$_};
|
||||
# `echo $s >> /tmp/ling.log`;
|
||||
#}
|
||||
|
||||
my $batch=$ENV{ERRM_COND_BATCH};
|
||||
my $batch=0;
|
||||
if (exists($ENV{ERRM_COND_BATCH})) { $batch=$ENV{ERRM_COND_BATCH}; }
|
||||
my @a=();
|
||||
my $condname=$ENV{ERRM_COND_NAME};
|
||||
my $respname=$ENV{ERRM_ER_NAME};
|
||||
|
||||
if (!$batch) {
|
||||
if (!$batch) { #handle single event
|
||||
my $time=$ENV{ERRM_TIME};
|
||||
my $nodenamelist=$ENV{ERRM_NODE_NAMELIST};
|
||||
$nodenamelist =~ s/\{(.*)\}/$1/;
|
||||
@ -43,14 +41,63 @@ if (!$batch) {
|
||||
};
|
||||
|
||||
push(@a, $event);
|
||||
} else {
|
||||
xCAT::MsgUtils->message('S', "logeventtoxcat:batching is not supported by this script yet.\n");
|
||||
exit 0;
|
||||
} else { #handle event batching
|
||||
if ($ENV{ERRM_COND_BATCH_NUM} > 0) {
|
||||
#check if event detail file exist
|
||||
if (!exists($ENV{ERRM_EVENT_DETAIL_FILE})){
|
||||
xCAT::MsgUtils->message('S', "logeventtoxcat: no event detail file specified in the response $respname for condition $condname.\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
my $filename=$ENV{ERRM_EVENT_DETAIL_FILE};
|
||||
if (! -f $filename) {
|
||||
xCAT::MsgUtils->message('S', "logeventtoxcat: cannot find event detail file $filename in response $respname for condition $condname.\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
open(FILE1, "<$filename");
|
||||
my $line1=readline(FILE1);
|
||||
my @aTemp=split(/=/, $line1);
|
||||
my $num_events=$aTemp[1];
|
||||
close(FILE1);
|
||||
|
||||
my $count;
|
||||
for ($count = 1; $count <= $num_events; $count++) {
|
||||
my $content=`sed -n "/Event $count/, /(null)/ p" $filename`;
|
||||
|
||||
my @content_array=split(/\n/, $content);
|
||||
pop(@content_array); #get rid of last line
|
||||
shift(@content_array); #get rid of firt line
|
||||
|
||||
my %content_hash=();
|
||||
foreach(@content_array) {
|
||||
/([^\=]+)\=(.*)/;
|
||||
$content_hash{$1}=$2;
|
||||
}
|
||||
|
||||
my $time=$content_hash{ERRM_TIME};
|
||||
my $nodenamelist=$content_hash{ERRM_NODE_NAMELIST};
|
||||
$nodenamelist =~ s/\{(.*)\}/$1/;
|
||||
my $event={
|
||||
eventtype => $content_hash{ERRM_TYPE},
|
||||
monitor => $content_hash{ERRM_COND_NAME},
|
||||
monnode => $content_hash{ERRM_NODE_NAME},
|
||||
node => $nodenamelist,
|
||||
application => 'RMC',
|
||||
component => $content_hash{ERRM_RSRC_CLASS_PNAME},
|
||||
id => $content_hash{ERRM_RSRC_NAME} . "," . $content_hash{ERRM_ATTR_PNAME},
|
||||
severity => $content_hash{ERRM_COND_SEVERITY},
|
||||
message => '',
|
||||
rawdata => $content_hash{ERRM_ATTR_PNAME} . "=" . $content_hash{ERRM_VALUE},
|
||||
};
|
||||
push(@a, $event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my ($rc, $msg)=xCAT::Utils->logEventsToDatabase(\@a);
|
||||
if ($rc) {
|
||||
xCAT::MsgUtils->message('S', "logeventtoxcat:$msg\n");
|
||||
xCAT::MsgUtils->message('S', "logeventtoxcat:$msg. The condition is $condname. The response is $respname.\n");
|
||||
}
|
||||
|
||||
exit $rc;
|
||||
|
@ -1138,7 +1138,7 @@ sub getAllRegs
|
||||
my %names=();
|
||||
my $table=xCAT::Table->new("monitoring", -create =>1);
|
||||
if ($table) {
|
||||
my $tmp1=$table->getAllEntries();
|
||||
my $tmp1=$table->getAllEntries("all");
|
||||
if (defined($tmp1) && (@$tmp1 > 0)) {
|
||||
foreach(@$tmp1) {
|
||||
my $monnode=0;
|
||||
@ -1190,7 +1190,7 @@ sub config {
|
||||
if (@product_names == 0) {
|
||||
@product_names=keys(%all);
|
||||
}
|
||||
|
||||
|
||||
print "------config: product_names=@product_names\n";
|
||||
|
||||
foreach(@product_names) {
|
||||
@ -1312,7 +1312,7 @@ sub getNodeConfData {
|
||||
my %names=();
|
||||
my $table=xCAT::Table->new("monitoring", -create =>1);
|
||||
if ($table) {
|
||||
my $tmp1=$table->getAllEntries();
|
||||
my $tmp1=$table->getAllEntries("all");
|
||||
if (defined($tmp1) && (@$tmp1 > 0)) {
|
||||
foreach(@$tmp1) { $names{$_->{name}}=1; }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user