--- projects/cms/source/host/ihost-perl/ihost.pl 2001/01/26 17:09:29 1.1
+++ projects/cms/source/host/ihost-perl/ihost.pl 2001/02/01 09:10:52 1.11
@@ -1,4 +1,4 @@
-#!/usr/local/bin/perl -w
+#!/usr/bin/perl -w
# -----------------------------------------------------------
# Perl i-scream Host.
@@ -9,7 +9,7 @@
# - pjm2@ukc.ac.uk
#
# $Author: pjm2 $
-# $Id: ihost.pl,v 1.1 2001/01/26 17:09:29 pjm2 Exp $
+# $Id: ihost.pl,v 1.11 2001/02/01 09:10:52 pjm2 Exp $
#------------------------------------------------------------
$| = 1;
@@ -48,15 +48,25 @@ $seq_no = 1;
$last_udp_time = time;
$last_tcp_time = time;
while (1) {
- if (time >= $last_udp_time + $udp_update_time) {
+ my($time) = time;
+ if ($time >= $last_udp_time + $udp_update_time) {
&send_udp_packet();
- $last_udp_time = time;
+ $last_udp_time = $time;
}
- if (time >= $last_tcp_time + $tcp_update_time) {
+ if ($time >= $last_tcp_time + $tcp_update_time) {
&send_tcp_heartbeat();
- $last_tcp_time = time;
+ $last_tcp_time = $time;
}
- `sleep 1`;
+ my($next_udp) = $udp_update_time - $time + $last_udp_time;
+ my($next_tcp) = $tcp_update_time - $time + $last_tcp_time;
+ my($delay);
+ if ($next_udp < $next_tcp) {
+ $delay = $next_udp
+ }
+ else {
+ $delay = $next_tcp;
+ }
+ `sleep $delay`;
}
exit(0);
@@ -67,10 +77,14 @@ sub tcp_configure() {
PeerAddr => $filter_manager_addr,
PeerPort => $filter_manager_port,
Proto => 'tcp'
- ) or die "Could not perform configuration via TCP: $!\n";
+ );
+ 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";
+ print "Program ended.\n";
+ exit(1);
+ }
- die "Could not connect to the i-scream filter manager: $!\n" unless $sock;
-
# Now run through the configuration process.
my($response);
@@ -88,7 +102,7 @@ sub tcp_configure() {
chop $response;
$last_modified = $response;
- print "Config last modified: ". scalar localtime $last_modified . "\n";
+ print "Config last modified: ". (scalar localtime $last_modified/1000) . "\n";
print $sock "FILELIST\n";
$response = <$sock>;
@@ -107,7 +121,7 @@ sub tcp_configure() {
chop $response;
$tcp_update_time = $response;
- print "UDP packet period: $udp_update_time seconds.\nTCP heartbeat period: $tcp_update_time.\n";
+ print "UDP packet period: $udp_update_time seconds.\nTCP heartbeat period: $tcp_update_time seconds.\n";
print $sock "ENDCONFIG\n";
$response = <$sock>;
@@ -169,9 +183,9 @@ sub send_udp_packet() {
$disk_info .= "";
my($hostname) = hostname();
- $hostname =~ s/^([^\.]*?)/$1/;
- my($domainname) = `cat /etc/resolv.conf`;
- $domainname =~ s/domain\s*([^\s]*?)/$1/;
+ $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');
@@ -191,6 +205,7 @@ sub send_udp_packet() {
$packet{"packet.os.platform"}
$packet{"packet.os.sysname"}
$packet{"packet.os.version"}
+ $packet{"packet.os.uptime"}
$packet{"packet.users.count"}
@@ -243,9 +258,11 @@ sub send_tcp_heartbeat() {
PeerAddr => $filter_addr,
PeerPort => $tcp_port,
Proto => 'tcp'
- ) or die "Could not perform heartbeat via TCP: $!\n";
-
- die "Could not connect to the i-scream filter: $!\n" unless $sock;
+ );
+ if (!defined $sock) {
+ print "IHOST WARNING: Failed to deliver a heartbeat to the i-scream filter.\n";
+ return;
+ }
# Now run through the configuration process.
my($response);