Page 1 of 1
check_command syntax in define service?
Posted: Tue Oct 17, 2017 9:28 pm
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
}
Re: check_command syntax in define service?
Posted: Tue Oct 17, 2017 9:31 pm
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.
Re: check_command syntax in define service?
Posted: Wed Oct 18, 2017 9:43 am
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?
Re: check_command syntax in define service?
Posted: Wed Oct 18, 2017 1:31 pm
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
}
Re: check_command syntax in define service?
Posted: Wed Oct 18, 2017 2:11 pm
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)
Re: check_command syntax in define service?
Posted: Wed Oct 18, 2017 2:51 pm
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
Re: check_command syntax in define service?
Posted: Wed Oct 18, 2017 4:07 pm
by eloyd
Re: check_command syntax in define service?
Posted: Thu Oct 19, 2017 11:51 am
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 (5.93 KiB) Viewed 16111 times