Dump diffable configuration snapshots

Hello,

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?

Cheers.

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)
REMOVE_ATTR=".last_check_result,.last_check,.last_state,.last_hard_state_change,.next_check,.flapping_current,.last_hard_state,.severity,.state,.state_type,.check_attempt,.last_notification,.next_notification,.last_problem_notification,.notified_problem_users,.no_more_notifications,.notification_number,.source_location.first_column,.source_location.last_column,.flapping,.flapping_last_change,.downtime_depth"
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
done