DSL: 99 bottles of beer

That was a question on Twitter, and actually, this is really easy to implement inside the Icinga DSL :smiley:



const NumberOfBeers = 99

globals.getBeerContent = function() {
  var out = ""

  for (c in range(NumberOfBeers, 0, -1)) {
    out += c + " bottles of beer on the wall, " + c + " bottles of beer.\\n"

    var reduced = c - 1

    if (c == 1) {
      reduced = "no more"

    out += "Take one down and pass it around, " + reduced + " bottles of beer on the wall.\\n\\n"

  out += "No more bottles of beer on the wall, no more bottles of beer.\\n"
  out += "Go to the store and buy some more, " + NumberOfBeers + " bottles of beer on the wall.\\n"

  return out

object Host NumberOfBeers + "beers" {
  check_command = "dummy"
  check_interval = 1s
  vars.dummy_text = {{
    return getBeerContent()





Thanks for answering my question so fast :slight_smile:

I tried to deploy it, since I think it’s a nice demo of DSLs capabilities.

However I didn’t get it to work to show up in icingaweb2.

I already foundthe documentation of fileshipper and the explaination that Director simply can’t serialize DSL. So I guess, I missed something. Any hints which documentation I should look into?

Regards, joke_s

Oh, that’s not possible with the Director in this way with custom variables unfortunately. One trick you may do - put the command argument value to “Icinga DSL” and put the function code in there.

1 Like

Thanks for your reply. How did you manage to display it inside the hosts view in Icinga Web in your screenshots?

Sorry for the delayed answer, I was out of Office last week.

Via dummy CheckCommand where dummy_text is assign a runtime lambda function within {{ ... }}. This runtime function just calls another globally defined function above. You could of course move the code from that global function directly into the lambda function as well, my version allows to re-use it in other hosts and services for the fun and pride :smiley:

1 Like