--- projects/cms/source/host/ihost-perl/ihost.pl 2001/11/21 10:08:20 1.42 +++ projects/cms/source/host/ihost-perl/ihost.pl 2001/12/18 03:51:11 1.43 @@ -8,7 +8,7 @@ # a typical Unix/Linux box. # # $Author: tdb $ -# $Id: ihost.pl,v 1.42 2001/11/21 10:08:20 tdb Exp $ +# $Id: ihost.pl,v 1.43 2001/12/18 03:51:11 tdb Exp $ #------------------------------------------------------------ $| = 1; @@ -275,18 +275,18 @@ sub send_udp_packet() { $ip = inet_ntoa(scalar(gethostbyname(hostname())) || 'localhost') or $ip = 'localhost'; # add some extra data to the array - push(@data, "packet.attributes.seq_no=$seq_no"); - push(@data, "packet.attributes.machine_name=$fqdn"); - push(@data, "packet.attributes.date=$date"); - push(@data, "packet.attributes.type=data"); - push(@data, "packet.attributes.ip=$ip"); + push(@data, "packet.attributes.seq_no $seq_no"); + push(@data, "packet.attributes.machine_name $fqdn"); + push(@data, "packet.attributes.date $date"); + push(@data, "packet.attributes.type data"); + push(@data, "packet.attributes.ip $ip"); # sort the data - @data = sort(@data); - + @data = sort(grep(!/^$/, grep(/^packet\./, @data))); + # turn the array into some nice XML my($xml) = &make_xml("", ""); - + my($sock) = new IO::Socket::INET ( PeerPort => $udp_port, PeerAddr => $filter_addr, @@ -407,27 +407,43 @@ sub make_xml() { my($curlevel, $curline) = @_; my($xmltemp) = ""; my($curtag) = ""; my($attributes) = ""; while(1) { - $curline = shift(@data) if $curline eq ""; chomp $curline; + $curline = shift(@data) if $curline eq ""; + return $xmltemp if not defined $curline; + chomp $curline; + # dealing with nest (or attributes) if($curline =~ /^$curlevel([^\.\s]+\.)/) { $curtag=$1; + if($curline =~ /^$curlevel$curtag([^\.\s]+)\s+(.*)$/) { + $xmltemp .= &make_xml("$curlevel$curtag", $curline); + } + elsif($curline =~ /^$curlevel$curtag(attributes)\.([^\.\s]+)\s+(.*)$/) { + $attributes .= " $2=\"$3\""; + } + else { + $xmltemp .= &make_xml("$curlevel$curtag", $curline); + } + my($nextline) = $data[0]; chomp $nextline if defined $nextline; + if((defined $nextline) && ($nextline =~ /^$curlevel$curtag/)) { + $curline = ""; + } + else { + $curtag =~ s/(.*)\./$1/; + $xmltemp = "<$curtag$attributes>$xmltemp" unless $curtag eq ""; + return $xmltemp; + } } - if($curline =~ /^$curlevel$curtag([^\.\s]+)\s+(.*)$/) { - $xmltemp .= "<$1$attributes>$2"; - } - elsif($curline =~ /^$curlevel$curtag(attributes)\.([^\.=]+)=(.*)$/) { - $attributes .= " $2=\"$3\""; - } - else { - $xmltemp .= &make_xml("$curlevel$curtag", $curline); - } - my($nextline) = $data[0]; chomp $nextline if defined $nextline; - $curtag =~ s/(.*)\./$1/; - if((defined $nextline) && ($nextline =~ /^$curlevel$curtag\./)) { - $curline = ""; - } - else { - $xmltemp = "<$curtag$attributes>$xmltemp" unless $curtag eq ""; - return $xmltemp; + # dealing with value + elsif($curline =~ /^$curlevel([^\.\s]+)\s+(.*)$/) { + $curtag=$1; + $xmltemp=$2; + my($nextline) = $data[0]; chomp $nextline if defined $nextline; + if(defined $nextline && ($nextline =~ /^$curlevel$curtag\./ || $nextline =~ /^$curlevel$curtag\s+/)) { + $curline = ""; + } + else { + $xmltemp = "<$curtag$attributes>$xmltemp" unless $curtag eq ""; + return $xmltemp; + } } } }