Any code formatters for Icinga2 language?

Hi everyone,

We’re working with a fairly large Icinga2 configuration, totaling over 120k lines of code spread across roughly 600 config files that have grown organically over time.

Lately, we’ve been wanting to clean up (i.e., refactor) the configuration, particularly focusing on standardizing indentation. Ideally, we’d like to do this automatically.

Has anyone here encountered a similar challenge and found a solution?

The ideal scenario would be a tool (similar to Prettier for JavaScript or GNU Indent for C) that could strip all existing formatting and reformat everything according to a standardized style. It would also be great if it could be used as a pre-commit hook to maintain consistency in future configurations.

Thanks in advance for any advice or recommendations!

First, congratulations on running such a huge Icinga setup.

Unfortunately, I don’t know of the existence of an Icinga 2 DSL formatter, beautifier or linter. This may definitely be a useful project, as something similar was requested the other day in https://community.icinga.com/t/how-to-export-rendered-config-by-type-without-using-director/14096. As a starting point, one can check out the lexer and parser files used by Icinga 2, https://github.com/Icinga/icinga2/tree/master/lib/config.

2 Likes

If, by any chance, you would like to start something to handle Icinga2 code, I would be quite interested.
A proper parser/compiler outside of icinga2 would be really helpful, but I did not yet find time and motivation for such a task yet.

There are syntax highlight configs for vim and nano (Addons - Icinga 2) which might also be a starting point!? :thinking: Though, I don’t use them, so I don’t know if they’re up to date.

Thanks for your interest!

At the moment, we’re exploring a few different approaches, but it’s still too early to provide any concrete updates. If we manage to come up with a viable solution, we’ll definitely share it with the community.

We agree that a full-fledged parser/compiler outside of Icinga2 would be extremely helpful, but interpreting and processing the configuration is a much larger task than simply handling indentation. For now, we’re focused on finding a practical solution to our specific issue, even if it ends up being a “98% solution” rather than perfect.

1 Like