Jabber notification
Fred Jordan
fjordan at hcssun01.hcs.net
Thu Jul 10 18:30:11 CEST 2003
Short answer, it's hardcoded in the notify-by-jabber.pl script. For the
long asnwer see my script included below. I didn't write this script;
only modified it to suit my needs here. My script sends this to
everyone who is logged into the jabber server via the motd. Rather
crude; wouldn't mind other suggestions/improvements; but it works
OK.
BTW, was your problem getting the notifications to jabber the same
as the ones I first had; or something different? Just curious. Would
rather fix the script than have to omit the variable being passed to
the script ,if possible.
What I would REALLY love, is to have a seperate conference room on
the jabber server; one for nagios notifications, one for swatch scrubbed
syslog messages; etc. Problem is (which gets back to my programming
ability) not sure how to modify the notify-by-jabber.pl AND the
jabber server to do this.
Thanks Much,
Fred
#!/usr/bin/perl
#
# Author David Cox
# Created from various code examples found on the web
# Last Modified 08/06/2002
# Feel free to use or modify as needed to suit your needs
#######################################################
# MAXWAIT is used because the send message function didn't seem to
# like being called to fast. The message would be sent unless I waited a second
# or so. You can experiment with it but I just went with 2 seconds.
#######################################################
use strict;
use Net::Jabber qw(Client) ;
use Net::Jabber qw(Message) ;
use Net::Jabber qw(Protocol) ;
use Net::Jabber qw(Presence) ;
my $len = scalar @ARGV;
use constant RECIPIENT => 'my.host.net/announce/motd';
use constant SERVER => 'my.host.net';
use constant PORT => 5222;
use constant USER => 'nagios-user';
use constant PASSWORD => 'nagios-passwd';
use constant RESOURCE => 'telnet';
use constant MESSAGE => <STDIN>;
use constant MAXWAIT => 2 ;
my $connection = Net::Jabber::Client->new();
$connection->Connect( "hostname" => SERVER,"port" => PORT ) or die
"Cannot connect ($!)\n";
my @result = $connection->AuthSend( "username" => USER,"password" =>
PASSWORD,"resource" => RESOURCE );
if ($result[0] ne "ok") {
die "Ident/Auth with server failed: $result[0] - $result[1]\n";
}
my $message = Net::Jabber::Message->new();
$message->SetMessage( "to" => "my.host.net/announce/motd",
"body" => MESSAGE);
$connection->Send($message);
sleep(MAXWAIT);
$connection->Disconnect();
exit;
On Thu, 10 Jul 2003, Edwards, Thomas wrote:
> Appreciate the help, one question, how does the notify-by-jabber.pl know
> which user to send to if the email address is different than the jabber
> address? Would their be a way to send it that way?
>
> -----Original Message-----
> From: Fred Jordan [mailto:fjordan at hcssun01.hcs.net]
> Sent: Wednesday, July 09, 2003 6:13 PM
> To: Edwards, Thomas
> Cc: 'nagios-users at lists.sourceforge.net'
> Subject: Re: [Nagios-users] Jabber notification
>
>
> Try this:
>
> # 'notify-by-jabber' command definition
> define command{
> command_name notify-by-jabber
> command_line /usr/bin/printf "Service: $SERVICEDESC$, Host:
> $HOSTNAME$, State: $SERVICESTATE$, Date: $DATETIME$" |
> /usr/local/nagios/notify-by-
> jabber.pl
> }
>
> Do NOT try this:
> # 'notify-by-jabber' command definition
> define command{
> command_name notify-by-jabber
> command_line /usr/bin/printf "Service: $SERVICEDESC$, Host:
> $HOSTNAME$, State: $SERVICESTATE$, Info: $OUTPUT$, Date: $DATETIME$" |
> /usr/local/nagios/notify-by-jabber.pl
> }
>
> I had the same problem a few months ago. Rebuilding everything in site;
> hacking everything that could log output to a file. Note the difference; the
> first command definition has removed the "Info: $OUTPUT$" being passed to
> the notify-by-jabber.pl script. Turned out there is a "%", ":",";", or some
> character that was screwing up the notify-by-jabber.pl script. Sorry, but am
> at home right now and don't which character was the problem but I just about
> "lost it" trying to find this problem( I don't sound like I am on a rant or
> anything do I?).
>
> At any rate, would be glad to converse with anyone/everyone about the
> possiblities of integrating jabber with nagios; and for that matter with
> swatch and other tools we run here. We have a nagios server that sends
> notifications to everyone logged in to the jabber server. People in the NOC
> seem to think its great, and want the jabber server tied to everything we
> run. To be honest; I kind of like the idea too.
>
> Would be glad to swap scripts; nagios, jabbber or otherwise; with anyone
> interested. A word or warning though; what I write ain't pretty but it
> usually gets the job done. Never been a good programmer and would starve to
> death if I had to make a living cranking out lines of code.
>
> Hope this helps,
> Fred
>
> On Wed, 9 Jul 2003, Edwards, Thomas wrote:
>
> > I was wondering if anyone had gotten the jaber notification to work
> > and could provide me a little insite into configureing this.
> >
> > I got the jabber script here
> > http://www.nagios.org/faqs/viewfaq.php?faq_id=50
> > <http://www.nagios.org/faqs/viewfaq.php?faq_id=50> and configured it.
> >
> > Installed the appropriate jabber perl mods to allow sending via the
> > script alone etc:
> >
> > [nagios at nagios etc]# ./jabber
> > Usage...
> > notify [jabberid] [message]
> >
> > Then modified miscommands.cfg as follows according to the jabber
> > script
> >
> >
> > # 'notify-by-jabber' command definition
> > define command{
> > command_name notify-by-jabber
> > command_line /usr/local/nagios/etc/jabber user at localhost
> > "**$NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is
> > $SERVICESTATE$ **" $CONT ACTEMAIL$"
> > }
> >
> > Added a line to contacts.cfg for notify-by-jabber to see if it would
> > send, so far nothing. No errors as far as I can see.
> >
> > Any suggestions or clarifications would be greatly appreciated.
> >
> > Tom
> >
> >
> >
> > ************************************************************
> > The information in this email is confidential and may be legally
> > privileged. It is intended solely for the addressee, and access by
> > anyone else is unauthorized.
> >
> > If you are not the intended recipient, any disclosure, copying,
> > distribution or any action taken or omitted to be taken in reliance on
> > it, is prohibited and may be unlawful.
> >
> > If you believe that you have received this email in error, please
> > advise us by calling (901) 385 3688, or emailing
> > mailgateway at accredohealth.net, and then delete this message and all
> > copies and backups thereof. Thank you.
> > ************************************************************
> >
> >
>
>
> ************************************************************
> The information in this email is confidential and may be
> legally privileged. It is intended solely for the addressee,
> and access by anyone else is unauthorized.
>
> If you are not the intended recipient, any disclosure,
> copying, distribution or any action taken or omitted to be
> taken in reliance on it, is prohibited and may be unlawful.
>
> If you believe that you have received this email in error,
> please advise us by calling (901) 385 3688, or emailing
> mailgateway at accredohealth.net, and then delete this message
> and all copies and backups thereof. Thank you.
> ************************************************************
>
-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null
More information about the Users
mailing list