mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-31 03:12:30 +00:00 
			
		
		
		
	some responses for monitoring batch events on SN or HMC
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@8111 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
		| @@ -0,0 +1,8 @@ | ||||
| #!/usr/bin/perl | ||||
|  | ||||
| $RES::EventResponse{'MsgRootBatchEvents_H'} = { | ||||
| 	Name => q(MsgRootBatchEvents_H), | ||||
| 	Locked => q(0), | ||||
| 	Actions => q({[msgEvent,{127},{0},{86400},/opt/xcat/sbin/rmcmon/msg-hierarchical-batch-event root -d,3,0,0,0,{},0]}), | ||||
| }; | ||||
| 1; | ||||
| @@ -85,7 +85,16 @@ my $dirname="/tmp/batch_process/"; | ||||
| if (! -d $dirname) { | ||||
|     mkdir($dirname); | ||||
| } | ||||
| my $cmd="scp $sn_name:$filename $dirname/$bn"; | ||||
|  | ||||
| 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"; | ||||
| @@ -126,14 +135,18 @@ for ($count = 1; $count <= $num_events; $count++) { | ||||
| }    | ||||
|      | ||||
| #send the mail out | ||||
| `echo "$msg"| mail -s "$severity $type: $ENV{ERRM_COND_NAME}" $user`; | ||||
| `echo "$msg"| mail -s "xxx$severity $type: $ENV{ERRM_COND_NAME}" $user`; | ||||
|  | ||||
| #delete the batch file on the mn | ||||
| `rm $dirname/$bn`; | ||||
|  | ||||
| #remove the batch file on the sn if needed | ||||
| if ($delete) { | ||||
|     `ssh -l root $sn_name "rm $filename"`; | ||||
|     if ($isHMC) { | ||||
| 	`ssh -l hscroot $sn_name "rm $filename"`; | ||||
|     } else { | ||||
| 	`ssh -l root $sn_name "rm $filename"`; | ||||
|     } | ||||
| } | ||||
|  | ||||
| exit; | ||||
|   | ||||
							
								
								
									
										159
									
								
								xCAT-rmc/scripts/msg-hierarchical-batch-event
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										159
									
								
								xCAT-rmc/scripts/msg-hierarchical-batch-event
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,159 @@ | ||||
| #!/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 $where = join(' ', @ARGV); | ||||
| my $delete=0; | ||||
| if ($where =~ /-d/) { | ||||
|     $delete=1; | ||||
| } | ||||
|  | ||||
| $where =~ 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; | ||||
| $msg .= "The following $type occurred:\n"; | ||||
| $msg .= " Event Time:  " . convertTime($EventTime) . "\n"; | ||||
| $msg .= " Condition name:  $ENV{ERRM_COND_NAME}\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; | ||||
| }    | ||||
|      | ||||
| #send the mail out | ||||
| my $rc = system(qq(echo "$msg" | write $where)) >> 8; | ||||
|  | ||||
| #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 $rc; | ||||
|  | ||||
|  | ||||
| # convert time string | ||||
| sub convertTime { | ||||
|   my ($seconds, $micro) = split(/\./, $_[0]); | ||||
|   return strftime("%A %D %T", localtime($seconds)); | ||||
| } | ||||
| @@ -4,7 +4,7 @@ | ||||
| # 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 email address as the input. | ||||
| # 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. | ||||
|  | ||||
| @@ -79,7 +79,7 @@ $msg .= "  MN Condition:  $ENV{ERRM_COND_NAME}\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:  $ResourceName\n"; | ||||
| $msg .= "  Resource Name:  $ResourceName\n"; | ||||
| $msg .= "  Time:  " . convertTime($EventTime) . " \n"; | ||||
| if (length($valuesMsg)) { | ||||
|   $msg .= "  Attributes:\n"; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user