The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Log::Dispatch::Jabber - Log messages via Jabber

SYNOPSIS

 use Log::Dispatch;
 use Log::Dispatch::Jabber;

 my $dispatcher = Log::Dispatch->new();
 my $jabber     = Log::Dispatch::Jabber->new(
                                             name=>"jabber",
                                             min_level=>"debug",
                                             login=>{
                                                     hostname => "some.jabber.server",
                                                     port     => 5222,
                                                     username => "logger",
                                                     password => "*****",
                                                     resource => "logger",
                                                    },

                                             to=>["webmaster\@a.jabber.server",chief_honco\@a.jabber.server"],

                                             check_presence=>1,

                                             # Send a message to this address even if their
                                             # presence indicates they are not available.
                                             force=>"webmaster\@a.jabber.server",

                                             # Buffer 5 messages before sending.
                                             buffer => "5",
                                            );

 $dispatcher->add($jabber);

 $dispatcher->log(
                  level   => 'debug',
                  message => 'Hello. Programmer. This is '.ref($jabber)
                 );

DESCRIPTION

Log messages via Jabber.

ERRORS

All internal errors that the package encounters connecting to or authenticating with the Jabber server are logged to STDERR via Log::Dispatch::Screen.

PACKAGE METHODS

__PACKAGE__->new(%args)

Valid arguments are

  • name

    String.

    The name of the object.

    required

  • min_level

    String or Int.

    The minimum logging level this object will accept. See the Log::Dispatch documentation for more information.

    required

  • login

    A hash reference containting the following keys

    • hostname

      String.

      The name of the Jabber server that your object will connect to.

      Required

    • port

      Int.

      The port of the Jabber server that your object will connect to.

      Required

    • username

      String.

      The username that your object will use to log in to the Jabber server.

      Required

    • password

      String.

      The password that your object will use to log in to the Jabber server.

      Required

    • resource

      String.

      The name of the resource that you object will pass to the Jabber server.

      Required

  • to

    A string or an array reference.

    A list of Jabber addresses that messages should be sent to.

    Required

  • check_presence

    Boolean.

    If this flag is true then a message will only be sent if a recipient's presence is normal or chat

  • force

    A string or an array reference.

    A list of Jabber addresses that messages should be sent to regardless of their current presence status.

    This attribute is ignored unless the check_presence attribute is true.

  • buffer

    String. The number of messages to buffer before sending.

    If the argument passed is "-" messages will be buffered until the object's destructor is called.

  • debuglevel

    Int. Net::Jabber debugging level; consult docs for details.

  • debugfile

    String. Where to write Net::Jabber debugging; default is STDOUT.

Returns an object.

OBJECT METHODS

This package inherits from Log::Dispatch::Output.

Please consult the docs for details.

VERSION

0.3

DATE

November 25, 2002

AUTHOR

Aaron Straup Cope

SEE ALSO

Log::Dispatch

Net::Jabber

TO DO

  • Figure out if it is possible to maintain a connection to the Jabber server between calls to log_message.

    If the package does not disconnect between messages but also doesn't do the AuthSend thing, anything after the first message is not sent. (Where does it go?)

    If the package does not disconnect and does the AuthSend thing, the Jabber server returns a '503' error which is a flag that something is wrong. Except, you can still send the message if you ignore the fact that everything is not 'ok'.

    Go figure.

BUGS

  • Sending messages to multiple recipients:

    I've made some progress, in a two-steps forward, one-step back kind of way.

    Specifically, I can get the package to send messages to multiple addresses by connecting/disconnecting for every single address sent instead of logging in just once for every message.

    Then the problem becomes that if too many notices are sent in rapid succession (unlikely but who I am to say) the jabberd for the sender will likely start to limit the connection rate and all the subsequent connections will fail.

    I've tried this with both Net::Jabber and Jabber::Connection and the results were the same.

    Ideally, I'd like to simply create one connection and send a bunch of messages to different addresses. I can go through the motions without generating any errors but the messages themselves are only ever received by the first address...

    As of this writing : the package may fail if you send enough messages in a short enough period time to freak out your jabberd.

    It is recommended that you set the buffer attribute in the object constructor.

    In the meantime, I'm workin' on it.

     sub _send {
        my $self = shift;
    
        my $im = Jabber::NodeFactory->newNode("message");
        $im->insertTag('body')->data(...);
    
        # Where &_connect() and &_disconnect()
        # are simply wrapper methods that DWIM 
    
        # $self->_connect();
        # The above works great except that only
        # the first address in $self->{'__to'}
        # ever receives any messages
    
        # This would be my preferred way of doing
        # things since there's no point in creating
        # a gazillion connetions - unless I've spaced
        # on some important Jabber fundamentals....
    
        foreach my $addr (@{$self->{'__to'}}) {
           $im->attr("to",$addr);
    
           $self->_connect();
           # The above works so long as not too many
           # messages are sent in rapid succession
    
           # Log::Dispatch::Jabber has hooks to
           # buffer messages but if I send (4)
           # successive notices with nothing in
           # between, the server I'm testing against
           # (and out-of-the-box FreeBSD port) starts
           # to carp with 'is being connection rate limited'
           # errors after the third notice.
    
           # I suppose I could sleep(n) but that seems
           # like sort of rude behaviour for a log thingy.
    
           # Happy happy
           $self->{'__client'}->send($im);
           $self->_disconnect();
        }
    
        # $self->_disconnect()
     }

Please report all bugs to http://rt.cpan.org/NoAuth/Dists.html?Queue=Log::Dispatch::Jabber

LICENSE

Copyright (c) 2002, Aaron Straup Cope. All Rights Reserved.

This is free software, you may use it and distribute it under the same terms as Perl itself.