use IO::Socket;
@ISA = qw(Exporter Spong::Status);
-@EXPORT_OK = qw(status);
+@EXPORT_OK = qw(status event);
$VERSION = 0.01;
sub status {
}
alarm(0);
- print STDERR scalar localtime, " can't connect to spong server.\n" if ! $ok;
+ warn scalar(localtime) . " can't connect to spong server.\n" if ! $ok;
+}
+
+sub event {
+ my( $addr, $host, $cat, $color, $summary, $message, $ttl ) = @_;
+ my( $sock, $ok, $ts );
+ $ts = time();
+
+ $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("event $host $cat $color $ts $summary\n");
+ $sock->print("$message\n");
+
+ undef $sock;
+ $ok = 1;
+ }
+
+ alarm(0);
+ warn scalar(localtime) . " can't connect to spong server.\n" if ! $ok;
}