Dear Icinga community,
I am trying to get myself familiar with the Icinga DSL, and write some checks where multiple already existing objects and checks are being used to cluster them together into a single check and also use some inner logic. Later these custom checks will be fed into business processes, but first I want to get some custom checks set up and experiment with what I can do with the DSL.
For this, I would need a way to be able to interact with the DSL while developing my checks, and I thought that using the Icinga console one can do this.
I have searched around, but I could not find a more elegant IDE or tool for this, and I am wondering what I am doing wrong.
Namely, when I try to do simple things like get the exit status of some checks by copy-pasting into the console the following three lines, it all works fine, and the return values are all 0.000000 as expected:
get_service("fqdnhostname", "ping4").last_check_result.exit_status
get_service("fqdnhostname", "ntp_time").last_check_result.exit_status
get_service("fqdnhostname", "ssh").last_check_result.exit_status
However, when I try to copy-paste into the console some code which contains a bit of logic, like for example:
var listofchecks = [ "ping4", "ntp_time", "ssh" ]
for (var mycheck in listofchecks ) {
if (get_service("fqdnhostname", mycheck).last_check_result.exit_status > 0) {
return 2 //something is broken
} else {
return 0 //all checks are OK
}
}
this will fail with the first error being:
return 2 //something is broken
^^^^^^^^
Invalid flow control statement.
The above will fail even if I remove the “// comment” from the end of the lines.
In theory the above code should work, but just for testing purpose I have tried to copy-paste into the Icinga console the code from https://icinga.com/docs/icinga-2/latest/doc/08-advanced-topics/#access-object-attributes-at-runtime-cluster-check and this also fails to run in the Icinga console.
Could you please help me out what is the right way and environment/IDE/tool to interact with existing objects and develop custom DSL checks? Most likely I had overlooked something in the documentation how to do this in pactice.
While on this topic, is there a simple way to just print out variables in the DSL without explicitly having to “return” them?
I would like to thank you in advance for your help.
Best regards