Nagios own command use
-
aleksandrs.jurcenko
- Posts: 8
- Joined: Mon Mar 02, 2015 8:36 am
Nagios own command use
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?
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
For this you're going to want to use `check_by_ssh`:
So in your case the command could look like this:
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.
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]
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"
}-
aleksandrs.jurcenko
- Posts: 8
- Joined: Mon Mar 02, 2015 8:36 am
Re: Nagios own command use
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""
}
???
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
That should be very possible. I would recommend wrapping that up into a shell script.
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.
Code: Select all
#!/usr/bin/bash
ssh [email protected] "/usr/local/nagios/libexec/check_load -w 1,1,1 -c 3,3,3"
exit $?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
I wrote:
my3.sh (bash script)
and in .cfg file I call:
and the output in the Nagios is:
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 $?
Code: Select all
define command{
command_name my_com
command_line $USER1$/my3
}
But the file location is correct...(No output on stdout) stderr: execvp(/usr/local/nagios/libexec/my3, ...) failed. errno is 2: No such file or directory
-
jdalrymple
- Skynet Drone
- Posts: 2620
- Joined: Wed Feb 11, 2015 1:56 pm
Re: Nagios own command use
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?
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
No problem is not in my3.sh
yes, i can run script manually.
./my3.sh
all will work
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
I'm sorry, I think you misunderstood what I meant.
You showed us your command definition:
But I think maybe it should be:
You showed us your command definition:
Code: Select all
define command{
command_name my_com
command_line $USER1$/my3
}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
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
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
It needs to be:
Please post the output of the following:
Code: Select all
define command{
command_name my_com
command_line $USER1$/my3.sh
}Code: Select all
ls -l /usr/local/nagios/libexec/my3*