That was a question on Twitter, and actually, this is really easy to implement inside the Icinga DSL
http://www.99-bottles-of-beer.net/lyrics.html
Code
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()
}}
}
Result
References
- range(): https://icinga.com/docs/icinga2/latest/doc/18-library-reference/#range
- for loop: https://icinga.com/docs/icinga2/latest/doc/17-language-reference/#for-loops
- conditions: https://icinga.com/docs/icinga2/latest/doc/17-language-reference/#conditional-statements
- additive assignment: https://icinga.com/docs/icinga2/latest/doc/17-language-reference/#assignments
- global functions: https://icinga.com/docs/icinga2/latest/doc/08-advanced-topics/#register-and-use-global-functions