Page 1 of 1
Notification Command Failing
Posted: Tue Jul 30, 2013 5:18 pm
by agutierrezps
Hello everyone,
I'm having a problem when it comes to the notification commands. You see i have a script made in perl which sends tweets as alarms, if i execute it manually it works but it doesnt works when an alarm is activacted and sends the notification.
Here is my command definition:
Code: Select all
define command{
command_name host-notify-by-twitter_mex
command_line /usr/local/nagios/bin/twitter.pl MEX $HOSTNAME$ "State: $HOSTSTATE$" "Info: $HOSTOUTPUT$" "Date: $LONGDATETIME$" >> /FILES/latam/nagios/var/debug_twitter.log
}
define command{
command_name notify-by-twitter_mex
command_line /usr/loca/nagios/bin/twitter.pl MEX '$HOSTSTATE$' '$HOSTNAME$' '$SERVICEDESC$' '$SERVICEOUTPUT$' > /FILES/latam/nagios/var/debug_twitter.log
}
This is driving me nuts, since the script is working but no there is no reason given why the notification executes the command but nothing happens.
Re: Notification Command Failing
Posted: Tue Jul 30, 2013 8:44 pm
by scottwilkerson
Have you added the notification command to a contact?
What are the permissions on these files?
Code: Select all
ls -l /usr/local/nagios/bin/twitter.pl
ls -l /FILES/latam/nagios/var/debug_twitter.log
The log needs to be writable by the nagios user and twitter.pl needs to be executable
Doe twitter.pl have any use lib lines in the script?
Re: Notification Command Failing
Posted: Wed Jul 31, 2013 10:03 am
by agutierrezps
Hello,
Thanks for you answer.
Yes i have added the notification command to a contact.
The permissions of the files are the following
-rwxr-xr-x 1 twitter.pl
-rw-rw-r-- 1 debug_twitter.log
This is the content of the script in perl
Code: Select all
use Net::Twitter::Lite::WithAPIv1_1;
use Switch;
my $consumer_key = "";
my $consumer_secret = "";
my $access_token = "";
my $access_token_secret = "";
my $region = $ARGV[0];
my $type = $ARGV[1];
my $hostname = $ARGV[2];
my $service_desc = $ARGV[3];
my $service_out = $ARGV[4];
my $url = $url = "http://localhost.nagios.com/nagios/cgi-bin/extinfo.cgi?type=2&host=";
my $tweet = Net::Twitter::Lite::WithAPIv1_1->new(consumer_key => $consumer_key,
consumer_secret => $consumer_secret,
access_token => $access_token,
access_token_secret => $access_token_secret);
my $prepare_tweet = $type." in ".$hostname." on ".$service_desc." ( ".$service_out." ) ".$url.$hostname."&service=".$service_desc;
my $result = $tweet->update({status => $prepare_tweet});
I've deleted the tokens for twitter
This use lib you mention i don't have it.
My perl instalation has the following folders
bin, lib, man
Greetings.
Re: Notification Command Failing
Posted: Wed Jul 31, 2013 11:05 am
by abrist
You will need to install a package for that lib if you do not have it. What distro are you running?
Re: Notification Command Failing
Posted: Wed Jul 31, 2013 11:39 am
by agutierrezps
I already have the lib's needed for Twitter.
My question was about the "use lib".
scottwilkerson said this
Doe twitter.pl have any use lib lines in the script?
Greetings.
Re: Notification Command Failing
Posted: Wed Jul 31, 2013 12:50 pm
by abrist
I believe Scott was referring to the lines:
Code: Select all
use Net::Twitter::Lite::WithAPIv1_1;
use Switch;
Those libraries are installed, correct?
Re: Notification Command Failing
Posted: Wed Jul 31, 2013 2:51 pm
by agutierrezps
Yes, that is correct.
Those libraries are installed.
Greetings
Re: Notification Command Failing
Posted: Wed Jul 31, 2013 4:39 pm
by abrist
What does a standard output of the script form the cli look like?
Though probably not related, your commands above are odd:
The order of passed macros are different between the two commands - one starts with HOSTSTATE, the other starts with HOSTNAME. Additionally, The first command appends to the log (>>), while the other overwrites the log (>). Finally, the second command has an invalid path:
should be: