From 69283ceb59b6f1170d3d42f38e139b680d4443f3 Mon Sep 17 00:00:00 2001 From: cvs Date: Tue, 7 Dec 1999 07:24:14 +0000 Subject: [PATCH] Remove &status function. Replace it with Spong::Status module. --- src/spong-network.pl | 89 ++------------------------------------------ 1 file changed, 3 insertions(+), 86 deletions(-) diff --git a/src/spong-network.pl b/src/spong-network.pl index 7faea70..e04e58f 100755 --- a/src/spong-network.pl +++ b/src/spong-network.pl @@ -27,6 +27,7 @@ use Net::Ping; use Socket; use Spong::Daemon; +use Spong::Status qw(status); srand( time() ^ ($$ + ($$ << 15 )) ); @@ -205,53 +206,6 @@ _EOM_ } -# --------------------------------------------------------------------------- -# &status( SERVERADDR, HOST, SERVICE, COLOR, SUMMARY, MESSAGE ) -# -# This function sends information to the Spong server. It reports the current -# status of a service, and sends along a string of information that might be -# helpful in diagnosing the problem. This code is modeled after the bb -# program, but is a little different in that it handles multi-line messages -# and send over the time as an int, rather then a string. -# --------------------------------------------------------------------------- - -sub status { - my( $addr, $host, $cat, $color, $summary, $message ) = @_; - my( $iaddr, $paddr, $proto, $line, $ip, $ok ); - - if( $addr =~ /^\s*((\d+\.){3}\d+)\s*$/ ) { - $ip = $addr; - } else { - my( @addrs ) = (gethostbyname($addr))[4]; - my( $a, $b, $c, $d ) = unpack( 'C4', $addrs[0] ); - $ip = "$a.$b.$c.$d"; - } - - $iaddr = inet_aton( $ip ) || die "no host: $addr\n"; - $paddr = sockaddr_in( $SPONG_UPDATE_PORT, $iaddr ); - $proto = getprotobyname( 'tcp' ); - - # Set an alarm so that if we can't connect "immediately" it times out. - - $SIG{'ALRM'} = sub { die }; - alarm(30); - - eval <<'_EOM_'; - socket( SOCK, PF_INET, SOCK_STREAM, $proto ) || die "socket: $!"; - connect( SOCK, $paddr ) || die "connect: $!"; - select((select(SOCK), $| = 1)[0]); - print SOCK "status $host $cat $color ", time(), " $summary\n"; - print SOCK "$message\n"; - close( SOCK ) || die "close: $!"; - $ok = 1; -_EOM_ - - alarm(0); - print STDERR scalar localtime, " can't connect to spong server.\n" if ! $ok; -} - - - # =========================================================================== # Utility functions, and signal handlers... # =========================================================================== @@ -356,19 +310,10 @@ sub pipe_handler { } -# This is a tempory kludge until I create the check function plugins -# mechanism +# Load all of the checks specified in all of the 'services' attribute +# in %HOSTS sub config_funcs { -# $PLUGINS{'ping'} = \&check_ping; -# $PLUGINS{'ftp'} = \&check_ftp; -# $PLUGINS{'pop'} = \&check_pop; -# $PLUGINS{'smtp'} = \&check_smtp; -# $PLUGINS{'nntp'} = \&check_nntp; -# $PLUGINS{'imap'} = \&check_imap; -# $PLUGINS{'dns'} = \&check_dns; -# $PLUGINS{'http'} = \&check_http; -# $PLUGINS{'nfs'} = \&check_nfs; # Consolidate all of the service to be checked into a unique list my (%checks,$check); @@ -386,31 +331,3 @@ sub config_funcs { } } -# Fork into the backgroup and disconnect our console and become -# the session group leader - -sub daemonize { - - my ($pid); - - # Try to fork - $pid = fork(); - if (! defined $pid) { - die "ERROR: Could not fork: $!"; - } elsif ($pid) { - # I'm the parent, so just exit gracefully - exit(0); - } else { - # I'm the child - - # Disconnect from the console - open(STDIN,"/dev/null"); - open(STDERR,">/dev/null"); - - # Become session group leader - POSIX::setsid(); - } -} - - -- 2.30.2