When I try to use a $USERn$ macro as a value in a _CUSTOM_VAR, it doesn't work. In the example below, the method that doesn't work tries to send a $ as the community string. Are the $'s in the custom variable value being scrubbed or cleaned or something?
# This works--------------------------------------------
host.cfg:
define host{
use generic-switch
host_name switch01.domain.com
alias A switch
address 1.2.3.4
hostgroups switches
parents router01.domain.com
_SNMP_COMMUNITY public
}
service.cfg:
define service{
use generic-service
hostgroup_name switches
service_description Uptime
check_command check_snmp!-C $_HOSTSNMP_COMMUNITY$ -o sysUpTime.0
}
command.cfg:
define command{
command_name check_snmp
command_line $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$
}
# This does not-----------------------------------------
resource.cfg:
$USER6$=public
host.cfg:
define host{
use generic-switch
host_name switch01.domain.com
alias A switch
address 1.2.3.4
hostgroups switches
parents router01.domain.com
_SNMP_COMMUNITY $USER6$
}
service.cfg:
define service{
use generic-service
hostgroup_name switches
service_description Uptime
check_command check_snmp!-C $_HOSTSNMP_COMMUNITY$ -o sysUpTime.0
}
command.cfg:
define command{
command_name check_snmp
command_line $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$
}
Are user macros allowed in custom object variables?
Re: Are user macros allowed in custom object variables?
I can't say I've ever attempted to do this, nor do I directly know the answer to your question (though it may be because $USERn$ is not available as an environment variable). However as an alternative you may be able to do either of the following (the second is a guess... I have no idea if it will work):
1. Add the _SNMP_COMMUNITY to a host template and assign that to all the devices that need it.
2. Create a dummy host template and then use On-Demand macros to get the value. I.e:
define host {
name host_snmp_dummy
_SNMP_COMMUNITY public
register 0
}
and then in the command use check_command check_snmp!-C $_HOSTSNMP_COMMUNITY:host_snmp_dummy$ -o sysUpTime.0
Let me know if that helps, I'm curious now
1. Add the _SNMP_COMMUNITY to a host template and assign that to all the devices that need it.
2. Create a dummy host template and then use On-Demand macros to get the value. I.e:
define host {
name host_snmp_dummy
_SNMP_COMMUNITY public
register 0
}
and then in the command use check_command check_snmp!-C $_HOSTSNMP_COMMUNITY:host_snmp_dummy$ -o sysUpTime.0
Let me know if that helps, I'm curious now