more work for different conditons and reponses

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@8123 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
linggao 2010-11-10 19:55:16 +00:00
parent c777b41bd1
commit 011568c4fd
19 changed files with 340 additions and 27 deletions

View File

@ -685,7 +685,7 @@ sub startNodeStatusMon {
}
if ($batch) {
my $result=`startcondresp NodeReachability_Batch UpdatexCATNodeStatus_Batch 2>&1`;
my $result=`startcondresp NodeReachability_B UpdatexCATNodeStatus_B 2>&1`;
if (($?) && ($result !~ /2618-244|2618-008/)) { #started
$retcode=$?;
$retmsg="Error start node status monitoring: $result";

View File

@ -0,0 +1,12 @@
#!/usr/bin/perl
$RES::Condition{'AllServiceableEvents_HB'} = {
Name => q(AllServiceableEvents_HB),
ResourceClass => q(IBM.Condition),
EventExpression => q(LastBatchedEventFile.Saved != 0),
EventDescription => q(An event will be generated when a serviceable event occurs on a HMC. The serviceable events are monitored by a batch condition called AllServiceableEvents_B on the HMC. This condition monitors the batch condition. This way, if the mn is down, the conditions events will still be saved on the batch files on the HMC. ),
SelectionString => q(Name="AllServiceableEvents_B"),
ManagementScope => q(4),
Severity => q(0),
};
1;

View File

@ -14,11 +14,11 @@ if (exists($ENV{RSCT_VER})) {
}
}
$RES::Condition{'NodeReachability_Batch'} = {
Name => q(NodeReachability_Batch),
$RES::Condition{'NodeReachability_B'} = {
Name => q(NodeReachability_B),
ResourceClass => q(IBM.MngNode),
EventExpression => q(Status!=Status@P),
EventDescription => q(An event will be generated when a status changes),
EventDescription => q(An event will be generated when a status changes. This is a batch condition.),
ManagementScope => q(1),
EventBatchingInterval => q(60),
EventBatchingMaxEvents => q(200),

View File

@ -1,7 +1,7 @@
#!/usr/bin/perl
$RES::EventResponse{'EmailRootHierarchicalEvents'} = {
Name => q(EmailRootHierarchicalEvents),
$RES::EventResponse{'EmailRootAnyTime_H'} = {
Name => q(EmailRootAnyTime_H),
Locked => q(0),
Actions => q({[emailEvent,{127},{0},{86400},/opt/xcat/sbin/rmcmon/email-hierarchical-event root,3,0,0,0,{},0]}),
};

View File

@ -1,7 +1,7 @@
#!/usr/bin/perl
$RES::EventResponse{'EmailRootBatchEvents_H'} = {
Name => q(EmailRootBatchEvents_H),
$RES::EventResponse{'EmailRootAnyTime_HB'} = {
Name => q(EmailRootAnyTime_HB),
Locked => q(0),
Actions => q({[emailEvent,{127},{0},{86400},/opt/xcat/sbin/rmcmon/email-hierarchical-batch-event root -d,3,0,0,0,{},0]}),
};

View File

@ -11,8 +11,8 @@ if (exists($ENV{RSCT_VER})) {
if (xCAT::Utils->CheckVersion($rsct_ver, "2.3.5.0") < 0) { exit 0;}
}
$RES::EventResponse{'LogEventToTealEvenetLog_Batch'} = {
Name => q(LogEventToTealEvenetLog_Batch),
$RES::EventResponse{'LogEventToTealEvenetLog_B'} = {
Name => q(LogEventToTealEvenetLog_B),
Locked => q(0),
EventBatching => q(1),
Actions => q({[logToTeal,{127},{0},{86400},/opt/xcat/sbin/rmcmon/logeventtoteal,3,0,0,0,{},0]}),

View File

@ -11,8 +11,8 @@ if (exists($ENV{RSCT_VER})) {
if (xCAT::Utils->CheckVersion($rsct_ver, "2.3.5.0") < 0) { exit 0;}
}
$RES::EventResponse{'LogEventToxCATDatabase_Batch'} = {
Name => q(LogEventToxCATDatabase_Batch),
$RES::EventResponse{'LogEventToxCATDatabase_B'} = {
Name => q(LogEventToxCATDatabase_B),
Locked => q(0),
EventBatching => q(1),
Actions => q({[updatexCAT,{127},{0},{86400},/opt/xcat/sbin/rmcmon/logeventtoxcat,3,0,0,0,{},0]}),

View File

@ -0,0 +1,8 @@
#!/usr/bin/perl
$RES::EventResponse{'LogEvents_H'} = {
Name => q(LogEvents_H),
Locked => q(0),
Actions => q({[logEvent,{127},{0},{86400},/opt/xcat/sbin/rmcmon/log-hierarchical-event /tmp/eventlog,3,0,0,0,{},0]}),
};
1;

View File

@ -0,0 +1,8 @@
#!/usr/bin/perl
$RES::EventResponse{'LogEvents_HB'} = {
Name => q(LogEvents_HB),
Locked => q(0),
Actions => q({[logEvent,{127},{0},{86400},/opt/xcat/sbin/rmcmon/log-hierarchical-batch-event /tmp/eventlog -d,3,0,0,0,{},0]}),
};
1;

View File

@ -1,7 +1,7 @@
#!/usr/bin/perl
$RES::EventResponse{'MsgRootHierarchicalEvents'} = {
Name => q(MsgRootHierarchicalEvents),
$RES::EventResponse{'MsgEventsToRootAnyTime_H'} = {
Name => q(MsgEventsToRootAnyTime_H),
Locked => q(0),
Actions => q({[msgEvent,{127},{0},{86400},/opt/xcat/sbin/rmcmon/msg-hierarchical-event root,3,0,0,0,{},0]}),
};

View File

@ -1,7 +1,7 @@
#!/usr/bin/perl
$RES::EventResponse{'MsgRootBatchEvents_H'} = {
Name => q(MsgRootBatchEvents_H),
$RES::EventResponse{'MsgEventsToRootAnyTime_HB'} = {
Name => q(MsgEventsToRootAnyTime_HB),
Locked => q(0),
Actions => q({[msgEvent,{127},{0},{86400},/opt/xcat/sbin/rmcmon/msg-hierarchical-batch-event root -d,3,0,0,0,{},0]}),
};

View File

@ -11,8 +11,8 @@ if (exists($ENV{RSCT_VER})) {
if (xCAT::Utils->CheckVersion($rsct_ver, "2.3.5.0") < 0) { exit 0;}
}
$RES::EventResponse{'UpdatexCATNodeStatus_Batch'} = {
Name => q(UpdatexCATNodeStatus_Batch),
$RES::EventResponse{'UpdatexCATNodeStatus_B'} = {
Name => q(UpdatexCATNodeStatus_B),
Locked => q(0),
EventBatching => q(1),
Actions => q({[updatexCAT,{127},{0},{86400},/opt/xcat/sbin/rmcmon/updatexcatnodestatus,3,0,0,0,{},0]}),

View File

@ -0,0 +1,12 @@
#!/usr/bin/perl
$RES::Condition{'AllServiceableEvents_HB'} = {
Name => q(AllServiceableEvents_HB),
ResourceClass => q(IBM.Condition),
EventExpression => q(LastBatchedEventFile.Saved != 0),
EventDescription => q(An event will be generated when a serviceable event occurs on a HMC. The serviceable events are monitored by a batch condition called AllServiceableEvents_B on the HMC. This condition monitors the batch condition. This way, if the mn is down, the conditions events will still be saved on the batch files on the HMC. ),
SelectionString => q(Name="AllServiceableEvents_B"),
ManagementScope => q(4),
Severity => q(0),
};
1;

View File

@ -14,11 +14,11 @@ if (exists($ENV{RSCT_VER})) {
}
}
$RES::Condition{'NodeReachability_Batch'} = {
Name => q(NodeReachability_Batch),
$RES::Condition{'NodeReachability_B'} = {
Name => q(NodeReachability_B),
ResourceClass => q(IBM.MngNode),
EventExpression => q(Status!=Status@P),
EventDescription => q(An event will be generated when a status changes),
EventDescription => q(An event will be generated when a status changes. This is a batch condition.),
ManagementScope => q(1),
EventBatchingInterval => q(60),
EventBatchingMaxEvents => q(200),

View File

@ -11,8 +11,8 @@ if (exists($ENV{RSCT_VER})) {
if (xCAT::Utils->CheckVersion($rsct_ver, "2.3.5.0") < 0) { exit 0;}
}
$RES::EventResponse{'LogEventToTealEvenetLog_Batch'} = {
Name => q(LogEventToTealEvenetLog_Batch),
$RES::EventResponse{'LogEventToTealEvenetLog_B'} = {
Name => q(LogEventToTealEvenetLog_B),
Locked => q(0),
EventBatching => q(1),
Actions => q({[logToTeal,{127},{0},{86400},/opt/xcat/sbin/rmcmon/logeventtoteal,3,0,0,0,{},0]}),

View File

@ -11,8 +11,8 @@ if (exists($ENV{RSCT_VER})) {
if (xCAT::Utils->CheckVersion($rsct_ver, "2.3.5.0") < 0) { exit 0;}
}
$RES::EventResponse{'LogEventToxCATDatabase_Batch'} = {
Name => q(LogEventToxCATDatabase_Batch),
$RES::EventResponse{'LogEventToxCATDatabase_B'} = {
Name => q(LogEventToxCATDatabase_B),
Locked => q(0),
EventBatching => q(1),
Actions => q({[updatexCAT,{127},{0},{86400},/opt/xcat/sbin/rmcmon/logeventtoxcat,3,0,0,0,{},0]}),

View File

@ -11,8 +11,8 @@ if (exists($ENV{RSCT_VER})) {
if (xCAT::Utils->CheckVersion($rsct_ver, "2.3.5.0") < 0) { exit 0;}
}
$RES::EventResponse{'UpdatexCATNodeStatus_Batch'} = {
Name => q(UpdatexCATNodeStatus_Batch),
$RES::EventResponse{'UpdatexCATNodeStatus_B'} = {
Name => q(UpdatexCATNodeStatus_B),
Locked => q(0),
EventBatching => q(1),
Actions => q({[updatexCAT,{127},{0},{86400},/opt/xcat/sbin/rmcmon/updatexcatnodestatus,3,0,0,0,{},0]}),

View File

@ -0,0 +1,161 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
# Script to demonstrate how to parse out the event info that comes from a
# Condition that is watching another Condition in a hierarchical cluster environment.
# The condition that is being watched is a batch event. This script will go th the
# node that has the watched condition, get the event batch file. And parse the file
# and then send email to a user with the detailed info of the events in the batch file.
# The batch file will be then deleted if -d flag is set.
# To use this script, create a Response that invokes this script with user id as the input.
# Then associate the Response with a Condition that is watching Conditions on other
# nodes. When the Conditions occur, this script will wall the relevant event information.
# This info that is passed into this sample is structured as follows:
# EMS Condition/Event:
# $ENV{ERRM_COND_NAME}
# $ENV{ERRM_TYPEID}
# ...
# $ENV{ERRM_NODE_NAME} --> SN
# $ENV{ERRM_RSRC_NAME} --> SN Condition
# $ENV{ERRM_VALUE} --> SN Event: LastBatchedEventFile
# $Saved
# $FileName
# $Size
use strict;
use Getopt::Std;
use POSIX qw(strftime);
use File::Basename;
use File::Path;
my $logfn = join(' ', @ARGV);
my $delete=0;
if ($logfn =~ /-d/) {
$delete=1;
}
$logfn =~ s/-d//; #remove -d
# Convert Severity and Type environment variables from integers to strings
my @COND_SEVERITY = qw(Informational Warning Critical);
my @TYPE = ('event', 'rearm event');
my $severity=$COND_SEVERITY[$ENV{ERRM_COND_SEVERITYID}];
my $type=$TYPE[$ENV{ERRM_TYPEID }];
# Parse the ERRM_VALUE attribute, which will contain the EventOccurred structured data variable from the Condition class
# The fields in this structured data variable are documented below where we parse them out.
my $event = $ENV{ERRM_VALUE};
$event =~ s/^\[(.*)\]$/$1/; # SD variables have square brackets around them
# This parse the LastEvent
my ( # split the SD into the following fields:
$Saved, # batch file has been saved
$filename, # location of the batch file
$Size, # The size of the batch file
) = split(/,/, $event);
my $sn_condname=$ENV{ERRM_RSRC_NAME};
my $sn_name=$ENV{ERRM_NODE_NAME};
my (
$EventTime, # Time of event expressed in seconds since 1/1/1970
$EventTimeMicros, # Number of microseconds past EventTime
) = split(/,/, $ENV{ERRM_TIME});
my $msg="===================================================================\n";;
$msg .= " Event Time: " . convertTime($EventTime) . "\n";
$msg .= " Condition name: $ENV{ERRM_COND_NAME}\n";
$msg .= " Event Type: $type\n";
$msg .= " Severiry: $severity\n";
$msg .= " Condition being monitored: $sn_condname\n";
$msg .= " Node where the condition was monitored: $sn_name\n"; # do we have to use $ERRM_NODE_NAMELIST here?
$msg .= " SN batch files name: $filename\n";
#copy the batch file from sn to mn
$filename =~ s/"//g;
my $bn=basename($filename);
#printf stderr "ful path :$filename\n";
#printf stderr "base name:$bn\n";
my $dirname="/tmp/batch_process/";
if (! -d $dirname) {
mkdir($dirname);
}
my $cmd;
my $isHMC=0;
if ($filename =~ /\/home\/hscroot\/tmp/) {
$isHMC=1;
$cmd="scp hscroot\@$sn_name:$filename $dirname/$bn";
}
else {
$cmd="scp $sn_name:$filename $dirname/$bn";
}
my $rc=`$cmd 2>&1`;
if ($? != 0) {
$msg .= "$rc\n";
}
#now process the batch file
open(FILE1, "<$dirname/$bn");
readline(FILE1);#skip first 2 lines
readline(FILE1);
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:/,/ERRM_COND_BATCH/ p" $dirname/$bn`;
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 $event = "Event count: $count\n";
#$event .= " Event time: " . $content_hash{ERRM_TIME} . "\n";
$event .= " Node where the event occurred: " . $content_hash{ERRM_NODE_NAMELIST} . "\n";
$event .= " Resource class: " . $content_hash{ERRM_RSRC_CLASS_PNAME} . "\n";
$event .= " Resource name: " . $content_hash{ERRM_RSRC_NAME} . "\n";
$event .= " Attribute name: " . $content_hash{ERRM_ATTR_PNAME} . "\n";
$event .= " Attribute value: " . $content_hash{ERRM_VALUE} . "\n\n";
$msg .= $event;
}
#log the events
if (open (FILE, ">>$logfn")) {
print FILE "$msg\n";
close (FILE);
}
#delete the batch file on the mn
`rm $dirname/$bn`;
#remove the batch file on the sn if needed
if ($delete) {
if ($isHMC) {
`ssh -l hscroot $sn_name "rm $filename"`;
} else {
`ssh -l root $sn_name "rm $filename"`;
}
}
exit;
# convert time string
sub convertTime {
my ($seconds, $micro) = split(/\./, $_[0]);
return strftime("%A %D %T", localtime($seconds));
}

View File

@ -0,0 +1,112 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
# Script to demonstrate how to parse out the event info that comes from a
# Condition that is watching another Condition in a hierarchical cluster environment.
# To use this script, create a Response that invokes this script with a log file name as the input.
# Then associate the Response with a Condition that is watching Conditions on other
# nodes. When the Conditions occur, this script will wall the relevant event information.
# This info that is passed into this sample is structured as follows:
# EMS Condition/Event:
# $ENV{ERRM_COND_NAME}
# $ENV{ERRM_TYPEID}
# ...
# $ENV{ERRM_NODE_NAME} --> SN
# $ENV{ERRM_RSRC_NAME} --> SN Condition
# $ENV{ERRM_VALUE} --> SN Event:
# $Occurred
# $ErrNum
# ...
# $NodeName --> Leaf Node:
# $ResourceName --> Resource
# $Attribute 1 --> Attr 1
# $Attribute 2 --> Attr 2
use strict;
use Getopt::Std;
use POSIX qw(strftime);
use File::Path;
# Convert Severity and Type environment variables from integers to strings
my @COND_SEVERITY = qw(Informational Warning Critical);
my @TYPE = ('Event', 'Rearm event');
my $severity=$COND_SEVERITY[$ENV{ERRM_COND_SEVERITYID}];
my $type=$TYPE[$ENV{ERRM_TYPEID }];
my $filename = shift;
# Parse the ERRM_VALUE attribute, which will contain the EventOccurred structured data variable from the Condition class
# The fields in this structured data variable are documented below where we parse them out.
my $event = $ENV{ERRM_VALUE};
$event =~ s/^\[(.*)\]$/$1/; # SD variables have square brackets around them
# This parse the LastEvent
my ( # split the SD into the following fields:
$Occurred, # One if the condition has been triggered
$ErrNum, # Non-zero if there was in error in the event registration
$ErrMsg, # The string msg related to ErrNum
$EventFlags, # Bit mask giving some additional info about the event
$EventTime, # Time of event expressed in seconds since 1/1/1970
$EventTimeMicros, # Number of microseconds past EventTime
$ResourceHandle, # Binary address of the RMC resource that caused the condition to be triggered
$NodeName, # The node on which the event occurred. For conditions that use the management domain scope (4),
# this will be the leaf node. For conditions that use the local scope (e.g. NodeReachability),
# this will be the FMS.
$NumAttrs, # Number of attr values from the resource returned in this event
$NumAttrsInExpr, # How many of the above were attributes in the event expression
$IndexForAttrs, # The starting index of the array of values. Until new fixed fields are added
# to LastEvent, this will be the element right after this one.
$AttrArray # This list of attribute names, types, and values
) = split(/,/, $event, 12);
my @attrArray = split(/,/, $AttrArray); # Note: parsing this way does not support SDs or SD Arrays that may be in this list
my ($ResourceName, $valuesMsg);
my $j = 0; # index into attrArray
for (my $i=0; $i<$NumAttrs; $i++) {
my $attrName = $attrArray[$j++];
my $attrType = $attrArray[$j++]; # Types <= 8 are "simple" types. Types > 8 are SDs and arrays.
my $attrValue = $attrArray[$j++];
if ($attrName eq '"Name"') { $ResourceName = $attrValue; }
$valuesMsg .= " Attribute Value $i: $attrName = $attrValue\n";
}
if (!length($ResourceName)) { $ResourceName = '(unknown)'; }
my $msg="=============================================================================\n";
$msg .= " Time: " . convertTime($EventTime) . " \n";
$msg .= " MN Condition: $ENV{ERRM_COND_NAME}\n";
$msg .= " Severity: $severity\n";
$msg .= " Event Type: $type\n";
$msg .= " SN Condition: $ENV{ERRM_RSRC_NAME}\n";
$msg .= " SN: $ENV{ERRM_NODE_NAME}\n"; # do we have to use $ERRM_NODE_NAMELIST here?
$msg .= " Node: $NodeName\n";
$msg .= " Resource Name: $ResourceName\n";
if (length($valuesMsg)) {
$msg .= " Attributes:\n";
$msg .= $valuesMsg;
}
# Skipped the following: $ERRM_EXPR $ERRM_RSRC_CLASS_PNAME $ERRM_DATA_TYPE $ERRM_NODE_NAMELIST $ERRM_RSRC_TYPE
#$str = escape_chars($str);
if (open (FILE, ">>$filename")) {
print FILE "$msg\n";
close (FILE);
}
exit;
# convert time string
sub convertTime {
my ($seconds, $micro) = split(/\./, $_[0]);
return strftime("%A %D %T", localtime($seconds));
}