Skip to content
Notifications
Clear all

Just built a custom action script to post high-severity offenses to a Slack war room.

3 Posts
3 Users
0 Reactions
9 Views
(@markw6)
Eminent Member
Joined: 1 week ago
Posts: 14
Topic starter   [#3307]

QRadar's built-in notification actions are limited. Needed high-severity offenses to trigger an immediate post in our incident response Slack channel.

Built a custom action script that uses the offense ID from the context. Script fetches offense details via API and formats a clean Slack message. Requires a valid API key and Slack webhook.

```python
#!/opt/qradar/bin/python
# Custom Action Script for Slack
import sys
import json
import requests
from qpylib import qpylib

# Fetch offense details
offense_id = sys.argv[1]
api_url = '/api/siem/offenses/{0}'.format(offense_id)
offense_data = qpylib.REST('GET', api_url)
offense_json = json.loads(offense_data.read())

# Build Slack payload
slack_payload = {
"text": "High Severity Offense Created",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"*Offense ID:* {offense_json['id']}n*Severity:* {offense_json['severity']}n*Description:* {offense_json['description']}"
}
}
]
}

# Post to Slack webhook
webhook_url = 'YOUR_SLACK_WEBHOOK_URL'
response = requests.post(webhook_url, json=slack_payload)
if response.status_code != 200:
qpylib.log('Failed to post to Slack: ' + str(response.status_code))
```

Deploy to `/opt/qradar/bin/` and configure a rule action to execute it. Now the SOC team sees critical offenses in under 10 seconds. Main pitfall: ensure your appliance has outbound HTTPS access to Slack's API endpoints.

mw


Infrastructure is code.


   
Quote
(@lucyw2)
Eminent Member
Joined: 1 week ago
Posts: 15
 

This is super helpful, thanks for sharing! I'm just starting with QRadar automation. A quick question - where do you actually store and manage the API key securely in this setup? Is it in a config file the script reads, or somewhere else in QRadar? I'm always nervous about hardcoding that stuff.



   
ReplyQuote
(@cloud_rookie_em)
Estimable Member
Joined: 3 months ago
Posts: 138
 

Yeah, I was wondering about that too. Hardcoding API keys in a script is a big no-go for security audits.

I think you can store the Slack webhook URL in QRadar's custom action properties. It gets passed to the script as an environment variable or argument, keeps it out of the code. But the QRadar API token itself... that's trickier. Maybe using the qpylib's built-in auth handles that part? I'm not sure.

Does anyone know if the script inherits the context's permissions, so you don't need to store a separate API key for fetching the offense?



   
ReplyQuote