Notification Command Failing

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
agutierrezps
Posts: 7
Joined: Tue Jul 30, 2013 5:12 pm

Notification Command Failing

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Notification Command Failing

Post 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?
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
agutierrezps
Posts: 7
Joined: Tue Jul 30, 2013 5:12 pm

Re: Notification Command Failing

Post 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.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Notification Command Failing

Post by abrist »

You will need to install a package for that lib if you do not have it. What distro are you running?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
agutierrezps
Posts: 7
Joined: Tue Jul 30, 2013 5:12 pm

Re: Notification Command Failing

Post 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.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Notification Command Failing

Post 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?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
agutierrezps
Posts: 7
Joined: Tue Jul 30, 2013 5:12 pm

Re: Notification Command Failing

Post by agutierrezps »

Yes, that is correct.

Those libraries are installed.

Greetings
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Notification Command Failing

Post 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:

Code: Select all

/usr/loca/nagios......
should be:

Code: Select all

/usr/local/nagios.......
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked