Open a ticket when a device config changes
Every config change should be tied to a change record. This recipe is a small web service that receives rConfig’s config.changed webhook, checks it really came from rConfig, and opens a ticket in ServiceNow or Jira with the device, the command, the changed lines and a link back to rConfig. Engineers then confirm the change was planned, or chase it if it wasn’t.
How it works
rConfig --POST config.changed--> receiver --checks signature, queues--> worker --creates--> ticket- rConfig posts a signed Generic JSON event for each config change.
- The receiver checks the
X-rConfig-Signatureheader against the raw body, ignores events it has already seen, puts the event on a queue and returns200at once. - A worker thread takes events off the queue and creates the ticket.
Answering first and working afterwards matters: a receiver that waits for ServiceNow before answering can exceed the webhook timeout, and rConfig counts that as a failure. See designing a receiver.
What you need
- A Generic JSON webhook in rConfig, subscribed to
config.changedonly, pointing at the receiver’s HTTPS address. Copy its signing secret when it’s shown. See webhook notifications. - A ServiceNow or Jira account that can create tickets, ideally a dedicated integration user.
- Python 3 with
flaskandrequests(pip install flask requests), behind an HTTPS reverse proxy or load balancer.
The receiver runs on your own infrastructure, not on the rConfig server, so it reads its secrets from environment variables set by your service manager or container platform.
| Variable | What it holds |
|---|---|
RCONFIG_WEBHOOK_SECRET |
The webhook’s signing secret (whsec_...) |
TICKET_SYSTEM |
servicenow or jira |
SN_INSTANCE, SN_USER, SN_PASSWORD |
ServiceNow instance name and credentials |
JIRA_URL, JIRA_USER, JIRA_TOKEN, JIRA_PROJECT |
Jira site, account, API token and project key |
The receiver
Save it as rconfig_change_tickets.py.
#!/usr/bin/env python3"""Receive rConfig config.changed webhooks and open a ticket for each change.
Run behind an HTTPS reverse proxy, for example: gunicorn --workers 1 --threads 4 --bind 127.0.0.1:8080 rconfig_change_tickets:app
One worker process, so the duplicate check and the queue are shared."""
import hashlibimport hmacimport jsonimport osimport queueimport threadingimport timefrom collections import OrderedDict
import requestsfrom flask import Flask, abort, request
SECRET = os.environ["RCONFIG_WEBHOOK_SECRET"]SYSTEM = os.environ.get("TICKET_SYSTEM", "servicenow")TOLERANCE = 300 # seconds; matches rConfig's own checkSEEN_LIMIT = 5000 # remember this many event IDs for duplicate checks
app = Flask(__name__)work = queue.Queue()seen = OrderedDict()seen_lock = threading.Lock()
def signature_ok(header, raw_body): parts = dict(p.strip().split("=", 1) for p in header.split(",") if "=" in p) timestamp, digest = parts.get("t", ""), parts.get("v1", "") if not timestamp.isdigit() or not digest or abs(time.time() - int(timestamp)) > TOLERANCE: return False expected = hmac.new(SECRET.encode(), f"{timestamp}.".encode() + raw_body, hashlib.sha256).hexdigest() return hmac.compare_digest(expected, digest)
def first_time(event_id): with seen_lock: if event_id in seen: return False seen[event_id] = True while len(seen) > SEEN_LIMIT: seen.popitem(last=False) return True
@app.post("/rconfig/webhook")def receive(): raw = request.get_data() # raw bytes, before any parsing if not signature_ok(request.headers.get("X-rConfig-Signature", ""), raw): abort(401) event = json.loads(raw) if event.get("schema_version") != 1: return "unsupported schema", 200 # 200 so rConfig doesn't retry if event.get("event") == "config.changed" and first_time(event["id"]): work.put(event) return "", 200 # webhook.test and other events: accept and ignore
def describe(event): data = event.get("data", {}) device, config = data.get("device", {}), data.get("config", {}) diff = data.get("diff") or {} lines = [f"{l['type']} {l['text']}" for l in diff.get("lines", []) if l["type"] in ("+", "-")] if diff.get("truncated"): lines.append(f"... {diff['total_lines']} lines in all; see rConfig for the full diff") if data.get("diff_error"): lines.append(f"(no diff: {data['diff_error']})") title = f"Config change on {device.get('name')} ({config.get('command')})" body = "\n".join([ event.get("summary", ""), f"Device: {device.get('name')} (rConfig ID {device.get('id')}, {device.get('category')})", f"Config version: {config.get('version')}", f"Detected: {event.get('occurred_at')}", f"View in rConfig: {event.get('url')}", "", "Changed lines:", *lines, ]) return title, body
def open_servicenow(title, body): response = requests.post( f"https://{os.environ['SN_INSTANCE']}.service-now.com/api/now/table/incident", auth=(os.environ["SN_USER"], os.environ["SN_PASSWORD"]), json={"short_description": title, "description": body, "category": "network"}, headers={"Accept": "application/json"}, timeout=30) response.raise_for_status() return response.json()["result"]["number"]
def open_jira(title, body): response = requests.post( f"{os.environ['JIRA_URL'].rstrip('/')}/rest/api/2/issue", auth=(os.environ["JIRA_USER"], os.environ["JIRA_TOKEN"]), json={"fields": {"project": {"key": os.environ["JIRA_PROJECT"]}, "summary": title, "description": body, "issuetype": {"name": "Task"}}}, timeout=30) response.raise_for_status() return response.json()["key"]
def worker(): while True: event = work.get() title, body = describe(event) for attempt in range(1, 4): try: ticket = open_servicenow(title, body) if SYSTEM == "servicenow" else open_jira(title, body) app.logger.info("event %s -> ticket %s", event["id"], ticket) break except requests.RequestException as exc: app.logger.warning("event %s attempt %d failed: %s", event["id"], attempt, exc) time.sleep(30 * attempt) work.task_done()
threading.Thread(target=worker, daemon=True).start()The ticket it opens
Config change on edge-rtr-01 (show running-config)
A configuration change was detected on edge-rtr-01 for command 'show running-config'.Device: edge-rtr-01 (rConfig ID 12, Routers)Config version: 42Detected: 2026-11-15T09:42:17+00:00View in rConfig: https://rconfig.example.com/configs/view/5521?ref=device-view
Changed lines:- logging host 192.0.2.50+ logging host 198.51.100.50Adapting it
- Link to the change record. If changes carry a change number (in a device description, or in your pipeline), look it up in
describe()and add it to the ticket, or close the ticket automatically when a matching approved change exists. - Only some devices. Filter on
data.device.categorybefore queuing, or use a separate webhook and receiver per team. - Survive restarts. The queue and duplicate list are in memory. For a production receiver, write events to a database or a message queue first, and work from that.
- Other events. The same receiver can handle
compliance.device_failedorconnection.device_failure; see the event list.