Dear Icinga community,
I am trying to perform a check, where a single check should combine multiple checks into one, and I want to do this without a business process. I thought that using a “function” for this via DSL should be simple, but so far I did not succeed, and I am a bit lost and confused after going through several blog posts presenting very complicated solutions.
I found this example
https://icinga.com/blog/2021/04/29/calculating-a-state-over-mutliple-services/
which is over-complicated for me.
Could please someone share a working simple example. Practically what I would need is to know:
- how to save a custom function
- how to make a saved custom function usable as a check (or how to call that function)
- how to associate that check with a host, or how to call that function to execute a check
After going through the example I posted above, I don’t see why I would need to set up dummy hosts and helper functions just to run a simple function which runs on the icinga master node, so it would be nice to have a more simple working example what I can use as a blueprint, so I can learn the basics.
Namely, I have created a custom function running multiple checks at once which works if I copy-paste it into the Icinga2 console. After pasting in the text file into the console which contains the new function, I can call it from the console with:
MyFunction()
and it returns the expected result just fine:
"OK: minimal stack check passed"
When I create a conf file under /etc/icinga2/zones.d/master/ where I save this function which I pasted into the console, and restart icinga2 service, thing are still fine.
However, if I create a separate conf file, where now I try to call this function like:
apply Service "DSL_Test" {
display_name = "Minimal StackCheck from DSL"
vars.dummy_state = 3
vars.dummy_text = MyFunction()
assign where host.name == "icinga"
check_command = "dummy"
check_interval = 5m
retry_interval = 3m
}
and I try to restart icinga2.service, this fails with:
critical/config: Error: Invalid field access (for value of type 'Service'): 'MyFunction'
Probably I am overlooking something basic of how to use a custom function, and how to perform a check with a custom function. By searching online, I did not find a good explanation and basic examples, so I would appreciate it if someone could help me out here with a simple working example.
Best regards