--- projects/cms/source/host/ihost-perl/ihost.pl 2001/02/01 09:10:52 1.11 +++ projects/cms/source/host/ihost-perl/ihost.pl 2001/02/28 10:53:13 1.20 @@ -2,14 +2,15 @@ # ----------------------------------------------------------- # Perl i-scream Host. +# http://www.i-scream.org.uk # # An all-in-one script to act as an i-scream host on # a typical Unix/Linux box. You may adapt the data-gathering # methods as you see fit. # - pjm2@ukc.ac.uk # -# $Author: pjm2 $ -# $Id: ihost.pl,v 1.11 2001/02/01 09:10:52 pjm2 Exp $ +# $Author: tdb $ +# $Id: ihost.pl,v 1.20 2001/02/28 10:53:13 tdb Exp $ #------------------------------------------------------------ $| = 1; @@ -31,6 +32,7 @@ use vars qw ( $tcp_port $filter_addr $file_list + $fqdn ); if (@ARGV != 2) { @@ -71,6 +73,13 @@ while (1) { exit(0); + +#----------------------------------------------------------------------- +# tcp_configure +# Establishes a TCP connection to the specified i-scream filter manager. +# The host then requests details from the server, such as the intervals +# at which to send UDP packets. +#----------------------------------------------------------------------- sub tcp_configure() { my($sock) = new IO::Socket::INET( @@ -85,7 +94,7 @@ sub tcp_configure() { exit(1); } - # Now run through the configuration process. + # Now run through the configuration process... my($response); print $sock "STARTCONFIG\n"; @@ -111,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; @@ -155,13 +171,24 @@ sub tcp_configure() { close($sock); print "Configuration finished sucessfully!\n"; + + return; } + + + +#----------------------------------------------------------------------- +# send_udp_packet +# Sends a UDP packet to an i-scream filter. +# The packet contains XML markup describing some of the machine's state. +# Receipt of UDP packets is not guaranteed. +#----------------------------------------------------------------------- sub send_udp_packet() { my(@statgrab) = `./statgrab.pl`; my(%packet); - for (my($i) = 0; $i < $#statgrab; $i++) { + for (my($i) = 0; $i <= $#statgrab; $i++) { $statgrab[$i] =~ /^([^\s]*) (.*)$/; $packet{$1} = $2; } @@ -171,29 +198,26 @@ sub send_udp_packet() { my($disk_info) = ""; my($i) = 0; while (defined $packet{"packet.disk.p$i.attributes.mount"}) { - $disk_info .= ""; - $disk_info .= qq/$packet{"packet.disk.p$i.attributes.name"}<\/name>/; - $disk_info .= qq/$packet{"packet.disk.p$i.attributes.kbytes"}<\/kbytes>/; - $disk_info .= qq/$packet{"packet.disk.p$i.attributes.used"}<\/used>/; - $disk_info .= qq/$packet{"packet.disk.p$i.attributes.avail"}<\/avail>/; - $disk_info .= qq/$packet{"packet.disk.p$i.attributes.mount"}<\/mount>/; - $disk_info .= ""; + $disk_info .= " + $packet{"packet.load.load1"} $packet{"packet.load.load5"} @@ -226,20 +250,21 @@ sub send_udp_packet() { $packet{"packet.cpu.swap"} - $packet{"packet.memory.real"} + $packet{"packet.memory.total"} $packet{"packet.memory.free"} - $packet{"packet.memory.swap_total"} - $packet{"packet.memory.swap_free"} + $packet{"packet.swap.total"} + $packet{"packet.swap.free"} $disk_info 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, @@ -250,8 +275,18 @@ EOF close($sock); $seq_no++; print "-"; + + return; } + + + +#----------------------------------------------------------------------- +# send_tcp_heartbeat +# Establishes a TCP connection to an i-scream filter. +# The heartbeat is used as a guaranteed "I'm alive" delivery mechanism. +#----------------------------------------------------------------------- sub send_tcp_heartbeat() { my($sock) = new IO::Socket::INET( @@ -319,4 +354,6 @@ sub send_tcp_heartbeat() { close($sock); print "^"; + + return; }