]> git.etc.gen.nz Git - spong.git/commitdiff
added event() routine to send event message to spong-server
authorStephen L Johnson <sjohnson@monsters.org>
Wed, 9 Feb 2000 20:13:46 +0000 (20:13 +0000)
committerStephen L Johnson <sjohnson@monsters.org>
Wed, 9 Feb 2000 20:13:46 +0000 (20:13 +0000)
src/lib/Spong/Status.pm

index 13330903ececc70034aecbeebc16d96b819c03cb..ccbd5188a37ad612622e318e12301c8c1497d134 100755 (executable)
@@ -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;
 }