hi mcapra
Thanks for your comments. I also find that the hostname will be correctly substituted when it's put into the check_command, but not when it is within a custom object variable and then the resulting object macro. Below are some more detailed reproduction steps.
regards
-jeff
The following test script, named test_macro.sh
Code: Select all
#!/bin/bash
function _log {
echo "`date`:$$:$@" >> /tmp/test_macro.log
}
while getopts 'q:z:' OPT "$@"; do
case ${OPT} in
q) PROMETHEUS_QUERY="$OPTARG" ;;
z) TESTNUM="$OPTARG" ;;
esac
done
_log "$TESTNUM query: [$PROMETHEUS_QUERY]"
together with these definitions:
Code: Select all
define hostgroup {
hostgroup_name test-macro
alias test
members dev1
}
define command {
command_name test_macro
command_line $USER32$/test_macro.sh -q '$ARG1$' -z '$ARG2$'
}
define service {
use prometheus-service-template
hostgroup_name test-macro
service_description test1
_promql HBase_GcTimeMillis{instance=~\"'$HOSTNAME$''\\'..*\"}/HBase_GcCount
check_command test_macro!$_SERVICEPROMQL$!test1
}
define service {
use prometheus-service-template
hostgroup_name test-macro
service_description test2
_i instance=~\"'$HOSTNAME$''\\'..*\"
_promql HBase_GcTimeMillis{$_SERVICEI$}/HBase_GcCount{$_SERVICEI$}
check_command test_macro!$_SERVICEPROMQL$!test2
}
define service {
use prometheus-service-template
hostgroup_name test-macro
service_description test3
_i instance=~\"'$HOSTNAME$''\\'..*\"
check_command test_macro!$_SERVICEI$!test3
}
define service {
use prometheus-service-template
hostgroup_name test-macro
service_description test4
_i $HOSTNAME$
check_command test_macro!$_SERVICEI$!test4
}
define service {
use prometheus-service-template
hostgroup_name test-macro
service_description test5
_i qwertyuiop
check_command test_macro!$_SERVICEI$!test5
}
define service {
use prometheus-service-template
hostgroup_name test-macro
service_description test6
check_command test_macro!"blahblahblah $HOSTNAME$ blahblah"!test6
}
define service {
use prometheus-service-template
hostgroup_name test-macro
service_description test7
check_command test_macro!$HOSTNAME$!test7
}
define service {
use prometheus-service-template
hostgroup_name test-macro
service_description test8
check_command test_macro!HBase_GcTimeMillis{instance=~"$HOSTNAME$"}/HBase_GcCount!test8
}
define service {
use prometheus-service-template
hostgroup_name test-macro
service_description test9
check_command test_macro!HBase_GcTimeMillis{instance=~\"'$HOSTNAME$''\\'..*\"}/HBase_GcCount{instance=~\"'$HOSTNAME$''\\'..*\"}!test9
}
yields the following results
Code: Select all
Sat Apr 1 02:38:22 PDT 2017:12093:test1 query: [HBase_GcTimeMillis{instance=~\"$\..*\"}/HBase_GcCount]
Sat Apr 1 02:38:28 PDT 2017:14563:test2 query: [HBase_GcTimeMillis{$_SERVICEI$}/HBase_GcCount{$_SERVICEI$}]
Sat Apr 1 02:38:34 PDT 2017:15374:test3 query: [instance=~\"$\..*\"]
Sat Apr 1 02:38:42 PDT 2017:15756:test4 query: [$HOSTNAME$]
Sat Apr 1 02:38:47 PDT 2017:16286:test5 query: [qwertyuiop]
Sat Apr 1 02:38:54 PDT 2017:17065:test6 query: ["blahblahblah dev1 blahblah"]
Sat Apr 1 02:38:46 PDT 2017:16019:test7 query: [dev1]
Sat Apr 1 02:38:23 PDT 2017:12181:test8 query: [HBase_GcTimeMillis{instance=~"dev1"}/HBase_GcCount]
test1 - HOSTNAME$ literal removed, nothing inserted. Note that all the escaping of quotes and period etc. is required for the promql query to be handled successfully by the prometheus server
test2 - not sure if Nagios allows macro within macro, it doesn't work and $_SERVICEI$ remains as literal
test3 - similar to test1
test4 - attempt to put only $HOSTNAME$ into a custom object var, remains literal all the way to the script.
test5 - sanity check that custom object var macro is actually working - OK
test6 - similar to your test result, works fine when the $HOSTNAME$ is in the check_command - OK
test7 - same as test 6 - OK
test8 - similar to test 7 and 6 - OK
test9 - does not run, I think the escaped quotes etc. cause it to have a problem.