1st plugin, not sure about passing arguments

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
larryq
Posts: 8
Joined: Thu Aug 28, 2014 3:11 pm

1st plugin, not sure about passing arguments

Post 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.
Last edited by larryq on Wed Oct 15, 2014 10:20 am, edited 1 time in total.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: 1st plugin, not sure about passing arguments

Post 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"
Former Nagios employee
larryq
Posts: 8
Joined: Thu Aug 28, 2014 3:11 pm

Re: 1st plugin, not sure about passing arguments

Post 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.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: 1st plugin, not sure about passing arguments

Post by tmcdonald »

Let me know how that works out for you
Former Nagios employee
larryq
Posts: 8
Joined: Thu Aug 28, 2014 3:11 pm

Re: 1st plugin, not sure about passing arguments

Post 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?
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: 1st plugin, not sure about passing arguments

Post 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.
larryq
Posts: 8
Joined: Thu Aug 28, 2014 3:11 pm

Re: 1st plugin, not sure about passing arguments

Post 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.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: 1st plugin, not sure about passing arguments

Post 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!
Former Nagios employee
Locked