Skip to content
Notifications
Clear all

My script to compare rule sets before and after a change.

9 Posts
9 Users
0 Reactions
104 Views
(@crm_hopper_2025)
Honorable Member
Joined: 6 months ago
Posts: 339
Topic starter   [#28306]

Hey everyone! 👋 Long time lurker, first time poster in this specific subforum. As someone whose entire professional life seems to be migrating between CRMs and marketing automation platforms (Salesforce to HubSpot to Zoho and back again, anyone?), I’ve developed a... let's call it a *healthy paranoia* about configuration changes.

That paranoia followed me right into network security when I started managing our SonicWall firewalls. A few months back, a simple rule re-order to optimize traffic flow had... unintended consequences. Let's just say a critical SaaS tool went offline for 20 minutes, and I aged roughly five years. The problem? I thought I knew exactly what I’d changed, but the sheer volume of rules made it impossible to be *sure*.

So, being the automation-obsessed RevOps person I am, I built a little script to compare rule sets before and after any change. It’s saved my skin more than once during firmware updates, policy reviews, and clean-up projects. I know there are paid tools, but this is quick, dirty, and gives me a diff I can read with my morning coffee.

The gist is:
* It uses the SonicWall CLI via SSH (you'll need credentials and access).
* Takes a "before" snapshot of your rule set (NAT policies, access rules, etc.) and saves it as a text file with a timestamp.
* After your changes, you run it again for the "after" snapshot.
* It then does a line-by-line comparison, highlighting additions, deletions, and modifications.

It’s not fancy GUI, but it gives me a clear, actionable report. For example, it'll flag if a service object in a key rule changed from TCP/443 to TCP/8443, or if a new rule was accidentally inserted in the wrong place in the hierarchy.

Here's the core logic I use (adapted for clarity):

```bash
#!/bin/bash
# This is a simplified version. Always test in a lab first!
HOST="firewall.local"
USER="admin"
BACKUP_DIR="./sonicwall_snapshots"

# Connect, get rules, clean up CLI formatting
ssh $USER@$HOST "show access-rule" | grep -v "^$|^$|^---" > "$BACKUP_DIR/access_rules_$(date +%Y%m%d_%H%M%S).txt"
# Repeat for NAT, address objects, etc.
```

Then, for comparison, I use a simple diff tool:
```bash
diff -u "$BACKUP_DIR/access_rules_before.txt" "$BACKUP_DIR/access_rules_after.txt" > rule_change_report.txt
```

**Why I bother with this:**
* **Audit Trails:** It creates a perfect, timestamped record for change management tickets.
* **Troubleshooting:** When something breaks, my first question is "what changed?" This answers it in seconds.
* **Migration Prep:** Seriously, this is like a data migration between CRMs. You need to know the source, the target, and every delta in between.

**A few pitfalls I learned the hard way:**
* The CLI output can vary slightly between firmware versions. Run your "before" and "after" on the *same* firmware.
* This doesn't capture every single object (like all DPI-SSL settings), so you need to expand the commands you snapshot based on what you're changing.
* Always, always store these snapshots in a secure place—they contain your rule structure!

I'm curious—how do you all track and validate configuration drifts? Does anyone else have scripts or homebrew tools they swear by for SonicWall or similar gear? Would love to swap war stories and maybe improve this little script together.

Hopefully last migration,



   
Quote
(@emmal)
Reputable Member
Joined: 4 months ago
Posts: 320
 

I feel that pain, especially coming from a SaaS onboarding background. You think a change is isolated, but it's never just one rule, it's the whole sequence. That 'healthy paranoia' is just being a responsible admin.

So you're pulling the config via SSH before and after. Do you store those snapshots anywhere, maybe tagged with a change ticket number? I've been trying to cobble together a similar audit trail for our Zendesk routing rule changes, and figuring out how to version that history is the tricky part.

What happens when the diff is huge, like after a firmware update? Is your script good at highlighting just the moved vs. the truly altered lines?



   
ReplyQuote
(@helenb)
Estimable Member
Joined: 4 months ago
Posts: 128
 

Storing diffs against a ticket number is a great idea. Do you find your team actually references that history later, or does it just become audit fodder?

> when the diff is huge, like after a firmware update
That's a good point. Are you comparing the raw config output or parsing it into objects first? I'd think a raw line diff after a firmware update would be mostly noise from reformatted text.



   
ReplyQuote
(@danielm)
Honorable Member
Joined: 4 months ago
Posts: 453
 

That "healthy paranoia" is the best and cheapest tool in your kit, frankly. The story about a re-order taking out a SaaS tool is a classic case study in why vendor dashboards that hide the actual sequence from you are a liability.

You mention a script, but I'm immediately skeptical of the "quick and dirty" part when dealing with CLI output. Are you just diffing raw text? Because that falls apart the moment the vendor reformats a line or adds a whitespace in their latest firmware "enhancement." You'll get a thousand-line diff for a single rule change. Parsing it into comparable objects is the non-trivial part everyone glosses over, and the point where the paid tools start to justify their annoying invoices.

So what's your actual method for isolating a moved rule from a changed one? String matching on the source and destination?


— skeptical but fair


   
ReplyQuote
(@infra_auditor_nina)
Honorable Member
Joined: 8 months ago
Posts: 467
 

> Do you find your team actually references that history later

In my audits, almost never. It's pure compliance theater, stored to satisfy a checkbox and then immediately forgotten. The history only gets pulled when something is already on fire and they need a scapegoat.

> a raw line diff after a firmware update would be mostly noise

Exactly. That's why the object-parsing question is the only one that matters. If you're just diffing text, you're creating a false sense of security. The tool might as well just output "something changed, good luck." Has anyone actually validated their diff script against a firmware update that reformatted the entire config tree? I'm betting not.


- Nina


   
ReplyQuote
(@consultant_carl_42)
Reputable Member
Joined: 6 months ago
Posts: 381
 

You had me nodding along right up until "quick, dirty, and gives me a diff I can read." That's the siren song right before you run aground. You mention migrations between Salesforce and HubSpot, so you know the pain of field mapping after a vendor update. A raw CLI diff is like comparing two Salesforce page layouts with a line-by-line text tool after a Winter '24 release. The layout might be functionally identical, but the diff output is terrifying noise because the underlying XML got rearranged. Your script will tell you everything changed when it hasn't, and worse, it might tell you nothing changed when something crucial has been altered at the attribute level. The coffee-time confidence it gives you is the most dangerous part.


Test the migration.


   
ReplyQuote
(@danm)
Honorable Member
Joined: 4 months ago
Posts: 452
 

> a diff I can read with my morning coffee.

Oh man, I love that feeling. That moment when you can quickly eyeball what changed before you hit apply? Priceless.

Your point about migrations is spot on. I built a similar thing for Confluence space exports once. It just pulled the JSON and diffed objects, ignoring internal IDs. The first time a vendor update re-sorted all the page nodes alphabetically, my naive text diff blew up. Learned that lesson the hard way.

Are you pulling just the rule section, or the whole config? I found trimming the noise first helps a ton.



   
ReplyQuote
(@annad)
Reputable Member
Joined: 4 months ago
Posts: 343
 

That feeling when a simple re-order brings down a critical tool is all too real, and it's exactly why your healthy paranoia is the right instinct. I've seen similar outages from just moving a "deny" rule in a content filter list.

You mentioned pulling via SSH and reading the diff with your coffee. I'm really glad you found something that works for you, honestly. It shows you're taking control.

But I'm immediately curious about one thing: when you pull the config, are you grabbing the entire output, or are you filtering for just the security policy section? The full config has so much extra noise - system settings, interface stats, VPN parameters. A raw text diff on the whole thing, even for a tiny rule change, can be a nightmare to parse. Filtering down to just the relevant rule base first makes the "coffee time" review so much more feasible.



   
ReplyQuote
(@henryg)
Honorable Member
Joined: 4 months ago
Posts: 420
 

> quick, dirty, and gives me a diff I can read with my morning coffee.

That's the confidence I'm talking about. The comfort is the problem. You're comparing raw CLI text. What happens when the next firmware changes the indentation or adds a comment header? Your coffee-time diff becomes a thousand-line monstrosity that says everything changed, and you'll never trust it again.

Parsing into objects is the only real way, and that's where the quick and dirty script turns into a month-long project accounting for every vendor-specific quirk. That's why they sell the expensive tools.


Your vendor is not your friend.


   
ReplyQuote