--- projects/cms/source/host/ihost-perl/ihost.pl 2001/02/05 17:38:38 1.15 +++ projects/cms/source/host/ihost-perl/ihost.pl 2001/03/06 08:38:42 1.24 @@ -10,7 +10,7 @@ # - pjm2@ukc.ac.uk # # $Author: pjm2 $ -# $Id: ihost.pl,v 1.15 2001/02/05 17:38:38 pjm2 Exp $ +# $Id: ihost.pl,v 1.24 2001/03/06 08:38:42 pjm2 Exp $ #------------------------------------------------------------ $| = 1; @@ -32,6 +32,7 @@ use vars qw ( $tcp_port $filter_addr $file_list + $fqdn ); if (@ARGV != 2) { @@ -85,7 +86,7 @@ sub tcp_configure() { PeerAddr => $filter_manager_addr, PeerPort => $filter_manager_port, Proto => 'tcp' - ); + ) or die "Cannot connect!"; if (!defined $sock) { print "IHOST ERROR: Could not connect to $filter_manager_addr:$filter_manager_port.\n"; print "Please check that there is an i-scream server at this address.\n"; @@ -119,6 +120,13 @@ sub tcp_configure() { print "File list obtained: $file_list\n"; + print $sock "FQDN\n"; + $response = <$sock>; + chop $response; + $fqdn = $response; + + print "FQDN returned: $fqdn\n"; + print $sock "UDPUpdateTime\n"; $response = <$sock>; chop $response; @@ -143,9 +151,17 @@ sub tcp_configure() { print $sock "FILTER\n"; $response = <$sock>; + unless (defined($response)) { + print "Failed: Could not get a filter address from the filter manager.\n"; + exit(1); + } chop $response; $response =~ /(.*);(.*);(.*)/; ($filter_addr, $udp_port, $tcp_port) = ($1, $2, $3); + unless (defined($filter_addr) && defined($udp_port) && defined($tcp_port)) { + print "Failed: Filter address response from server did not make sense: $response\n"; + exit(1); + } print "Got filter data ($filter_addr, $udp_port, $tcp_port)\n"; @@ -201,12 +217,7 @@ sub send_udp_packet() { } $disk_info .= ""; - my($hostname) = hostname(); - $hostname =~ s/\..*$//g; - `cat /etc/resolv.conf` =~ /domain\s+([^\s]+)/; - my($domainname) = $1; - my($machine_name) = "$hostname.$domainname"; - my($ip) = inet_ntoa(scalar(gethostbyname($hostname)) || 'localhost'); + my($ip) = inet_ntoa(scalar(gethostbyname(hostname())) || 'localhost'); # Build the XML packet this way, as we can clearly # see the structure and contents... I like this ;-) @@ -214,7 +225,7 @@ sub send_udp_packet() { # larger than 8196 bytes] my($xml) = < + $packet{"packet.load.load1"} $packet{"packet.load.load5"} @@ -261,12 +272,12 @@ EOF # Make the packet smaller by stripping out newlines and leading spaces. $xml =~ s/\n\s*//g; - + my($sock) = new IO::Socket::INET ( PeerPort => $udp_port, PeerAddr => $filter_addr, Proto => 'udp' - ) or die "Socket: $!\n"; + ) or die "Could not send UDP: $!\n"; print $sock $xml or die "Could not send UDP packet: $!\n"; close($sock); @@ -290,7 +301,7 @@ sub send_tcp_heartbeat() { PeerAddr => $filter_addr, PeerPort => $tcp_port, Proto => 'tcp' - ); + ) or return; if (!defined $sock) { print "IHOST WARNING: Failed to deliver a heartbeat to the i-scream filter.\n"; return; @@ -301,6 +312,7 @@ sub send_tcp_heartbeat() { print $sock "HEARTBEAT\n"; $response = <$sock>; + return if (!defined $response); chop $response; if (!$response eq "OK") { close($sock); @@ -310,6 +322,7 @@ sub send_tcp_heartbeat() { print $sock "CONFIG\n"; $response = <$sock>; + return if (!defined $response); chop $response; if (!$response eq "OK") { close($sock); @@ -319,6 +332,7 @@ sub send_tcp_heartbeat() { print $sock "$file_list\n"; $response = <$sock>; + return if (!defined $response); chop $response; if (!$response eq "OK") { close($sock); @@ -328,6 +342,7 @@ sub send_tcp_heartbeat() { print $sock "$last_modified\n"; $response = <$sock>; + return if (!defined $response); chop $response; if ($response eq "ERROR") { close($sock); @@ -342,6 +357,7 @@ sub send_tcp_heartbeat() { print $sock "ENDHEARTBEAT\n"; $response = <$sock>; + return if (!defined $response); chop $response; if (!$response eq "OK") { close($sock);