Passing arguments to nagios plugin
Solution 1:
In the service definition you put the host_name of the host where the service is running that you want to check.
The check_command definition my_command!whatever
will pass whatever
to the command definition as $ARG1$. Add more !more
for $ARG2$, etc.
You need to pass the needed parameters to my_shell_script.sh
in the command definition. You have access to things like $HOSTNAME$ and $HOSTADDRESS$; the command you define in the define command
section will be run locally on the nagios server; for things like nrpe there's a command definition that connects to the nrpe server... hence also then the command is run locally!
Start here for nagios documentation, e.g. "The Basics" and "Standard Macros in Nagios".
Solution 2:
To Register and use custom plugin with parameter use following example
#!/bin/bash
URL=$1
if curl -s --head $URL | grep "200 OK" > /dev/null
then echo "Ok - $URL is up!"
exit 0
else echo "CRITICAL - $URL is down!"
exit 2
fi
Give Required permission and ownership same permission as built-in plugin
To test plugin individually
./check_web_url <<WEBSITE_URL>>
add defination in commands.cfg
define command {
command_name check_web_url
command_line $USER1$/check_web_url $ARG1$
}
Add check_web_url in cfg file
define service{
use local-service
host_name <specify-hostname>
service_description Check url
check_command check_web_url!http://website_url_will_here
check_interval 1
}