Page 1 of 1

ActionsComponent

Posted: Wed Apr 08, 2015 12:41 pm
by monitoreo1
Hi,
I have the following shell scrip
It runs fine on Linux console
But when run from a ActionsComponent :
/usr/local/nagios/libexec/script.sh %hostaddress% %hostname%

The desired result is not obtained

#!/bin/bash
#Parametros de entrada
HOSTADDRESS=$1
HOSTNAME=$2
USER=" "
PASS=" "

HOSTNAMEUP="$(echo $HOSTNAME | tr '[a-z]' '[A-Z]')"
SUFIJO="_SAZ_10.log"
RUTA=/logs/$DIR/producto/JBOSS/JBOSS62/SAZ/$HOSTNAMEUP$SUFIJO
scp -pr $USER@$HOSTADDRESS:$RUTA ./$HOSTNAMEUP$SUFIJO

cat $HOSTNAMEUP$SUFIJO

Nagios XI Version : 2014R2.6
x86_64
Red Hat Enterprise Linux Server release 7.0 (Maipo)

Re: ActionsComponent

Posted: Wed Apr 08, 2015 12:48 pm
by abrist
Does your hostname include spaces? If so, please wrap the variables in quotes:

Code: Select all

/usr/local/nagios/libexec/script.sh %hostaddress% "%hostname%"
Also, could you echo the incoming variables to a file to see if they are populated correctly?

Code: Select all

#!/bin/bash
#Parametros de entrada
HOSTADDRESS=$1
HOSTNAME="$2"
USER=" "
PASS=" "

echo "$HOSTNAME" > /tmp/actions_test.txt
echo "$HOSTADDRESS" >> /tmp/actions_test.txt

HOSTNAMEUP="$(echo "$HOSTNAME" | tr '[a-z]' '[A-Z]')"
SUFIJO="_SAZ_10.log"
RUTA=/logs/$DIR/producto/JBOSS/JBOSS62/SAZ/$HOSTNAMEUP$SUFIJO
scp -pr $USER@$HOSTADDRESS:$RUTA ./$HOSTNAMEUP$SUFIJO

cat $HOSTNAMEUP$SUFIJO

Re: ActionsComponent

Posted: Wed Apr 08, 2015 1:12 pm
by monitoreo1
I already made the modification to ActionsComponent :
/usr/local/nagios/libexec/logsSAZ.sh %hostaddress% "%hostname%"

The result from nagios is

Running: /usr/local/nagios/libexec/logsSAZ.sh
150.250.146.101
"lvmclcasjbnp01"

But it does not copy the file

It runs fine on Linux console

[root@lvm libexec]# ./logsSAZ.sh $ipaddress lvmclcasjbnp01
lvmclcasjbnp01
$ipaddress
Get the copy : LVM_SAZ_10.log

Re: ActionsComponent

Posted: Wed Apr 08, 2015 2:49 pm
by jdalrymple
selinux *should* be disabled by the NagiosXI intall, but can you verify?

Does the user nagios have proper permissions to execute scp? Are the proper ssh bits in place for passwordless SSH authentication to the remote host?

Re: ActionsComponent

Posted: Thu Apr 09, 2015 9:23 am
by monitoreo1
Nagios It does not execute scp and ssh.
How could solve this detail.

Re: ActionsComponent

Posted: Thu Apr 09, 2015 9:34 am
by ssax
The problem is that scp requires you to accept the key fingerprint:

You can do that this way, from the XI box:

Code: Select all

su - nagios
ssh user@yourserver
Then accept the key, you would have to do this for all the machines you want to connect to though so the nagios user has those fingerprints cached.

You could also use this command, I wouldn't recommend it for security reasons but it is an option:

Code: Select all

scp -pr -oStrictHostKeyChecking=no $USER@$HOSTADDRESS:$RUTA ./$HOSTNAMEUP$SUFIJO
You could also follow this guide:
http://xmodulo.com/how-to-accept-ssh-ho ... linux.html

Re: ActionsComponent

Posted: Thu Apr 09, 2015 11:09 am
by monitoreo1
You can close the topic.
Thanks