Page 1 of 2

Nagios own command use

Posted: Mon Mar 02, 2015 8:39 am
by aleksandrs.jurcenko
Hi,

i wanted to use this command in my Nagios: ssh [email protected] "/usr/local/nagios/libexec/check_load -w 1,1,1 -c 3,3,3"

if i run it, it works good. But how can i define it like a command?

define command{
command_name my_com
command_line ssh [email protected] "/usr/local/nagios/libexec/check_load -w 1,1,1 -c 3,3,3"
}

there will be error.

Also i tried make bash script "my_command.sh" where will be this command:
#!/bin/sh
ssh [email protected] "/usr/local/nagios/libexec/check_load -w 1,1,1 -c 3,3,3"

and after that in command.cfg use i wrote:

define command{
command_name my_com
command_line $USR1$/my_command.sh
}

But there also will be error.

Please, said me how can i write this command correctly?

Re: Nagios own command use

Posted: Mon Mar 02, 2015 9:55 am
by jdalrymple
For this you're going to want to use `check_by_ssh`:

Code: Select all

[jdalrymple@localhost ~]$ /usr/local/nagios/libexec/check_by_ssh --help
check_by_ssh v2.0.3 (nagios-plugins 2.0.3)
Copyright (c) 1999 Karl DeBisschop <[email protected]>
Copyright (c) 2000-2014 Nagios Plugin Development Team
        <[email protected]>

This plugin uses SSH to execute commands on a remote host

Usage:
 check_by_ssh -H <host> -C <command> [-fqv] [-1|-2] [-4|-6]
       [-S [lines]] [-E [lines]] [-t timeout] [-i identity]
       [-l user] [-n name] [-s servicelist] [-O outputfile]
       [-p port] [-o ssh-option] [-F configfile]
So in your case the command could look like this:

Code: Select all

define command{
command_name my_com
command_line $USER1$/check_by_ssh -H $HOSTADDRESS$ -l dir+dcsc_ldap -C "/usr/local/nagios/libexec/check_load -w 1,1,1 -c 3,3,3"
}
This will require that you configure the nagios user to have a public ssl key that is authorized on the remote system for the specified user. This is pretty clumsy and I highly recommend you look into doing this using nrpe instead of ssh.

Re: Nagios own command use

Posted: Mon Mar 02, 2015 11:21 am
by aleksandrs.jurcenko
Can I make it without check_by_ssh and check_nrpe?

I need that it was like:
ssh [email protected] "/usr/local/nagios/libexec/check_load -w 1,1,1 -c 3,3,3"

How I can put it to command?

define command{
command_name my_com
command_line "ssh [email protected] "/usr/local/nagios/libexec/check_load -w 1,1,1 -c 3,3,3""
}

???

Re: Nagios own command use

Posted: Mon Mar 02, 2015 12:17 pm
by jdalrymple
That should be very possible. I would recommend wrapping that up into a shell script.

Code: Select all

#!/usr/bin/bash
ssh [email protected] "/usr/local/nagios/libexec/check_load -w 1,1,1 -c 3,3,3"
exit $?
Obviously your nagios user would still have to logon using its public key, there is no way for Nagios to pass in the password.

I still very much encourage using nrpe, it is trivial to setup and this is exactly what it was designed to do.

Re: Nagios own command use

Posted: Tue Mar 03, 2015 4:04 am
by aleksandrs.jurcenko
I wrote:

my3.sh (bash script)

Code: Select all

#!/bin/sh
ssh [email protected] "/usr/local/nagios/libexec/check_load -w 1,1,1 -c 3,3,3"
exit $?
and in .cfg file I call:

Code: Select all

define command{
        command_name    my_com
        command_line    $USER1$/my3
        }
and the output in the Nagios is:
(No output on stdout) stderr: execvp(/usr/local/nagios/libexec/my3, ...) failed. errno is 2: No such file or directory
But the file location is correct...

Re: Nagios own command use

Posted: Tue Mar 03, 2015 9:39 am
by jdalrymple
You indicated that the file name is my3.sh but in your command definition you just used my3. Is that the problem?

Also, is the script executable by the nagios user?

Re: Nagios own command use

Posted: Tue Mar 03, 2015 9:42 am
by aleksandrs.jurcenko
No problem is not in my3.sh

yes, i can run script manually.
./my3.sh
all will work

Re: Nagios own command use

Posted: Tue Mar 03, 2015 9:54 am
by jdalrymple
I'm sorry, I think you misunderstood what I meant.

You showed us your command definition:

Code: Select all

define command{
        command_name    my_com
        command_line    $USER1$/my3
        }
But I think maybe it should be:

Code: Select all

define command{
        command_name    my_com
        command_line    $USER1$/my3.sh
        }

Re: Nagios own command use

Posted: Tue Mar 03, 2015 10:32 am
by aleksandrs.jurcenko
no, I understood you.
I have tried with both variant, the result is the same :(

(No output on stdout) stderr: execvp(/usr/local/nagios/libexec/my3, ...) failed. errno is 2: No such file or directory

Re: Nagios own command use

Posted: Tue Mar 03, 2015 11:20 am
by ssax
It needs to be:

Code: Select all

define command{
        command_name    my_com
        command_line    $USER1$/my3.sh
        }
Please post the output of the following:

Code: Select all

ls -l /usr/local/nagios/libexec/my3*