use Socket;
use Spong::Daemon;
+use Spong::Status qw(status);
srand( time() ^ ($$ + ($$ << 15 )) );
}
-# ---------------------------------------------------------------------------
-# &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...
# ===========================================================================
}
-# 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);
}
}
-# 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(STDOUT,">/dev/null");
- open(STDERR,">/dev/null");
-
- # Become session group leader
- POSIX::setsid();
- }
-}
-
-