The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

 Fault::Delegate::SimpleHttp - Logger delegate for simple http logging.

SYNOPSIS

 use Fault::Delegate::SimpleHttp;
 $self = Fault::Delegate::SimpleHttp->new ($host,$loguri,
                                           $raiseuri,$clearuri,$syncuri);
 $okay = $self->log                       ($msg);
 $zero = $self->trans01                   ($msg);
 $zero = $self->trans10                   ($msg);
 @list = $self->initfaults;

Inheritance

 UNIVERSAL
   Fault::Delegate
     Fault::Delegate::SimpleHttp

Description

The Class manages an http remote logging connection. To utilize this class you must impliment a set of cgi scripts according the specs given in the next section.

SimpleHttp can act as a template if I at some point want to impliment a Delegate that uses SSL, or that uses xml messages for two way communications.

Note: Each method undef's the Net::Http object it creates before exiting. This may or may not assist with re-entrancy in a multi-process environment, but it was a lesson learned with mysql db handles. The problem was that if a handle was created before processes spawned, it could get carried through into the child processes and if they used the handles the remote daemon could become very confused. Whether this would be true of a web daemon connection or not is conjecture, but the undef is a way of playing it safe.

API For Web Logger

A web site must supply a fairly modest set of scripts to support a minimal interface with which this module may communicate. Each of these scripts should return a code of 200 and a message of OK in their response header. They all use a common set of fields and field definitions:

    Priority is the set of priorities defined by Unix syslog.

    Type is may be any single word uppercase string that your remote application wishes to use to classify messages. At the very least it should support the minimal set described in Fault::Logger.

    Process is a single word name of the process that generated the log or fault message.

    Message is a string of arbitrary length, limited only by what the web server is willing to accept or transmit. It may contain contain any printable character other than newline. Other formatting characters, such as formfeed, are also best avoided.

There are four cgi scripts you will need at your web logger url.

log cgi script

This script must accept a POST with a single text line in the request body.

The line will consist of five space delimited fields:

        TimeStamp Priority Type Process Message

Any additional spaces are part of the message field.

The script may then do anything it wants with the message, including ignoring it.

faultraise cgi script

Almost exactly like the log cgi script except that it must at the very least remember the process and message portions such that a search may be carried out on either field.

If it recieves a message that is exactly the same as of one that is already stored for the process, do nothing.

faultclear cgi script

Similar to the log cgi script, but the body contains only the process and message, delimited by the first space.

        Process Message

If the message is an exact match for a message of an active fault for the same process, it should be deleted. If the message is not from an active fault for the process, it should be ignored and discarded.

faultsync cgi script

When called with a GET, it should dump a list of all fault messages, one to a line in a response body. Each line should be in the format described for log cgi script.

        TimeStamp Priority Type Process Message

If there are no fault messages, it should return an empty list.

Examples

 use Fault::Delegate::SimpleHttp;
 use Fault::Msg;
 use Fault::Logger;

 my $msg       = Fault::Msg                       ("Arf!");
 my $baz       = Fault::Delegate::SimpleHttp->new ($host,$loguri,
                                                   $raiseuri,$clearuri,
                                                   $syncuri);
 my $waslogged = $baz->log                        ($msg);

                 Fault::Logger->new               ($baz);
 my $waslogged = Fault::Logger->log               ("Bow! Wow!");

 [See Fault::Logger for a detailed example.]

Class Variables

 None.

Instance Variables

 host           Name or ip of the web logger server.
 logfn          URI on the host web server to the log cgi script.
 raisefn        URI on the host web server to the fault raise cgi script.
 clearfn        URI on the host web server to the fault clear cgi script.
 syncfn         URI on the host web server to the fault sync cgi script.

Class Methods

$self = Fault::Delegate::LogFile->new ($host,$loguri,$raiseuri,$clearuri,$syncuri)

Create an object to allow communications with a remote http based logging application. Returns undef on failure.

Instance Methods

$okay = $self->log ($msg)

Send a log message to the web logger of the form:

    Time Priority Type Process Message

and return true if we succeeded in doing so.

$zero = $self->trans01 ($msg)

Tell the web logger to raise a fault for the current process by sending a line of the form:

    Time Priority Type Process Message

It always returns 0.

$zero = $self->trans10 ($msg)

The the web logger to clear a fault for the current process by sending a line of the form:

    Process Message

It always returns 0.

@list = $self->initfaults

Requests a current list of faults from the weblogger when Logger initializes. @list contains a simple list of strings, where each string represents a unique active fault condition belonging to the current process.

 ("fault message 1", "fault message 2", ...)

If it cannot connect to the remote weblogger, an empty list is returned.

Private Class Method

 None.

Private Instance Methods

$bool = $self->_write ($msg)
$bool = $self->_connect
$bool = $self->_disconnect

Impliments the above overrides to the internal family protocol utilized by the Fault:Delegate log and test methods.

Errors and Warnings

Local warning messages are issued if the web logger cannot be reached or has any problems whatever. You cannot log to a web logger that is not working!

KNOWN BUGS

 See TODO.

SEE ALSO

 Fault::Logger, Fault::Delegate, Fault::Msg, Net::HTTP,
 Fault::ErrorHandler, Fault::DebugPrinter

AUTHOR

Dale Amon <amon@vnl.com>

6 POD Errors

The following errors were encountered while parsing the POD:

Around line 340:

=over should be: '=over' or '=over positive_number'

Around line 357:

=back doesn't take any parameters, but you said =back 4

Around line 406:

=back doesn't take any parameters, but you said =back 4

Around line 446:

You forgot a '=back' before '=head1'

Around line 486:

=back doesn't take any parameters, but you said =back 4

Around line 505:

=back doesn't take any parameters, but you said =back 4