Having observed a significant latency between QRadar offense triage and the creation of corresponding incidents in our internal ServiceNow instance, I undertook a project to automate this workflow. The goal was to create a lightweight, containerized service that polls the QRadar API for new or updated offenses, applies a configurable set of filtering rules, and then creates or updates tickets via the ServiceNow REST API. This eliminates manual copy-paste and ensures our SOC's response actions are immediately tracked.
The core application is written in Python, leveraging asynchronous I/O for efficient polling of both systems. It operates on a few key principles:
* **Idempotency:** Offenses are keyed by their QRadar ID within the ticketing system, preventing duplicates.
* **State Management:** The app maintains a minimal internal cache of processed offenses to avoid unnecessary API calls.
* **Configurable Mapping:** Severity, offense source, and category mappings from QRadar to ServiceNow priority, category, and assignment group are defined in a YAML configuration file.
Below is the central function for fetching offenses and the logic for determining if an action is required. The full repository includes the ServiceNow client, logging configuration, and Dockerfile.
```python
import aiohttp
import yaml
from datetime import datetime, timedelta
class QRadarIntegrator:
def __init__(self, config_path):
with open(config_path, 'r') as f:
self.config = yaml.safe_load(f)
self.processed_offenses = set()
async def fetch_new_offenses(self):
"""Fetches offenses from QRadar modified in the last polling interval."""
headers = {'SEC': self.config['qradar']['api_token']}
params = {
'filter': f'status={self.config["filters"]["status"]}',
'last_updated': f'>{int((datetime.now() - timedelta(minutes=self.config["polling_interval"])).timestamp() * 1000)}'
}
async with aiohttp.ClientSession() as session:
async with session.get(f"{self.config['qradar']['base_url']}/api/siem/offenses",
headers=headers, params=params, ssl=False) as resp:
if resp.status == 200:
offenses = await resp.json()
return [off for off in offenses if off['id'] not in self.processed_offenses]
else:
raise Exception(f"QRadar API error: {resp.status}")
def determine_action(self, offense):
"""Applies business logic to decide if a ticket should be created or updated."""
# Example filter: Ignore low-severity offenses from certain source IPs
if offense['severity'] < self.config['filters']['min_severity']:
return None
if offense['source_address_ids'] in self.config['filters']['ignored_source_ips']:
return None
return 'create' if offense['id'] not in self.processed_offenses else 'update'
```
The configuration file structure allows for precise control:
```yaml
qradar:
base_url: " https://qradar.example.com"
api_token: "your_ariel_api_token"
servicenow:
instance: "your_instance.service-now.com"
username: "integration_user"
password: "integration_pass"
table: "incident"
filters:
status: "OPEN"
min_severity: 3
ignored_source_ips: [ "192.168.10.0/24" ]
mappings:
severity_to_priority:
1: 4
2: 3
3: 3
4: 2
5: 1
6: 1
7: 1
8: 1
9: 1
10: 1
```
**Deployment & Operational Considerations:**
* The application is designed to run as a Kubernetes CronJob or a systemd timer, not as a long-running daemon, to simplify failure recovery.
* All secrets are injected via environment variables or a secrets management tool, not hardcoded as in the example.
* Extensive logging is captured in JSON format for easy ingestion into our own observability stack (Loki/Prometheus/Grafana), allowing us to monitor the integration's health and throughput.
* A significant pitfall avoided was QRadar's API pagination; the full code includes handling for the `Range` header to ensure all offenses are retrieved.
This approach has reduced our mean time to ticket creation from approximately 15 minutes to under 60 seconds. The code is available in our internal Git repository, and I am considering open-sourcing a generic version if there is community interest. I am particularly curious if others have implemented similar bridges and how they handle more complex workflows, such as closing QRadar offenses when a ticket is resolved in ServiceNow.
Sleep is for the weak. Latency is the enemy.