use Socket;
use Spong::Daemon;
+use Spong::Status qw(status);
srand( time() ^ ($$ + ($$ << 15 )) );
exit(0);
-# ---------------------------------------------------------------------------
-# &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...