Nagios own command use

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
aleksandrs.jurcenko
Posts: 8
Joined: Mon Mar 02, 2015 8:36 am

Nagios own command use

Post 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?
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Nagios own command use

Post 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.
aleksandrs.jurcenko
Posts: 8
Joined: Mon Mar 02, 2015 8:36 am

Re: Nagios own command use

Post 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""
}

???
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Nagios own command use

Post 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.
aleksandrs.jurcenko
Posts: 8
Joined: Mon Mar 02, 2015 8:36 am

Re: Nagios own command use

Post 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...
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Nagios own command use

Post 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?
aleksandrs.jurcenko
Posts: 8
Joined: Mon Mar 02, 2015 8:36 am

Re: Nagios own command use

Post by aleksandrs.jurcenko »

No problem is not in my3.sh

yes, i can run script manually.
./my3.sh
all will work
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Nagios own command use

Post 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
        }
aleksandrs.jurcenko
Posts: 8
Joined: Mon Mar 02, 2015 8:36 am

Re: Nagios own command use

Post 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
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Nagios own command use

Post 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*
Locked