Page 1 of 4

Remote command execution failed: Permission denied,please...

Posted: Wed Jun 11, 2014 5:10 am
by aleks1
Hi everybody! :)

I'm trying to implement a remote command from a nagios (let's call it for convenience nagios A :)) to the new nagios on ubuntu server 12.04 lts (nagios B) (this nagios on ubuntu server , was done , with the precious help of this forum :))
anyway i want to implement a simple command that control my nagios.log (on remote server nagios B)
i have just put the public key in authorized_keys.... and the access without password... works! the nagiosA access to the nagiosB only with a specific port: then i have tried the command from the command line:

Code: Select all

root@maestro: root@maestro:/etc/nagios-plugins/config# /usr/lib/nagios/plugins/check_by_ssh  -H 'intranet.xx.xx' -p '2022'  -C "/usr/local/nagios/libexec/check_nagios -F '/usr/local/nagios/var/nagios.log' -e '5' -C '/usr/local/nagios/bin/nagios'"

NAGIOS OK: 40 processes, status log updated 47 seconds ago 
ok works!
but when i try to implement this command on servece definition (for control automatically the remote nagios.log)
i got this error:

Code: Select all

backups;Nagios Status;UNKNOWN;SOFT;2;Remote command execution failed: Permission denied, please try again.
where am i wrong?

this is my command definition:

Code: Select all

define command{
        command_name    check_nagios_ssh
        command_line    /usr/lib/nagios/plugins/check_by_ssh -H '$HOSTADDRESS$' -p '$ARG4$' -C "/usr/local/nagios/libexec/check_nagios -F '$ARG1$' -e '$ARG2$' -C '$ARG3$'"
        }
this is my service definition:

Code: Select all

define service {
        use                     generic-service
        host_name               backups
        service_description     Nagios Status
        check_command           check_nagios_ssh!/usr/local/nagios/var/nagios.log!5!/usr/local/nagios/bin/nagios!2022
}
this is my host definition:

Code: Select all

define host{
        use                     generic-host            ; Name of host template to use
        host_name               backups
        alias                   Server Nagios
        address                 intranet.xx.xx
        }

any help be appreciate!!! :)

Re: Remote command execution failed: Permission denied,pleas

Posted: Wed Jun 11, 2014 5:40 am
by rajesh.mehra
Hi

You are using this command by root user but in back end it executes by nagios user.

Switch to nagios user and then run this command.

root@maestro: root@maestro:/etc/nagios-plugins/config# /usr/lib/nagios/plugins/check_by_ssh -H 'intranet.xx.xx' -p '2022' -C "/usr/local/nagios/libexec/check_nagios -F '/usr/local/nagios/var/nagios.log' -e '5' -C '/usr/local/nagios/bin/nagios'"



Tks
Rajesh Mehra

Re: Remote command execution failed: Permission denied,pleas

Posted: Wed Jun 11, 2014 6:47 am
by rajesh.mehra
1. Change your service and command definition according to below.



define command{
command_name check_nagios_ssh
command_line /usr/lib/nagios/plugins/check_by_ssh -H $ARG1$ -p $ARG2$ -l $ARG3$ -C $ARG4$
}



define service {
use generic-service
host_name backups
service_description Nagios Status
check_command check_nagios_ssh!22!root!"/usr/local/nagios/libexec/check_nagios -t 20 -e 5 -F /usr/local/nagios/var/nagios.log -C /usr/local/nagios/bin/nagios"
}


Tks
Rajesh Mehra

Re: Remote command execution failed: Permission denied,pleas

Posted: Wed Jun 11, 2014 8:00 am
by aleks1
hi! @rajesh.mehra
And thank you for reply!
so i use this command with root user in NagiosA (this is not my nagios)...because this nagios was implemented with root user (i don't know why! but everything belong to root user!)
now i try this your configuration! :)

Code: Select all

define command{
command_name check_nagios_ssh
command_line /usr/lib/nagios/plugins/check_by_ssh -H $ARG1$ -p $ARG2$ -l $ARG3$ -C $ARG4$
}



define service {
use generic-service
host_name backups
service_description Nagios Status
check_command check_nagios_ssh!22!root!"/usr/local/nagios/libexec/check_nagios -t 20 -e 5 -F /usr/local/nagios/var/nagios.log -C /usr/local/nagios/bin/nagios"
}

Re: Remote command execution failed: Permission denied,pleas

Posted: Wed Jun 11, 2014 8:22 am
by aleks1
hi! @rajesh.mehra
i have tried your configuration!

command definition:

Code: Select all

define command{
command_name check_nagios_ssh
command_line /usr/lib/nagios/plugins/check_by_ssh -H $ARG1$ -p $ARG2$ -l $ARG3$ -C $ARG4$
}
and service definition:

