--- /dev/null
+#
+# This module encapsulated the status function. It 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.
+#
+# methods
+# status( SERVERADDR, HOST, SERVICE, COLOR, SUMMARY, MESSAGE )
+
+package Spong::Status;
+
+require Exporter;
+
+use strict;
+use vars qw(@ISA @EXPORT_OK $VERSION);
+use Carp;
+use IO::Socket;
+
+@ISA = qw(Exporter Spong::Status);
+@EXPORT_OK = qw(status);
+$VERSION = 0.01;
+
+sub status {
+ my( $addr, $host, $cat, $color, $summary, $message ) = @_;
+ my( $sock, $ok );
+
+ $sock = IO::Socket::INET->new( PeerAddr => $addr,
+ PeerPort => $main::SPONG_UPDATE_PORT,
+ Proto => 'tcp',
+ Timeout => 30,
+ Reuse => 1,
+ );
+
+ if ( ! defined $sock ) {
+ croak "Could not connect with Spong Server: $@";
+ }
+
+ # Set an alarm on this block in case we run into problem talking to
+ # the spong server.
+ {
+ local $SIG{'ALRM'} = sub { die; };
+ alarm(30);
+
+ $sock->autoflush(1);
+ $sock->print("status $host $cat $color " . time(). " $summary\n");
+ $sock->print("$message\n");
+
+ undef $sock;
+ $ok = 1;
+ }
+
+ alarm(0);
+ print STDERR scalar localtime, " can't connect to spong server.\n" if ! $ok;
+}
+
+
+