From: cvs Date: Tue, 7 Dec 1999 07:20:21 +0000 (+0000) Subject: Created file. Adding into CVS repository. X-Git-Tag: spong-2_6-beta8~14 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7a16be2d8d3e4fbe16e6b693b04533780d0749fc;p=spong.git Created file. Adding into CVS repository. --- diff --git a/src/lib/Spong/Status.pm b/src/lib/Spong/Status.pm new file mode 100755 index 0000000..f0822bd --- /dev/null +++ b/src/lib/Spong/Status.pm @@ -0,0 +1,61 @@ +# +# 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; +} + + +