Skip to content
Guides & References

Capture state before and after a change

An SIE recipe that records a device's operational state either side of a change window, so the rConfig diff shows what the change actually did.

Script Integration EngineUpdated
On this page

Capture state before and after a change

A config backup shows what was configured. It doesn’t show whether the neighbours came back, the routes converged or the interfaces stayed up. This recipe collects a set of operational commands into one delimited snapshot. Run it before a change window and again after, and the rConfig diff between the two runs is the record of what the change actually did.


When to use it

  • You want evidence for a change record that the network was in the same state afterwards, or a list of exactly what differed.
  • You want a quick rollback check: compare the post-change snapshot with the pre-change one and look only at what moved.

How it fits on a device

A device with a script template runs every command in its command group as a script. So the snapshot gets its own device record, separate from the device’s normal backup:

Device record Template Collects
core-sw-01 The device’s normal connection template Running config, on its normal schedule
core-sw-01-snapshot The script template below The snapshot, on demand

Both records point at the same IP address. The normal backups carry on untouched, and the snapshot’s history only contains snapshots, so its diffs are easy to read.


What you need

  • An SSH key the device accepts for a read-only user, stored in the scripts keys folder and owned by the web user (see get your server ready for scripts). The script uses key authentication so it never needs a password on its command line.

The template

sie-snapshot-template.yml
main:
name: "SIE - Pre and post change snapshot"
desc: "Captures a delimited operational state snapshot over SSH"
connect:
timeout: 120
idletimeout: 60
idleTimeout: 60
protocol: script
# exit_codes is deliberately left out: any non-zero exit fails the run.
failure_criteria:
error_patterns:
- "ERROR:"
success_patterns:
- "SIE-OK: snapshot"

The command

/bin/bash {script_path}pre-post-change-snapshot.sh {device_ip} {device_username}

The script

Save it as pre-post-change-snapshot.sh in the scripts folder.

pre-post-change-snapshot.sh
#!/usr/bin/env bash
#
# Capture a delimited operational state snapshot from a device over SSH, for the
# rConfig Script Integration Engine.
#
# Usage: pre-post-change-snapshot.sh <ip> <username>
#
# The snapshot goes to stdout and becomes the stored backup. Progress, errors and
# the success marker go to stderr. Exit code 0 on success, 1 on any failure.
set -o pipefail
KEYS="/var/www/html/rconfig8/current/storage/app/rconfig/scripts/keys"
KEY_FILE="$KEYS/snapshot_ed25519"
# Adapt for your platform. The delimiters matter more than the exact commands.
COMMANDS=(
"show ip interface brief"
"show ip route summary"
"show ip ospf neighbor"
"show ip bgp summary"
"show cdp neighbors"
"show interfaces status"
)
# Timers and ages change on every run. Mask them rather than dropping the line,
# so a neighbour line still shows when its state changes.
MASK='s/[0-9]{1,2}:[0-9]{2}:[0-9]{2}/<time>/g; s/\b[0-9]+[ywdh][0-9]+[wdhm]\b/<age>/g'
fail() {
echo "ERROR: $1" >&2
exit 1
}
HOST="${1:-}"
USER_NAME="${2:-}"
[ -n "$HOST" ] || fail "usage: pre-post-change-snapshot.sh <ip> <username>"
[ -n "$USER_NAME" ] || fail "usage: pre-post-change-snapshot.sh <ip> <username>"
[ -r "$KEY_FILE" ] || fail "cannot read the SSH key $KEY_FILE"
echo "collecting snapshot from $HOST as $USER_NAME" >&2
for command in "${COMMANDS[@]}"; do
# A fixed delimiter per section keeps the diff readable: a line that moves
# between sections shows as a move, not as two unrelated changes.
echo "===== ${command} ====="
if ! output=$(ssh -i "$KEY_FILE" \
-o BatchMode=yes \
-o StrictHostKeyChecking=accept-new \
-o UserKnownHostsFile="$KEYS/known_hosts" \
-o ConnectTimeout=10 \
"${USER_NAME}@${HOST}" "$command" 2>/dev/null); then
fail "'${command}' failed on ${HOST}"
fi
printf '%s\n' "$output" | tr -d '\r' | sed -E "$MASK"
echo
done
echo "===== end of snapshot ====="
echo "SIE-OK: snapshot ${#COMMANDS[@]} sections from ${HOST}" >&2
exit 0

Running it around a change

  1. Before the change, open the snapshot device and click Download Now. That stores the pre-change snapshot.
  2. Make the change.
  3. Once the network has settled, click Download Now again. That stores the post-change snapshot.
  4. Open the snapshot device’s configuration diff for the two versions.

An empty diff means the operational state you measured is the same as before. Anything else is in the diff, section by section:

A diff between two snapshots
===== show ip ospf neighbor =====
Neighbor ID Pri State Dead Time Address Interface
192.0.2.1 1 FULL/DR <time> 192.0.2.1 GigabitEthernet0/1
192.0.2.2 1 FULL/BDR <time> 192.0.2.2 GigabitEthernet0/2
192.0.2.2 1 INIT/DROTHER <time> 192.0.2.2 GigabitEthernet0/2

Adapting it

  • Other platforms. Replace COMMANDS with your platform’s equivalents. Keep each command read-only.
  • Less noise. MASK replaces clock times and ages such as 1d02h with a fixed placeholder, so a neighbour’s line only changes when its state does. Counters (packets, errors, drops) change on every run too: leave them out of the command list, or add diff exclusions for the snapshot’s command.
  • Several devices in one change. Give each one a snapshot device record and put them in a device group, so you can download them together.

Type to search.