Today I will show you a couple of out of field useful functions from the Icinga DSL I use when creating some testing configurations for Icinga 2. Using the Icinga DSL is easy, quick and a good way of testing and validating your Icinga setup.
Icinga 2 console
But first, do you know how to use the Icinga 2 console? It’s super easy. Just type in “icinga2 console” in the terminal of your choice; it’s a CLI command which offers lots and lots of functions. Did you get it to work? If so, you should see an output that looks like this.
# icinga2 console Icinga 2 (version: 2.12.1-1) Type $help to view available commands. <1> =>
The log function
One of the useful functions of the Icinga DSL I use is the log function. This is how it’s constructed:
function log(severity, facility, value)
You can set the severity to
LogDebug, LogNotice, LogInformation, LogWarning or
LogCritical, while the
facility can be set by you to indicate where the message originates from.
value is the log message itself you’re trying to convey. So let’s test it!
<1> => log(LogDebug, "blogposttest", "Hello, I am a logging message!") null <2> => log(LogCritical, "blogposttest", "Hello, I am a logging message!") critical/blogposttest: Hello, I am a logging message! null
So as you can see, it obviously depends on the set log level for your log message to show itself in the appropiate context.
LogCritical is always a good idea for making sure your implemented message shows itself to you while testing. So how do I use it for testing? Well, when used in configuration, your log message will show up when the configuration is being compiled, at the start of Icinga, for example. When using countless different files in configuration, for example configurations I need to test for customers or colleagues, it can be useful to have the log function implemented at the start of a configuration file so you know which ones are being used and which ones might be missing. I encourage you to go ahead and try playing around with it a bit!
The sleep function
Did you know the Icinga DSL offers a sleep function? It’s usage is really, really simple:
<1> => sleep(1) null
You just give the function the number of seconds you want it to do nothing, and Icinga will do nothing for the specified amount of seconds. So why is that useful? Well, in large setups with many services and hosts, like I’ve described them before, you will get hundreds, even thousands of services which will all spew out a log message like I’ve explained before. So what I like to do is combinate the log function with a sleep function directly afterwards, so the Icinga 2 output is easily readable with your eyes while compiling the configuration, and you can continue or stop if any big errors are noticeable for you; you don’t need to run through the complete configuration. Don’t forget to remove the sleep-function before using it in a productive way though! 🙂
If you want to find out more about DSL functions, click here. And have fun trying out the various ways of testing your configuration!