From e06caf342d6263e96094a2482d9956110912f340 Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Wed, 9 Feb 2000 20:13:46 +0000 Subject: [PATCH] added event() routine to send event message to spong-server --- src/lib/Spong/Status.pm | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/lib/Spong/Status.pm b/src/lib/Spong/Status.pm index 1333090..ccbd518 100755 --- a/src/lib/Spong/Status.pm +++ b/src/lib/Spong/Status.pm @@ -21,7 +21,7 @@ use Carp; use IO::Socket; @ISA = qw(Exporter Spong::Status); -@EXPORT_OK = qw(status); +@EXPORT_OK = qw(status event); $VERSION = 0.01; sub status { @@ -55,7 +55,41 @@ 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; } -- 2.30.2