+ Post New Thread
Results 1 to 1 of 1
Scripts Thread, Nagios notify by Google Chat (with HTTP proxy, and google apps domains) in Coding and Web Development; As our mail system is google apps, and therefore includes the Google Talk system, I decided to have a play ...
  1. #1

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,694
    Thank Post
    516
    Thanked 2,455 Times in 1,899 Posts
    Blog Entries
    24
    Rep Power
    833

    Nagios notify by Google Chat (with HTTP proxy, and google apps domains)

    As our mail system is google apps, and therefore includes the Google Talk system, I decided to have a play with getting this working with Nagios notifications. After reading the information here about using it with Jabber, I made some changes to get it to work within a typical school network. Namely, one with a proxy server and one with a custom domain.

    The result is below.

    Nagios command definitions remain the same as the above link:

    Code:
    # 'host-notify-by-jabber' command definition
    define command{        
    command_name    host-notify-by-jabber        
    command_line    /usr/local/bin/notify_via_jabber $CONTACTPAGER$ "Host '$HOSTALIAS$' is $HOSTSTATE$ - Info: $HOSTOUTPUT$"        
    }
    
    # 'notify-by-jabber' command definition
    define command{        
    command_name    notify-by-jabber        
    command_line    /usr/local/bin/notify_via_jabber $CONTACTPAGER$ "$NOTIFICATIONTYPE$ $HOSTNAME$ $SERVICEDESC$ $SERVICESTATE$ $SERVICEOUTPUT$ $LONGDATETIME$"        
    }
    The below is the modified script. This needs putting into a file wherever you normally store your plugins for nagios (and the above editing to reflect this). This file needs execute permissions applying to it for the nagios user.

    Code:
    #!/usr/bin/perl -w
    #
    # script for nagios notify via Jabber / Google Talk Instant Messaging
    #   using XMPP protocol and SASL PLAIN authentication.
    #
    # author: Andrew Elwell <A.Elwell@physics.gla.ac.uk>
    # based on work by Thus0 <Thus0@free.fr> and  David Cox
    #
    # released under the terms of the GNU General Public License v2
    # Copyright 2007 Andrew Elwell.
    
    # Edits for Google Apps Domains and for use of a http proxy
    # by Tony Ayre <localzuk@gmail.com> Feb 2012
    
    
    use strict;
    use Net::XMPP;
    $ENV{'https_proxy'} = 'http://proxy:8080';
    
    
    ## Configuration
    my $username = "username";
    my $password = "password";
    my $componentname = 'customdomain.com';
    my $resource = "nagios";
    ## End of configuration
    
    
    
    
    my $len = scalar @ARGV;
    if ($len ne 2) {
       die "Usage...\n $0 [jabberid] [message]\n";
    }
    my @Field=split(/,/,$ARGV[0]);
    #------------------------------------
    
    
    # Google Talk & Jabber parameters :
    
    
    my $hostname = 'talk.google.com';
    my $port = 443;
    my $connectiontype = 'http';
    my $tls = 0;
    my $ssl = 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,
           ssl => $ssl);
    
    
    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);
    }
    
    
    # Send messages
    foreach ( @Field ) {
    $Connection->MessageSend(
            to       => "$_\@$componentname",
            resource => $resource,
            subject  => "Notification",
            type     => "chat",
            body     => $ARGV[1]);
    }
    To use it with your contacts in nagios, set the 'pager' value for any contacts to their google apps username (without the domain name). Also, you'll need to assign the 2 commands listed above to those users.

  2. 3 Thanks to localzuk:

    CyberNerd (22nd February 2012), pete (22nd February 2012), plexer (22nd February 2012)

SHARE:
+ Post New Thread

Similar Threads

  1. Google Apps- domain or hosting?
    By rocknrollstar in forum Virtual Learning Platforms
    Replies: 7
    Last Post: 27th May 2011, 08:47 PM
  2. Replies: 19
    Last Post: 15th October 2008, 02:44 PM
  3. Informal chat with possible future employer
    By PEO in forum General Chat
    Replies: 9
    Last Post: 29th November 2007, 08:12 AM
  4. Replies: 0
    Last Post: 2nd November 2007, 09:58 AM
  5. Anyone had dealings with http://www.inco-soft.net
    By jumpinjamez in forum Web Development
    Replies: 21
    Last Post: 14th June 2007, 12:27 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •