--- projects/cms/source/host/ihost-perl/ihost.pl 2001/12/18 03:51:11 1.43 +++ projects/cms/source/host/ihost-perl/ihost.pl 2002/03/21 17:57:13 1.47 @@ -8,7 +8,7 @@ # a typical Unix/Linux box. # # $Author: tdb $ -# $Id: ihost.pl,v 1.43 2001/12/18 03:51:11 tdb Exp $ +# $Id: ihost.pl,v 1.47 2002/03/21 17:57:13 tdb Exp $ #------------------------------------------------------------ $| = 1; @@ -33,6 +33,8 @@ use vars qw ( $fqdn $pidfile $retry_wait + $ostype + $key @data ); @@ -46,6 +48,11 @@ $filter_manager_port = $ARGV[1]; $seq_no = 1; $retry_wait = 60; +# work out our platform, if we can. +$ostype = `uname -s`; +chomp $ostype; +$ostype = "unknown" if not defined $ostype; + # write our PID to a file # use home dir by default #$pidfile = $ENV{"HOME"}; @@ -55,6 +62,7 @@ $pidfile .= "/.ihost.pid"; &write_pid(); &tcp_configure(); +&send_tcp_heartbeat(); &send_udp_packet(); $last_udp_time = time; @@ -266,7 +274,7 @@ sub send_udp_packet() { opendir PLUGINS, $plugins_dir; my(@plugins) = readdir PLUGINS; foreach my $plugin (@plugins) { - push @data, `$plugins_dir/$plugin` if -x "$plugins_dir/$plugin" && -f "$plugins_dir/$plugin"; + push @data, `$plugins_dir/$plugin $ostype` if -x "$plugins_dir/$plugin" && -f "$plugins_dir/$plugin"; } # get some extra data @@ -280,6 +288,7 @@ sub send_udp_packet() { push(@data, "packet.attributes.date $date"); push(@data, "packet.attributes.type data"); push(@data, "packet.attributes.ip $ip"); + push(@data, "packet.attributes.key $key"); # sort the data @data = sort(grep(!/^$/, grep(/^packet\./, @data))); @@ -368,6 +377,9 @@ sub send_tcp_heartbeat() { return; } + print $sock "KEY\n"; + $key = <$sock>; + print $sock "ENDHEARTBEAT\n"; $response = <$sock>; if (!$response eq "OK\n") { @@ -423,11 +435,11 @@ sub make_xml() { $xmltemp .= &make_xml("$curlevel$curtag", $curline); } my($nextline) = $data[0]; chomp $nextline if defined $nextline; - if((defined $nextline) && ($nextline =~ /^$curlevel$curtag/)) { + $curtag =~ s/(.*)\./$1/; + if((defined $nextline) && ($nextline =~ /^$curlevel$curtag\./)) { $curline = ""; } else { - $curtag =~ s/(.*)\./$1/; $xmltemp = "<$curtag$attributes>$xmltemp" unless $curtag eq ""; return $xmltemp; } @@ -445,5 +457,15 @@ sub make_xml() { return $xmltemp; } } + # dealing with a null value + elsif($curline =~ /^$curlevel([^\.\s]+)$/) { + # simply adding a space makes the above elsif deal with it :) + # just level with an empty tag in the XML + $curline .= " "; + } + # failing all that, skip the line + else { + $curline = ""; + } } }