From 81610b3c9c17930d888ce162cf761cd1ad3b33a6 Mon Sep 17 00:00:00 2001 From: mxi1 Date: Fri, 11 Dec 2009 02:38:34 +0000 Subject: [PATCH] web_lsevent is rewritten git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4757 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/lib/xcat/plugins/web.pm | 49 +++++++++++++++-------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/web.pm b/xCAT-server/lib/xcat/plugins/web.pm index 81759cad3..134dc2022 100644 --- a/xCAT-server/lib/xcat/plugins/web.pm +++ b/xCAT-server/lib/xcat/plugins/web.pm @@ -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}); } }