Last active
May 6, 2019 01:34
-
-
Save bageljp/5844641 to your computer and use it in GitHub Desktop.
notify_via_jabber with groupchat. clone from http://wiki.tkr.mydns.jp/Linux%E9%96%A2%E9%80%A3/Nagios%E3%81%AE%E9%80%9A%E7%9F%A5%E3%82%92gtalk%E3%81%A7%E5%8F%97%E3%81%91%E5%8F%96%E3%82%8B
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 'host-notify-by-jabber' command | |
| define command{ | |
| command_name host-notify-by-jabber | |
| command_line /usr/bin/perl $USER1$/notify_via_jabber.pl $CONTACTPAGER$ "`/usr/bin/printf \"***** Nagios *****\nHost '$HOSTALIAS$' is $HOSTSTATE$ - Info: $HOSTOUTPUT$\"`" | |
| } | |
| # 'host-notify-by-jabber' command to groupchat | |
| define command{ | |
| command_name host-notify-by-jabber-groupchat | |
| command_line /usr/bin/perl $USER1$/notify_via_jabber.pl $CONTACTPAGER$ "`/usr/bin/printf \"***** Nagios *****\nHost '$HOSTALIAS$' is $HOSTSTATE$ - Info: $HOSTOUTPUT$\"`" groupchat | |
| } | |
| # 'service-notify-by-jabber' command | |
| define command{ | |
| command_name service-notify-by-jabber | |
| command_line /usr/bin/perl $USER1$/notify_via_jabber.pl $CONTACTPAGER$ "`/usr/bin/printf \"***** Nagios *****\n$NOTIFICATIONTYPE$: $HOSTADDRESS$ ** Service: $SERVICEDESC$ ** State: $SERVICESTATE$\nInfo: $SERVICEOUTPUT$\nDate/Time: $LONGDATETIME$\"`" | |
| } | |
| # 'service-notify-by-jabber' command to groupchat | |
| define command{ | |
| command_name service-notify-by-jabber-groupchat | |
| command_line /usr/bin/perl $USER1$/notify_via_jabber.pl $CONTACTPAGER$ "`/usr/bin/printf \"***** Nagios *****\n$NOTIFICATIONTYPE$: $HOSTADDRESS$ ** Service: $SERVICEDESC$ ** State: $SERVICESTATE$\nInfo: $SERVICEOUTPUT$\nDate/Time: $LONGDATETIME$\"`" groupchat | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl -w | |
| # | |
| # script for nagios notify via Jabber / Google Talk Instant Messaging | |
| # using XMPP protocol and SASL PLAIN authentication. | |
| # | |
| # author: Andrew Elwell <[email protected]> | |
| # based on work by Thus0 <[email protected]> and David Cox | |
| # | |
| # released under the terms of the GNU General Public License v2 | |
| # Copyright 2007 Andrew Elwell. | |
| use strict; | |
| use Net::XMPP; | |
| use Encode 'decode'; | |
| ## Configuration | |
| my $username = "account(ex. nagios)"; | |
| my $password = "password(ex. password)"; | |
| my $resource = "resource(ex. nagios)"; | |
| ## End of configuration | |
| my $len = scalar @ARGV; | |
| if ($len lt 2) { | |
| die "Usage...\n $0 [jabberid] [message] [groupchat]\n"; | |
| } | |
| my @field=split(/,/,$ARGV[0]); | |
| #------------------------------------ | |
| # Google Talk & Jabber parameters : | |
| my $hostname = 'jabber_server(ex. jabber.example.com'; | |
| my $port = 5222; | |
| my $componentname = 'domain(ex. example.com)'; | |
| my $connectiontype = 'tcpip'; | |
| my $tls = 1; | |
| #------------------------------------ | |
| my $Connection = new Net::XMPP::Client(); | |
| # Connect to talk.google.com | |
| my $status = $Connection->Connect( | |
| hostname => $hostname, port => $port, | |
| componentname => $componentname, | |
| connectiontype => $connectiontype, tls => $tls); | |
| if (!(defined($status))) { | |
| print "ERROR: XMPP connection failed.\n"; | |
| print " ($!)\n"; | |
| exit(0); | |
| } | |
| # Change hostname | |
| my $sid = $Connection->{SESSION}->{id}; | |
| $Connection->{STREAM}->{SIDS}->{$sid}->{hostname} = $componentname; | |
| # Authenticate | |
| my @result = $Connection->AuthSend( | |
| username => $username, password => $password, | |
| resource => $resource); | |
| if ($result[0] ne "ok") { | |
| print "ERROR: Authorization failed: $result[0] - $result[1]\n"; | |
| exit(0); | |
| } | |
| if ($len lt 3 || $ARGV[2] ne "groupchat") { | |
| # Send messages | |
| foreach ( @field ) { | |
| $Connection->MessageSend( | |
| to => "$_\@$componentname", | |
| resource => $resource, | |
| subject => "Notification", | |
| type => "chat", | |
| body => decode('UTF-8',$ARGV[1])); | |
| } | |
| } else { | |
| # Send messages groupchat | |
| foreach ( @field ) { | |
| $Connection->MessageSend( | |
| to => "$_\@conference.$componentname", | |
| resource => $resource, | |
| subject => "Notification", | |
| type => "groupchat", | |
| body => decode('UTF-8',$ARGV[1])); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment