Icinga 2 DSL for Advent of Code

by | Dec 2, 2026

For over a decade, people in IT spent parts of their advent season solving programming puzzles instead of socializing or doing actual Christmas stuff. I am obviously talking about the Advent of Code, where, in a nutshell, small programming tasks wrapped in a cute little story need to be solved. While most people are using reasonable programming languages to do so, there are lots of attempts to solve this in unconventional ways – like in the Icinga 2 DSL, which is Icinga 2’s own configuration language you might already be familiar with. However, unlike some configuration languages, it is Turing-complete and can be used as a programming language on its own.

Puzzle

As the first day of Advent of Code is still easy, I wanted to show how the Icinga 2 DSL can be used as an actual programming language. The puzzle input was an unordered list of numbers, where, when ignoring the story around it, both the three most and the three least common numbers should be identified and multiplied.

Implementation in Icinga 2 DSL

Since there are no IO or file functions in the Icinga 2 library, we need to transform the input to Icinga 2 DSL first. The input comes as a text file of numbers, each on its own line. With the help of a little awk(1), this can be transpiled into an Icinga 2 array, which can then be included.

$ awk 'BEGIN { print "input = [" } { print $0 "," } END { print "]" }' input_demo > input.conf

$ head -n 3 input_demo
57
57
55

$ head -n 3 input.conf
input = [
57,
57,

Now, there are multiple approaches one could take to solve this. The Icinga 2 DSL supports both imperative as well as functional programming paradigms. I went for the latter.

To get started, I sorted the input array. Then, using reduce, I went over the sorted list pairwise and collapsed it to a list of pairs, containing both the number as well as its occurrence. So, [23,42,23,1,42,23] would become [[42,2],[23,3],[1,1]].

include "input.conf"

ids = ([[]] + input.sort()).reduce(
  (acc, elem) => (
    if (acc == []) {
      [[elem, 1]]
    } else if (acc[0][0] == elem) {
      var top = acc[0]
      top[1] += 1
      acc
    } else {
      [[elem, 1]] + acc
    }
))

Since Icinga 2’s reduce function does not allow passing an initial value, as most reduce or fold implementations do, I prefixed the sorted input with an array containing an empty array. This value could then be used as a special case for the first entry. For every other element, the reduce function only needs to decide if the topmost pair contains this element or not. The incrementing logic on top is a reference, so there is no need to write top back to acc.

The next step would be to sort this list of pairs based on their occurrence. Therefore, another sort call can be used, but this time with a custom compare function. As the count is no longer relevant, it can be dropped via a map call.

.sort((a, b) => (a[1] >= b[1])).map((pair) => (pair[0]))

Finally, ids is an array of unique numbers ordered by their occurrence in the input. This allows extracting both the most common and least common numbers.

log("Part One: " + (ids[0] * ids[1] * ids[2]).to_string())
log("Part Two: " + (ids[len(ids)-1] * ids[len(ids)-2] * ids[len(ids)-3]).to_string())

As it is tradition for Advent of Code puzzles, the second part of the riddle is only shown after the first part has been solved. Fortunately, today’s puzzle was kind enough to grant us a solution without having to refactor part one completely.

include "input.conf"

ids = ([[]] + input.sort()).reduce(
  (acc, elem) => (
    if (acc == []) {
      [[elem, 1]]
    } else if (acc[0][0] == elem) {
      var top = acc[0]
      top[1] += 1
      acc
    } else {
      [[elem, 1]] + acc
    }
)).sort(
  (a, b) => (a[1] >= b[1])
).map(
  (pair) => (pair[0]))

log("Part One: " + (ids[0] * ids[1] * ids[2]).to_string())
log("Part Two: " + (ids[len(ids)-1] * ids[len(ids)-2] * ids[len(ids)-3]).to_string())

Finally, run the code with the demo input.

$ icinga2 console -r ./day01.conf
information/config: Part One: 186276
information/config: Part Two: 193050
null

Reflections

Does all this information help with monitoring? Honestly, I do not think so. So, then why write about it? Because Icinga 2 comes with a real programming language which can help to express even niche demands by code. Your Icinga 2 configuration is, by definition, code in this DSL; and it is powerful enough to get a quick and readable solution for one of the most popular programming competitions.

You May Also Like…

 

Subscribe to our Newsletter

A monthly digest of the latest Icinga news, releases, articles and community topics.