whats app plugin for Nagios


If you want to send alerts to your phone on watsapp this is one way . 

apt-get install python python-dateutil python-argparse python-dev python-setuptools



python install setup.py

cd yowsup

./yowsup-cli registration --requestcode sms --phone 91yournumber  --cc 91  --mcc 404 --mnc 20

./yowsup-cli registration --register 671587 --phone 91yournumber --cc 91


cat yowsup-cli.config

cc=91
phone=yournumber
id=yourimeanumber
password=yourpassword


./yowsup-cli demos -c yowsup-cli.config  -s tonumber " saleeeeee"


Nagios Plugin config : 


cat /etc/nagios3/commands.cfg
 
define command{
        command_name    notify-service-by-watsapp
        command_line    /usr/lib/nagios/plugins/whatsapp.sh --numbers $_CONTACTDEVOPSPHONE$  --msg "***** Nagios : $NOTIFICATIONTYPE$ ***** \n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$ "
}


cat  /etc/nagios3/contacts.cfg


define contact{
        contact_name                    admin
        alias                           root
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,r
        service_notification_commands   notify-service-by-email,notify-service-by-watsapp
        host_notification_commands      notify-host-by-email
        _devopsphone                    9819031945
        email                           youremailid
        }




cat /usr/lib/nagios/plugins/whatsapp.sh

#!/bin/bash


while [  "$1" != "" ]
do
case "$1" in
--numbers) numbers=$2; shift;;
--msg) msg=$2; shift;;
*) echo "$0: invalid option $1" >&2
echo "Usage: $0   --numbers 9819031911 --msg \" test mgs\"" >&2
exit 1
esac
shift
done


ph_nums=($(echo $numbers | sed 's/,/ /g' ))

prntmsg=$(printf "$msg")


for i in ${ph_nums[@]}
do
sudo /opt/yowsup/yowsup/yowsup-cli demos -c /opt/yowsup/yowsup/yowsup-cli.config  -s 91${i} "$prntmsg"
echo "$i $msg"

done

send email using MIME::Lite::TT::HTML

#!/usr/bin/perl

 use strict;
 use warnings;
 use MIME::Lite::TT::HTML;




email ('agnello','agnello.dsouza@gmail.com');


sub email {

 my ( $recruiter_name, $to ) = @_;

 my %options;
 $options{INCLUDE_PATH} = '/scripts';
 my %params;
 $params{recruiter_name} = $recruiter_name ;

 my $msg = MIME::Lite::TT::HTML->new(
          From        =>  'agnello.dsouza@gmail.com'  ,
            To          =>  $to,
            Subject     =>  'Some subject  ',
            Template    =>  {
                                html     =>  'resume.tt',
                                text     =>  'text.resume.tt',
                            },
            TmplOptions =>  \%options,
            TmplParams  =>  \%params,
 );

# Set our content type properly
 $msg->attr("content-type"  => "multipart/mixed");

 # Attach a PDF to the message
 $msg->attach(  Type        =>  'application/pdf',
                Path        =>  '/scripts',
                Filename    =>  'Agnello_dsouza.pdf',
                Disposition =>  'attachment'
 );


# $msg->send('smtp', "smtp.gmail.com",   SSL=>1,  AuthUser=>'agnello.dsouza.linux@gmail.com',  AuthPass=>'xxxxxxxxxx',  Debug=>1);
 $msg->send();


}

HACK : script to get all linkedin Contact email IDs -- part 1

#!/usr/bin/perl


use strict;
use warnings;
use WWW::Mechanize;
use LWP;
use JSON;
use Data::Dumper;
use Getopt::Long;
use POSIX qw/ strftime /;
my $username = 'agnello.dsouza';
my $password = 'xxxxxxxxxxxxxx';
my $loginurl=  $maiurl.'/uas/login?goback=&trk=hb_signin';
my $json_file = '/tmp/json.data';



my $mech = login_linkedin();

#my $jdata = get_jdata($mech,$all_data);
#write_to_file($jdata,$json_file);

my $jdata = read_from_file($json_file);

my @contacts = gen_url ($jdata);

foreach (@contacts){
my $fnd_details_json = get_jdata($mech,$_);
my $email = $fnd_details_json->{'contact_data'}->{'emails_extended'}->[0]->{'email'};
next unless ( $email);
print "$email\n"
}





sub gen_url {
my $jdata= shift;
my @url ;
for my $i (@{$jdata->{'contacts'}} ){
my $uri = $maiurl.'/contacts/api/contacts/'.$i->{'id'}.'/?fields=name,emails_extended,birthday,phone_numbers,sites,addresses,company,title,location,ims,profiles,twitter,wechat,display_sources';
push (@url,  $uri );
}
return @url;
}


sub get_jdata {
my ( $mech,$url ) =@_;
$mech -> get ("$url");
return    decode_json($mech ->content()) ;
}


sub login_linkedin {
my $mech = WWW::Mechanize->new();
$mech -> cookie_jar(HTTP::Cookies->new());


$mech -> get("$loginurl");
$mech -> form_id('login');
$mech -> field ('session_key' => $username);
$mech -> field ('session_password' => $password);
$mech -> click_button (value => 'Sign In');

return $mech ;

}



sub read_from_file {
my $file = shift;
my $json;

{
  local $/; #Enable 'slurp' mode
  open my $fh, "<", "$file";
  $json = <$fh>;
  close $fh;
 }
return decode_json($json);
}

sub write_to_file {
my $data  = shift;
my $file  = shift;
open my $fh, ">", "$file";
print $fh encode_json($data);
close $fh;
}


Other Articles

Enter your email address: