Dump diffable configuration snapshots


My goal is to create a dump of as much of Icinga configuration as possible in order to compare after configuration edits.

I am struggling to obtain a simple and sortable object list.

I have tried two things:

  1. icinga2 object list: order of objects is random, so two dumps are difficult to compare. Additionally, this output is in no particular structured format making post-processing (like sorting) difficult.

  2. REST API: Only possible to dump each object type explicitly, in contrast to “icinga2 object list”. But at least it’s JSON and post-processing is easy.

So, how do I dump the configuration before and after modifications in a way that it can be easily compared?


The following provides configuration in a way that you can just run this multiple times and diff the output for meaningful information, like before and after a reload of Icinga.
Essentially I’m using jq to parse hosts, services and notification definitions (json) using REST API and removing any information that is not interesting for configuration comparison purposes.

curl=(curl -k -s -u root:password)
TS=$(date +%Y%m%d-%H%M%S)

for i in hosts services notifications; do
  ${curl[@]} 'https://localhost:5665/v1/objects/'$i | jq '.results | sort_by(.attrs.__name) | .[].attrs | del('"$REMOVE_ATTR"')' | grep -v -e last_state_ -e first_line -e last_line > out.$TS.$i