add option '-s' for reventlog to output the event from latest to oldest

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@15502 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
zhaoertao 2013-03-14 07:12:37 +00:00
parent dea73cdb01
commit bc44b57b73
3 changed files with 88 additions and 15 deletions

View File

@ -60,7 +60,7 @@ my %usage = (
BMC specific:
rvitals noderange {temp|voltage|wattage|fanspeed|power|leds|lcds|summary|all}",
"reventlog" =>
"Usage: reventlog <noderange> [all|clear|<number of entries to retrieve>] [-V|--verbose]
"Usage: reventlog <noderange> [all [-s]|clear|<number of entries to retrieve> [-s]] [-V|--verbose]
reventlog [-h|--help|-v|--version]",
"rinv" =>
"Usage:

View File

@ -362,16 +362,37 @@ sub eventlog { #Tried various optimizations, but MM seems not to do bulk-request
#TODO: try retrieving 5 at a time, then 1 at a time when that stops working
@ARGV=@_;
my $force;
GetOptions(
"f" => \$force,
);
my $cmd=shift @ARGV;
#GetOptions(
# "f" => \$force,
# );
my $cmd = undef;
my $order = undef;
my $arg = shift @ARGV;
while ($arg) {
if ($arg eq "all" or $arg eq "clear" or $arg =~/^\d+$/) {
if (defined($cmd)) {
return(1, "reventlog $cmd $arg invalid");
}
$cmd = $arg;
} elsif ($arg =~ /^-s$/) {
$order = 1;
} elsif ($arg =~ /^-f$/) {
$force = 1;
} else {
return(1, "unsupported command reventlog $arg");
}
$arg = shift @ARGV;
}
my $data;
my @output;
my $oid = $eventlogoid;
unless ($cmd) {
$cmd='all';
}
if (defined($force) and $cmd ne "clear") {
return(1, "option \"-f\" can only work with \"clear\"");
}
if ($cmd eq 'all') {
$cmd=65535; #no MM has this many logs possible, should be a good number
}
@ -413,15 +434,29 @@ sub eventlog { #Tried various optimizations, but MM seems not to do bulk-request
$matchstring="^(?!NODE).*";
}
if ($source =~ m/$matchstring$/i) { #MM guys changed their minds on capitalization
$numentries++;
unshift @output,"$sev:$date $time $text"; #unshift to get it in a sane order
if (defined($order)) {
$numentries++;
push @output, "$sev:$date $time $text";
} else {
unshift @output,"$sev:$date $time $text"; #unshift to get it in a sane order
if ($#output >= $requestednumber) {
pop @output;
}
}
} else {
foreach (@moreslots) {
#$matchstring=sprintf("BLADE_%02d",$_);
$matchstring=sprintf("NODE_%02d",$_);
if ($source =~ m/$matchstring$/i) { #MM guys changed their minds on capitalization
$numentries++;
unshift @output,"$sev:$date $time $text"; #unshift to get it in a sane order
if (defined($order)) {
$numentries++;
push @output, "$sev:$date $time $text";
} else {
unshift @output,"$sev:$date $time $text"; #unshift to get it in a sane order
if ($#output >= $requestednumber) {
pop @output;
}
}
}
}
}

View File

@ -3246,6 +3246,7 @@ sub readauxentry {
sub eventlog {
my $sessdata = shift;
my $subcommand = $sessdata->{subcommand};
my $cmdargv = $sessdata->{extraargs};
unless ($sessdata) { die "not fixed yet" }
my $netfun = 0x0a;
@ -3265,6 +3266,23 @@ sub eventlog {
#device id needed here
$rc=0;
#reventlog <node> [[all] [-s] | <num> [-s]| clear]
$subcommand = undef;
my $arg = shift(@$cmdargv);
while ($arg) {
if ($arg eq "all" or $arg eq "clear" or $arg =~ /^\d+$/) {
if (defined($subcommand)) {
return(1,"revenglog $subcommand $arg invalid");
}
$subcommand = $arg;
} elsif ($arg =~ /^-s$/) {
$sessdata->{sort}=1;
} else {
return(1,"unsupported command eventlog $arg");
}
$arg = shift(@$cmdargv);
}
unless (defined($subcommand)) {
$subcommand = 'all';
}
@ -3272,6 +3290,9 @@ sub eventlog {
$sessdata->{fullsel}=1;
}
elsif($subcommand eq "clear") {
if (exists($sessdata->{sort})) {
return(1,"option \"first\" can not work with $subcommand");
}
}
elsif($subcommand =~ /^\d+$/) {
$sessdata->{numevents} = $subcommand;
@ -3280,6 +3301,7 @@ sub eventlog {
else {
return(1,"unsupported command eventlog $subcommand");
}
$sessdata->{subcommand} = $subcommand;
$sessdata->{ipmisession}->subcmd(netfn=>0xa,command=>0x48,data=>[],callback=>\&eventlog_with_time,callback_args=>$sessdata);
}
sub eventlog_with_time {
@ -3348,7 +3370,11 @@ sub eventlog_with_selinfo {
}
$sessdata->{selentries} = [];
$sessdata->{selentry}=0;
$sessdata->{ipmisession}->subcmd(netfn=>0xa,command=>0x43,data=>[0,0,0x00,0x00,0x00,0xFF],callback=>\&got_sel,callback_args=>$sessdata);
if (exists($sessdata->{sort})) {
$sessdata->{ipmisession}->subcmd(netfn=>0xa,command=>0x43,data=>[0,0,0xFF,0xFF,0x00,0xFF],callback=>\&got_sel,callback_args=>$sessdata);
} else {
$sessdata->{ipmisession}->subcmd(netfn=>0xa,command=>0x43,data=>[0,0,0x00,0x00,0x00,0xFF],callback=>\&got_sel,callback_args=>$sessdata);
}
}
sub got_sel {
if (check_rsp_errors(@_)) {
@ -3363,10 +3389,20 @@ sub got_sel {
#}
my $next_rec_ls = $returnd[1];
my $next_rec_ms = $returnd[2];
my $next_rec_ls;
my $next_rec_ms;
my @sel_data = @returnd[3..19];
if (exists($sessdata->{sort})) {
$next_rec_ls = $sel_data[0] - 1;
$next_rec_ms = $sel_data[1];
if (($next_rec_ls < 0) && ($next_rec_ms > 0)) {
$next_rec_ls += 256;
$next_rec_ms -= 1;
}
} else {
$next_rec_ls = $returnd[1];
$next_rec_ms = $returnd[2];
}
$sessdata->{selentry}+=1;
if ($debug) {
print $sessdata->{selentry}.": ";
@ -3389,7 +3425,8 @@ sub got_sel {
} else {
push(@{$sessdata->{selentries}},$text);
}
if($next_rec_ms == 0xFF && $next_rec_ls == 0xFF) {
if(($next_rec_ms == 0xFF && $next_rec_ls == 0xFF) or
($next_rec_ms == 0x0 && $next_rec_ls == 0x0)) {
sendsel($sessdata);
return;
}
@ -3531,7 +3568,8 @@ sub got_sel {
}
}
if($next_rec_ms == 0xFF && $next_rec_ls == 0xFF) {
if(($next_rec_ms == 0xFF && $next_rec_ls == 0xFF) or
($next_rec_ms == 0x0 && $next_rec_ls == 0x0)) {
sendsel($sessdata);
return;
}