Code: Select all

define service {
        use generic-service
        host_name backups
        service_description Nagios Status
        check_command check_nagios_ssh!22!root!"/usr/local/nagios/libexec/check_nagios -t 20 -e 5 -F /usr/local/nagios/var/nagios.log -C /usr/local/nagios/bin/nagios"
}
but the error now is another:

Code: Select all

SERVICE ALERT: backups;Nagios Status;UNKNOWN;SOFT;2;check_by_ssh: Port must be a positive integer

Re: Remote command execution failed: Permission denied,pleas

Posted: Wed Jun 11, 2014 11:51 am
by rajesh.mehra
You are using ssh port 2022 so please change service defination 22 to 2022

Re: Remote command execution failed: Permission denied,pleas

Posted: Wed Jun 11, 2014 12:40 pm
by scottwilkerson
Yep, rajesh.mehra is onto it, change

Code: Select all

define service {
        use generic-service
        host_name backups
        service_description Nagios Status
        check_command check_nagios_ssh!22!root!"/usr/local/nagios/libexec/check_nagios -t 20 -e 5 -F /usr/local/nagios/var/nagios.log -C /usr/local/nagios/bin/nagios"
}
to

Code: Select all

define service {
        use generic-service
        host_name backups
        service_description Nagios Status
        check_command check_nagios_ssh!2022!root!"/usr/local/nagios/libexec/check_nagios -t 20 -e 5 -F /usr/local/nagios/var/nagios.log -C /usr/local/nagios/bin/nagios"
}

Re: Remote command execution failed: Permission denied,pleas

Posted: Thu Jun 12, 2014 2:59 am
by aleks1
i change it! :)
now is:

Code: Select all

define service {
        use generic-service
        host_name backups
        service_description Nagios Status
        check_command check_nagios_ssh!2022!root!"/usr/local/nagios/libexec/check_nagios -t 20 -e 5 -F /usr/local/nagios/var/nagios.log -C /usr/local/nagios/bin/nagios"
}
but i got this error:

Code: Select all

SERVICE ALERT: backups;Nagios Status;UNKNOWN;SOFT;1;check_by_ssh: Port must be a positive integer

Re: Remote command execution failed: Permission denied,pleas

Posted: Thu Jun 12, 2014 4:17 am
by rajesh.mehra
1. Check version of nagios-plugin

Code: Select all

[root@srv01 libexec]# ./check_by_ssh -V
check_by_ssh v1.4.16 (nagios-plugins 1.4.16)
[root@srv01 libexec]#
2. Is your other services working fine except check_by_ssh?
3. Is server able to connect without password?
4. Run this command on terminal

Code: Select all

/usr/lib/nagios/plugins/check_by_ssh -H your.remoteserver.address -l root -p 2022 -C "/usr/local/nagios/libexec/check_nagios -t 20 -e 5 -F /usr/local/nagios/var/nagios.log -C /usr/local/nagios/bin/nagios" -vvvvvvvvv 
5.Post output of above here.

Re: Remote command execution failed: Permission denied,pleas

Posted: Thu Jun 12, 2014 5:05 am
by aleks1
Hi! and thank you for the support! :)
1. Check version of nagios-plugin

Code: Select all

root@maestro:/usr/lib/nagios/plugins# ./check_by_ssh -V
check_by_ssh v1.4.15 (nagios-plugins 1.4.15)
2. Is your other services working fine except check_by_ssh?
i have the check ssh to port 2022 service and check tcp port 2022 service and both.... works!
3. Is server able to connect without password?
yeah i'm able :):

Code: Select all

root@maestro:/usr/lib/nagios/plugins# ssh -p 2022 [email protected]
Welcome to Ubuntu 12.04.1 LTS 
Last login: Thu Jun 12 09:47:45 2014 from 10.188.1.78
root@backups:~# 
4. Run this command on terminal

Code: Select all

root@maestro:/usr/lib/nagios/plugins# /usr/lib/nagios/plugins/check_by_ssh -H intranet.xx.xx -l root -p 2022 -C "/usr/local/nagios/libexec/check_nagios -t 20 -e 5 -F /usr/local/nagios/var/nagios.log -C /usr/local/nagios/bin/nagios" -vvvvvvvvv 
Command: /usr/bin/ssh
Argument 1: -l
Argument 2: root
Argument 3: -p
Argument 4: 2022
Argument 5: intranet.xx.xx
Argument 6: /usr/local/nagios/libexec/check_nagios -t 20 -e 5 -F /usr/local/nagios/var/nagios.log -C /usr/local/nagios/bin/nagios
NAGIOS OK: 41 processes, status log updated 68 seconds ago