ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/ihost-perl/ihost.pl
(Generate patch)

Comparing projects/cms/source/host/ihost-perl/ihost.pl (file contents):
Revision 1.16 by tdb, Tue Feb 13 12:28:50 2001 UTC vs.
Revision 1.24 by pjm2, Tue Mar 6 08:38:42 2001 UTC

# Line 32 | Line 32 | use vars qw (
32               $tcp_port
33               $filter_addr
34               $file_list
35 +             $fqdn
36              );
37  
38   if (@ARGV != 2) {
# Line 85 | Line 86 | sub tcp_configure() {
86                                       PeerAddr => $filter_manager_addr,
87                                       PeerPort => $filter_manager_port,
88                                       Proto => 'tcp'
89 <                                    );
89 >                                    ) or die "Cannot connect!";
90      if (!defined $sock) {
91          print "IHOST ERROR: Could not connect to $filter_manager_addr:$filter_manager_port.\n";
92          print "Please check that there is an i-scream server at this address.\n";
# Line 119 | Line 120 | sub tcp_configure() {
120  
121      print "File list obtained: $file_list\n";
122  
123 +    print $sock "FQDN\n";
124 +    $response = <$sock>;
125 +    chop $response;
126 +    $fqdn = $response;
127 +
128 +    print "FQDN returned: $fqdn\n";
129 +
130      print $sock "UDPUpdateTime\n";
131      $response = <$sock>;
132      chop $response;
# Line 143 | Line 151 | sub tcp_configure() {
151      
152      print $sock "FILTER\n";
153      $response = <$sock>;
154 +    unless (defined($response)) {
155 +        print "Failed: Could not get a filter address from the filter manager.\n";
156 +        exit(1);
157 +    }
158      chop $response;
159      $response =~ /(.*);(.*);(.*)/;
160      ($filter_addr, $udp_port, $tcp_port) = ($1, $2, $3);
161 +    unless (defined($filter_addr) && defined($udp_port) && defined($tcp_port)) {
162 +        print "Failed: Filter address response from server did not make sense: $response\n";
163 +        exit(1);
164 +    }
165      
166      print "Got filter data ($filter_addr, $udp_port, $tcp_port)\n";
167  
# Line 201 | Line 217 | sub send_udp_packet() {
217      }
218      $disk_info .= "</disk>";
219  
220 <    my($hostname) = hostname();
205 <    $hostname =~ s/\..*$//g;
206 <    my($resolv) = `cat /etc/resolv.conf`;
207 <    my($domainname);
208 <    my($machine_name);
209 <    if($resolv =~ /domain\s+([^\s]+)/) {
210 <        # some machines have domain <domain> in resolv.conf
211 <        $domainname = $1;
212 <        $machine_name = "$hostname.$domainname";
213 <    }
214 <    elsif($resolv =~ /search\s+([^\s]+)/) {
215 <        # some machines have search <domain> in resolv.conf
216 <        $domainname = $1;
217 <        $machine_name = "$hostname.$domainname";
218 <    }
219 <    else {
220 <        # we can't find out the domain
221 <        $machine_name = $hostname;
222 <    }
223 <    my($ip) = inet_ntoa(scalar(gethostbyname($hostname)) || 'localhost');
220 >    my($ip) = inet_ntoa(scalar(gethostbyname(hostname())) || 'localhost');
221  
222      # Build the XML packet this way, as we can clearly
223      # see the structure and contents... I like this ;-)
# Line 228 | Line 225 | sub send_udp_packet() {
225      # larger than 8196 bytes]
226      my($xml) = <<EOF;
227      
228 < <packet seq_no="$seq_no" machine_name="$machine_name" date="$date" type="data" ip="$ip">
228 > <packet seq_no="$seq_no" machine_name="$fqdn" date="$date" type="data" ip="$ip">
229      <load>
230          <load1>$packet{"packet.load.load1"}</load1>
231          <load5>$packet{"packet.load.load5"}</load5>
# Line 275 | Line 272 | EOF
272  
273      # Make the packet smaller by stripping out newlines and leading spaces.
274      $xml =~ s/\n\s*//g;
275 <    
275 >
276      my($sock) = new IO::Socket::INET (
277                                        PeerPort => $udp_port,
278                                        PeerAddr => $filter_addr,
279                                        Proto => 'udp'
280 <                                     ) or die "Socket: $!\n";
280 >                                     ) or die "Could not send UDP: $!\n";
281  
282      print $sock $xml or die "Could not send UDP packet: $!\n";
283      close($sock);
# Line 304 | Line 301 | sub send_tcp_heartbeat() {
301                                       PeerAddr => $filter_addr,
302                                       PeerPort => $tcp_port,
303                                       Proto => 'tcp'
304 <                                    );
304 >                                    ) or return;
305      if (!defined $sock) {
306          print "IHOST WARNING: Failed to deliver a heartbeat to the i-scream filter.\n";
307          return;
# Line 315 | Line 312 | sub send_tcp_heartbeat() {
312  
313      print $sock "HEARTBEAT\n";
314      $response = <$sock>;
315 +    return if (!defined $response);
316      chop $response;
317      if (!$response eq "OK") {
318          close($sock);
# Line 324 | Line 322 | sub send_tcp_heartbeat() {
322      
323      print $sock "CONFIG\n";
324      $response = <$sock>;
325 +    return if (!defined $response);
326      chop $response;
327      if (!$response eq "OK") {
328          close($sock);
# Line 333 | Line 332 | sub send_tcp_heartbeat() {
332  
333      print $sock "$file_list\n";
334      $response = <$sock>;
335 +    return if (!defined $response);
336      chop $response;
337      if (!$response eq "OK") {
338          close($sock);
# Line 342 | Line 342 | sub send_tcp_heartbeat() {
342      
343      print $sock "$last_modified\n";
344      $response = <$sock>;
345 +    return if (!defined $response);
346      chop $response;
347      if ($response eq "ERROR") {
348          close($sock);
# Line 356 | Line 357 | sub send_tcp_heartbeat() {
357      
358      print $sock "ENDHEARTBEAT\n";
359      $response = <$sock>;
360 +    return if (!defined $response);
361      chop $response;
362      if (!$response eq "OK") {
363          close($sock);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines