check_command syntax in define service?

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
ikekim
Posts: 85
Joined: Wed Aug 16, 2017 12:21 pm

check_command syntax in define service?

Post by ikekim »

I'm trying to create define service and want to use the "check_tcp" command and I can execute the command like this and it works. I used -h to get the help.

Code: Select all

./check_tcp -H 192.168.9.11 -p 1433
However, I'm not sure how to find the proper syntax & format when I'm trying to define it in the service for the "check_command".
My command syntax doesn't work in the below snipet, but how & where do I find the proper syntax? thanks, ik.

Code: Select all

# Define a service to check TCP on the remote machine.
define service{
        use                             local-service         ; Name of service template to use
        host_name                       infor1
        service_description             tcp
        check_command                   check_tcp! -f ok -I 192.168.1.100 -p 80
        notifications_enabled           0
        }
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: check_command syntax in define service?

Post by eloyd »

We'll also need to see the section of your "commands.cfg" that shows the check_tcp command. The "check_command" directive is really just a bunch of fields that go into the template defined by the command called "check_tcp" inside of commands.cfg, so the "fields" have to match.

Please post the appropriate section of your commands.cfg so we can check that out.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
kyang

Re: check_command syntax in define service?

Post by kyang »

Thanks @eloyd!

@ikekim, The commands.cfg for your check_tcp would help.

Also by "doesn't work" Do you mean Nagios has configuration errors?
ikekim
Posts: 85
Joined: Wed Aug 16, 2017 12:21 pm

Re: check_command syntax in define service?

Post by ikekim »

@eloyd

In commands.cfg, I see this part:

Code: Select all

# 'check_tcp' command definition
define command{
        command_name    check_tcp
        command_line    $USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$
        }
Therefore, when I define the service something like this, I get the error message "check_tcp: Port must be a positive integer ".

Code: Select all

# Define a service to check TCP on the remote machine.
define service{
        use                             local-service         ; Name of service template to use
        host_name                       iis-server1
        service_description             tcp
        check_command                   check_tcp!-H 192.168.9.100 -p 80
        notifications_enabled           0
        }
kyang

Re: check_command syntax in define service?

Post by kyang »

So I deleted the -p in the command, and set it under $ARG1$ in my check_command for the service.

Code: Select all

# 'check_tcp' command definition
define command{
        command_name    check_tcp
        command_line    $USER1$/check_tcp -H $HOSTADDRESS$ $ARG1$
        }

Code: Select all

# Define a service to check TCP on the remote machine.
define service{
        use                             local-service         ; Name of service template to use
        host_name                       localhost
        service_description             tcp
        check_command                   check_tcp!-H 192.168.4.125 -p 80
        notifications_enabled           0
        }
Let us know if it works! (It works on mine)
ikekim
Posts: 85
Joined: Wed Aug 16, 2017 12:21 pm

Re: check_command syntax in define service?

Post by ikekim »

@kyang,

This format gives me the error "check_tcp: Port must be a positive integer ".

Code: Select all

define service{
        use                             local-service         ; Name of service template to use
        host_name                       iis-server1
        service_description             tcp
        check_command                   check_tcp!-H 192.168.9.100 -p 80
        notifications_enabled           0
        }
This format works -

Code: Select all

define service{
        use                             local-service         ; Name of service template to use
        host_name                       iis-server1
        service_description             tcp
        check_command                   check_tcp! 80
        notifications_enabled           0
        }
I'm guessing maybe that yours appears to be working until the next check?

So even if I refer to the content of commands.cfg, this doesn't show me how the syntax works and I'm looking to find out if there is one.
As an example, ! is part of the syntax, but I don't see any where this should be part of the config format.

thanks,
ik
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: check_command syntax in define service?

Post by eloyd »

Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
kyang

Re: check_command syntax in define service?

Post by kyang »

Thanks @eloyd!

Mine actually still works after 1 day. The article eloyd posted is where you will find the syntax of !
If you want to pass arguments to commands during runtime, you can use $ARGn$ macros in the command_line directive of the command definition and then separate individual arguments from the command name (and from each other) using bang (!) characters in the object definition directive (host check command, service event handler command, etc) that references the command. More information on how arguments in command definitions are processed during runtime can be found in the documentation on macros.
port.PNG
port.PNG (5.93 KiB) Viewed 15995 times
Locked