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.25 by tdb, Mon Mar 12 23:20:43 2001 UTC

# Line 32 | Line 32 | use vars qw (
32               $tcp_port
33               $filter_addr
34               $file_list
35 +             $fqdn
36 +             $pidfile
37              );
38  
39   if (@ARGV != 2) {
# Line 43 | Line 45 | $filter_manager_port = $ARGV[1];
45  
46   $seq_no = 1;
47  
48 + # write our PID to a file
49 + $pidfile = "ihost.pid";
50 + &write_pid();
51 +
52   &tcp_configure();
53   &send_udp_packet();
54  
# Line 70 | Line 76 | while (1) {
76      `sleep $delay`;
77   }
78  
79 + # we'll probably never get here...
80 + `rm -f $pidfile`;
81   exit(0);
82  
83  
# Line 85 | Line 93 | sub tcp_configure() {
93                                       PeerAddr => $filter_manager_addr,
94                                       PeerPort => $filter_manager_port,
95                                       Proto => 'tcp'
96 <                                    );
96 >                                    ) or die "Cannot connect!";
97      if (!defined $sock) {
98          print "IHOST ERROR: Could not connect to $filter_manager_addr:$filter_manager_port.\n";
99          print "Please check that there is an i-scream server at this address.\n";
# Line 119 | Line 127 | sub tcp_configure() {
127  
128      print "File list obtained: $file_list\n";
129  
130 +    print $sock "FQDN\n";
131 +    $response = <$sock>;
132 +    chop $response;
133 +    $fqdn = $response;
134 +
135 +    print "FQDN returned: $fqdn\n";
136 +
137      print $sock "UDPUpdateTime\n";
138      $response = <$sock>;
139      chop $response;
# Line 143 | Line 158 | sub tcp_configure() {
158      
159      print $sock "FILTER\n";
160      $response = <$sock>;
161 +    unless (defined($response)) {
162 +        print "Failed: Could not get a filter address from the filter manager.\n";
163 +        exit(1);
164 +    }
165      chop $response;
166      $response =~ /(.*);(.*);(.*)/;
167      ($filter_addr, $udp_port, $tcp_port) = ($1, $2, $3);
168 +    unless (defined($filter_addr) && defined($udp_port) && defined($tcp_port)) {
169 +        print "Failed: Filter address response from server did not make sense: $response\n";
170 +        exit(1);
171 +    }
172      
173      print "Got filter data ($filter_addr, $udp_port, $tcp_port)\n";
174  
# Line 201 | Line 224 | sub send_udp_packet() {
224      }
225      $disk_info .= "</disk>";
226  
227 <    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');
227 >    my($ip) = inet_ntoa(scalar(gethostbyname(hostname())) || 'localhost');
228  
229      # Build the XML packet this way, as we can clearly
230      # see the structure and contents... I like this ;-)
# Line 228 | Line 232 | sub send_udp_packet() {
232      # larger than 8196 bytes]
233      my($xml) = <<EOF;
234      
235 < <packet seq_no="$seq_no" machine_name="$machine_name" date="$date" type="data" ip="$ip">
235 > <packet seq_no="$seq_no" machine_name="$fqdn" date="$date" type="data" ip="$ip">
236      <load>
237          <load1>$packet{"packet.load.load1"}</load1>
238          <load5>$packet{"packet.load.load5"}</load5>
# Line 275 | Line 279 | EOF
279  
280      # Make the packet smaller by stripping out newlines and leading spaces.
281      $xml =~ s/\n\s*//g;
282 <    
282 >
283      my($sock) = new IO::Socket::INET (
284                                        PeerPort => $udp_port,
285                                        PeerAddr => $filter_addr,
286                                        Proto => 'udp'
287 <                                     ) or die "Socket: $!\n";
287 >                                     ) or die "Could not send UDP: $!\n";
288  
289      print $sock $xml or die "Could not send UDP packet: $!\n";
290      close($sock);
# Line 304 | Line 308 | sub send_tcp_heartbeat() {
308                                       PeerAddr => $filter_addr,
309                                       PeerPort => $tcp_port,
310                                       Proto => 'tcp'
311 <                                    );
311 >                                    ) or return;
312      if (!defined $sock) {
313          print "IHOST WARNING: Failed to deliver a heartbeat to the i-scream filter.\n";
314          return;
# Line 315 | Line 319 | sub send_tcp_heartbeat() {
319  
320      print $sock "HEARTBEAT\n";
321      $response = <$sock>;
322 +    return if (!defined $response);
323      chop $response;
324      if (!$response eq "OK") {
325          close($sock);
# Line 324 | Line 329 | sub send_tcp_heartbeat() {
329      
330      print $sock "CONFIG\n";
331      $response = <$sock>;
332 +    return if (!defined $response);
333      chop $response;
334      if (!$response eq "OK") {
335          close($sock);
# Line 333 | Line 339 | sub send_tcp_heartbeat() {
339  
340      print $sock "$file_list\n";
341      $response = <$sock>;
342 +    return if (!defined $response);
343      chop $response;
344      if (!$response eq "OK") {
345          close($sock);
# Line 342 | Line 349 | sub send_tcp_heartbeat() {
349      
350      print $sock "$last_modified\n";
351      $response = <$sock>;
352 +    return if (!defined $response);
353      chop $response;
354      if ($response eq "ERROR") {
355          close($sock);
# Line 356 | Line 364 | sub send_tcp_heartbeat() {
364      
365      print $sock "ENDHEARTBEAT\n";
366      $response = <$sock>;
367 +    return if (!defined $response);
368      chop $response;
369      if (!$response eq "OK") {
370          close($sock);
# Line 365 | Line 374 | sub send_tcp_heartbeat() {
374      
375      close($sock);
376      print "^";
377 +    
378 +    return;
379 + }
380 +
381 + #-----------------------------------------------------------------------
382 + # write_pid
383 + # Writes the PID (process ID) of this instance to $pidfile.
384 + # This is then used by a seperate script to check (and restart) ihost.
385 + #-----------------------------------------------------------------------
386 + sub write_pid() {
387 +    open PID, ">$pidfile";
388 +    print PID $$;
389 +    close PID;
390      
391      return;
392   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines