--- projects/cms/source/host/ihost-perl/ihost.pl 2001/11/14 16:41:30 1.36 +++ projects/cms/source/host/ihost-perl/ihost.pl 2001/11/20 12:47:03 1.41 @@ -8,7 +8,7 @@ # a typical Unix/Linux box. # # $Author: tdb $ -# $Id: ihost.pl,v 1.36 2001/11/14 16:41:30 tdb Exp $ +# $Id: ihost.pl,v 1.41 2001/11/20 12:47:03 tdb Exp $ #------------------------------------------------------------ $| = 1; @@ -33,7 +33,7 @@ use vars qw ( $fqdn $pidfile $retry_wait - @statgrab + @data ); if (@ARGV != 2) { @@ -47,7 +47,11 @@ $seq_no = 1; $retry_wait = 60; # write our PID to a file -$pidfile = "/var/tmp/ihost.pid"; +# use home dir by default +$pidfile = $ENV{"HOME"}; +# or drop it in /var/tmp if we can't find HOME +$pidfile = "/var/tmp" if not defined $pidfile; +$pidfile .= "/.ihost.pid"; &write_pid(); &tcp_configure(); @@ -257,20 +261,29 @@ sub tcp_configure() { #----------------------------------------------------------------------- sub send_udp_packet() { - @statgrab = `./statgrab.pl`; + my($plugins_dir) = "plugins"; + 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"; + } + # get some extra data my($date) = time; my($ip); $ip = inet_ntoa(scalar(gethostbyname(hostname())) || 'localhost') or $ip = 'localhost'; # add some extra data to the array - push(@statgrab, "packet.attributes.seq_no=$seq_no"); - push(@statgrab, "packet.attributes.machine_name=$fqdn"); - push(@statgrab, "packet.attributes.date=$date"); - push(@statgrab, "packet.attributes.type=data"); - push(@statgrab, "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); + # turn the array into some nice XML my($xml) = &make_xml("", ""); @@ -388,13 +401,13 @@ sub write_pid() { #----------------------------------------------------------------------- # make_xml -# Turns an array of statgrab data into an XML string. +# Turns an array of plugins data into an XML string. #----------------------------------------------------------------------- sub make_xml() { my($curlevel, $curline) = @_; my($xmltemp) = ""; my($curtag) = ""; my($attributes) = ""; - while(true) { - $curline = shift(@statgrab) if $curline eq ""; chomp $curline; + while(1) { + $curline = shift(@data) if $curline eq ""; chomp $curline; if($curline =~ /^$curlevel([^\.\s]+\.)/) { $curtag=$1; } @@ -407,9 +420,9 @@ sub make_xml() { else { $xmltemp .= &make_xml("$curlevel$curtag", $curline); } - my($nextline) = $statgrab[0]; chomp $nextline if defined $nextline; + my($nextline) = $data[0]; chomp $nextline if defined $nextline; $curtag =~ s/(.*)\./$1/; - if(defined $nextline && $nextline =~ /^$curlevel$curtag\./) { + if((defined $nextline) && ($nextline =~ /^$curlevel$curtag\./)) { $curline = ""; } else {