[Solved] New Custom CheckCommand

(Madtempest) #1

Hi All,

I’ve had a look at both https://icinga.com/docs/icinga2/latest/doc/05-service-monitoring/#checkcommand-definition and [SOLVED] Add CheckCommand check_snmp_synology and I have a similar issue.

Here’s my check command:
object CheckCommand “opnsense” {
import “plugin-check-command”
command = [ PluginDir + “/check_opnsense.py” ]
arguments = {
“–hostname” = “$opnsense_hostname$”
“–api-key” = “$opnsense_api_key$”
“–api-secret” = “$opnsense_api_secret$”
“–insecure” = “$opnsense_insecure$”
“–mode” = “$opnsense_mode$”


And here’s my service
apply Service “opnsense updates” {
import “generic-service”
check_command = “opnsense”
vars.opnsense.hostname = “hostname”
vars.opnsense.api_key = “api_key”
vars.opnsense.api_secret = “api_secret”
vars.opnsense.insecure = “true”
vars.opnsense.mode = “updates”
assign where host.vars.os == “Opnsense”

The error that I get is that the Hostname is not being passed. I did managed to get the vars.opnsense.insecure pass through when I set vars.opnsense_insecure = true in the check command (found that in the debug logs) but the rest of the arguments don’t seem to want to pass along.

Thanks in advance.

(Alex) #2


you’re using in your CheckCommand template $opnsense_hostname$ and in your service template vars.opnsense.hostname. Try to change the point to an underline.

apply Service "opnsense updates" {
   import "generic-service"
   check_command = "opnsense"
   vars.opnsense_hostname = "hostname"
   vars.opnsense_api_key = "api_key"
   vars.opnsense_api_secret = "api_secret"
   vars.opnsense_insecure = "true"
   vars.opnsense_mode = "updates"
   assign where host.vars.os == "Opnsense"


(Madtempest) #3

Thanks for that.
It seems that if I use

“–hostname” = “$opnsense.hostname$” and vars.opnsense_hostname = “hostname” it fails to pass the hostname but using your method does.

What is the differentiator between . and _ for custom commands?

(Chris) #4

the differenc is the following:

the indexer in this case does create a different object out of this:

With the dot in between you define that you use a dictionary object instead of just a string:


(Madtempest) #5

Thanks Chris!

I’ll keep that in mind for the future.

Thanks for the assistance all.