web_lsevent is rewritten

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4757 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
mxi1 2009-12-11 02:38:34 +00:00
parent 687bb27418
commit 81610b3c9c

View File

@ -79,39 +79,40 @@ sub web_lsdef {
sub web_lsevent {
my ($request, $callback, $sub_req) = @_;
my $ret = `$request->{arg}->[0]`;
#please see the manpage for "lsevent" to see the output format
my @ret = `$request->{arg}->[0]`;
my @lines = split '\n', $ret;
#print Dumper(\@ret);
#please refer the manpage for the output format of "lsevent"
my $length = scalar @lines;
my $line = 0;
my %data = ();
while($line < $length) {
split "=", $lines[$line];
my $time = $_[1];
my %record = ();
split "=", $lines[$line+1];
my $cate = $_[1];
split "=", $lines[$line+2];
my $event = $_[1];
$data{$line} = {
"time" => $time,
"category" => $cate,
"event" => $event
};
$line +=4;
my $i = 0;
my $j = 0;
foreach my $item (@ret) {
if($item ne "\n") {
chomp $item;
my ($key, $value) = split("=", $item);
$record{$key} = $value;
$j ++;
if($j == 3) {
$i++;
$j = 0;
while (my ($k, $v) = each %record) {
$data{$i}{$k} = $v;
}
%record = ();
}
}
}
#print Dumper(\%data);
foreach my $key ( sort keys %data) {
$callback->({data => \%{$data{$key}}});
while (my ($key, $value) = each %data) {
$callback->({data => $value});
}
}