--- projects/cms/source/host/ihost-perl/ihost.pl 2002/03/11 13:34:24 1.46 +++ projects/cms/source/host/ihost-perl/ihost.pl 2002/05/21 16:47:11 1.50 @@ -1,5 +1,25 @@ #!/usr/bin/perl -w +# +# i-scream central monitoring system +# http://www.i-scream.org.uk +# Copyright (C) 2000-2002 i-scream +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + # ----------------------------------------------------------- # Perl i-scream Host. # http://www.i-scream.org.uk @@ -8,7 +28,7 @@ # a typical Unix/Linux box. # # $Author: tdb $ -# $Id: ihost.pl,v 1.46 2002/03/11 13:34:24 tdb Exp $ +# $Id: ihost.pl,v 1.50 2002/05/21 16:47:11 tdb Exp $ #------------------------------------------------------------ $| = 1; @@ -34,6 +54,7 @@ use vars qw ( $pidfile $retry_wait $ostype + $key @data ); @@ -61,6 +82,7 @@ $pidfile .= "/.ihost.pid"; &write_pid(); &tcp_configure(); +&send_tcp_heartbeat(); &send_udp_packet(); $last_udp_time = time; @@ -140,63 +162,63 @@ sub tcp_configure() { print $sock "LASTMODIFIED\n"; $response = <$sock>; - if (!$response) { - print "The i-scream server did not return anything for the LASTMODIFIED command.\n"; + if (!$response || $response eq "ERROR\n") { + print "The i-scream server did not provide the LASTMODIFIED value.\n"; close($sock); wait_then_retry(); next; } - chop $response; + chomp $response; $last_modified = $response; print "Config last modified: ". (scalar localtime $last_modified/1000) . "\n"; print $sock "FILELIST\n"; $response = <$sock>; - if (!$response) { + if (!$response || $response eq "ERROR\n") { print "The i-scream server did not provide a configuration file list.\n"; close($sock); wait_then_retry(); next; } - chop $response; + chomp $response; $file_list = $response; print "File list obtained: $file_list\n"; print $sock "FQDN\n"; $response = <$sock>; - if (!$response) { + if (!$response || $response eq "ERROR\n") { print "The i-scream server did not tell us our FQDN.\n"; close($sock); wait_then_retry(); next; } - chop $response; + chomp $response; $fqdn = $response; print "FQDN returned: $fqdn\n"; print $sock "UDPUpdateTime\n"; $response = <$sock>; - if (!$response) { + if (!$response || $response eq "ERROR\n") { print "The i-scream server did not give us a UDPUpdateTime.\n"; close($sock); wait_then_retry(); next; } - chop $response; + chomp $response; $udp_update_time = $response; print $sock "TCPUpdateTime\n"; $response = <$sock>; - if (!$response) { + if (!$response || $response eq "ERROR\n") { print "The i-scream server did not give us a TCPUpdateTime.\n"; close($sock); wait_then_retry(); next; } - chop $response; + chomp $response; $tcp_update_time = $response; print "UDP packet period: $udp_update_time seconds.\nTCP heartbeat period: $tcp_update_time seconds.\n"; @@ -220,14 +242,14 @@ sub tcp_configure() { wait_then_retry(); next; } - chop $response; - $response =~ /^(.*);(.*);(.*)/; + chomp $response; if ($response eq "ERROR") { print "There are no active configured filters for your host.\n"; close($sock); wait_then_retry(); next; } + $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"; @@ -286,6 +308,7 @@ sub send_udp_packet() { push(@data, "packet.attributes.date $date"); push(@data, "packet.attributes.type data"); push(@data, "packet.attributes.ip $ip"); + push(@data, "packet.attributes.key $key"); # sort the data @data = sort(grep(!/^$/, grep(/^packet\./, @data))); @@ -373,6 +396,9 @@ sub send_tcp_heartbeat() { &tcp_configure(); return; } + + print $sock "KEY\n"; + $key = <$sock>; print $sock "ENDHEARTBEAT\n"; $response = <$sock>;