Page 1 of 1

1st plugin, not sure about passing arguments

Posted: Tue Oct 14, 2014 5:51 pm
by larryq
Hi everyone,

I've installed my first plugin on a Nagios server, but am having trouble getting the arguments right. I've tried some things with $ARG1$ but realized, after doing this and that, I'm essentially just flopping around.

One complication, perhaps: this plugin is supposed to run on the nagios server itself, no npre call to a remote box.

The plugin is a shell script that makes a curl call against a remote box under the hood. Typical command line use with flags would read:

Code: Select all

my_shell_script.sh -H my.server.of.interest -P 9000 -I ./tmp/settings_file -timeout 80
(yes, it has its own '-H' flag, unrelated to nagios' hostname flag.)

Here's the skeleton I have right now. Nagios appears to think all my flags are one giant one.

Code: Select all

define command {
	command_name 	my_command
	command_line 	$USER1$/my_shell_script.sh $ARG1$
}

define service {
	use						generic-service;
	host_name				{{what do I put here?  This is supposed to run on the nagios box itself. My shell script is installed on it.}};
	service_description		some description
	check_command			my_command!{{what goes here?}}
}
The above is a little stripped down for readability, but that's the gist of it. It's the hostname and arguments and bits in the 'what do I put here' that are giving me trouble. I could use a nudge, and thanks for the suggestions.

Re: 1st plugin, not sure about passing arguments

Posted: Tue Oct 14, 2014 10:57 pm
by tmcdonald
A service needs to be attached to a host, so if you already have a localhost host set up, just put "localhost" in there.

For the command, you will wanna put this:

Code: Select all

my_command!"-H my.server.of.interest -P 9000 -I ./tmp/settings_file -timeout 80"

Re: 1st plugin, not sure about passing arguments

Posted: Wed Oct 15, 2014 9:31 am
by larryq
tmcdonald wrote:A service needs to be attached to a host, so if you already have a localhost host set up, just put "localhost" in there.

For the command, you will wanna put this:

Code: Select all

my_command!"-H my.server.of.interest -P 9000 -I ./tmp/settings_file -timeout 80"
Thank you very much, I'll try that.

Re: 1st plugin, not sure about passing arguments

Posted: Wed Oct 15, 2014 9:35 am
by tmcdonald
Let me know how that works out for you

Re: 1st plugin, not sure about passing arguments

Posted: Thu Oct 16, 2014 9:34 am
by larryq
Hmm. My new setup now reads like this:

Code: Select all

define command {
   command_name    my_command
   command_line    $USER1$/my_shell_script.sh 
}

define service {
   use                  generic-service;
   host_name           localhost;
   service_description      some description
   check_command         my_command!"-H my.server.of.interest -P 9000 -I ./tmp/settings_file -timeout 80"
}
...however, when I run this in Nagios I have the script print out the value of the first command line argument ($1 in unix terms) and it doesn't show anything. It's as if I'm not sending any command line arguments to the script. Have I missed something (quite likely) in the setup above?

Re: 1st plugin, not sure about passing arguments

Posted: Thu Oct 16, 2014 9:56 am
by slansing
Does the plugin require you wrap everything in double quotes? That should not be a valid config option for that entire string, try something like, or variations of:

Code: Select all

   check_command         my_command!-H $HOSTADDRESS$ -P 9000 -I ./tmp/settings_file -timeout 80
Now, that is all one argument you are using, and you don't have an argument set on the command itself:

Code: Select all

   command_line    $USER1$/my_shell_script.sh $ARG1$
What plugin are you using? You really need to look at it's usage/help output to know what flags are required, and what is accepted.

Re: 1st plugin, not sure about passing arguments

Posted: Fri Oct 17, 2014 7:10 pm
by larryq
Thanks for the assistance. I finally got this working after studying this tutorial here:
http://nagios.sourceforge.net/docs/nagi ... acros.html

My final entries read like this:

Code: Select all

check_command     my_command!$HOSTADDRESS$!9000!./tmp/settings_file!80

command_line       $USER1$/my_shell_script.sh -H $ARG1$ -P $ARG2$ -I $ARG3$ -T $ARG4$  
Not sure if that's the best way to do it but it worked for me.

Re: 1st plugin, not sure about passing arguments

Posted: Mon Oct 20, 2014 9:18 am
by tmcdonald
That's a perfectly valid way of configuring the check, and as slansing pointed out, splitting it up into multiple arguments is a bit easier to maintain and read.

I'll go ahead and close this thread now, but feel free to open another if you have any questions in the future!