Created
September 18, 2021 23:00
-
-
Save BoredHackerBlog/8c44db13db33d098a19b9d69ae53bb74 to your computer and use it in GitHub Desktop.
humio to og alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import request | |
from flask import Flask | |
import opsgenie_sdk | |
app = Flask(__name__) | |
og = opsgenie_sdk.configuration.Configuration() | |
og.api_key['Authorization'] = "" | |
og.api_client = opsgenie_sdk.api_client.ApiClient(configuration=og) | |
og.alert_api = opsgenie_sdk.AlertApi(api_client=og.api_client) | |
def process_event(events): | |
global og | |
alert_repo = events['repository'] | |
alert_timestamp = events['timestamp'] | |
alert_name = events['alert']['name'] | |
alert_desc = events['alert']['description'] | |
alert_url = events['url'] | |
for event in events['events']: | |
event['alert_repo'] = alert_repo | |
event['alert_timestamp'] = alert_timestamp | |
event['alert_name'] = alert_name | |
event['alert_desc'] = alert_desc | |
event['alert_url'] = alert_url | |
body = opsgenie_sdk.CreateAlertPayload( | |
message = f"{alert_repo} - {alert_name} - {alert_timestamp}", | |
details = event, | |
priority="P3" | |
) | |
# try this, if failed then alert w/ json blob | |
og.alert_api.create_alert(create_alert_payload=body) | |
@app.route('/events', methods=['POST']) | |
def events(): | |
process_event(request.get_json()) | |
return "Thanks" | |
# notifier json | |
""" | |
{ | |
"repository": "{repo_name}", | |
"url":"{url}", | |
"timestamp": "{triggered_timestamp}", | |
"alert": { | |
"name": "{name}", | |
"description": "{description}", | |
"query": { | |
"queryString": "{query_string} ", | |
"end": "{query_time_end}", | |
"start": "{query_time_start}" | |
}, | |
"notifierID": "{action_id}", | |
"id": "{id}" | |
}, | |
"warnings": "{warnings}", | |
"events": {events}, | |
"numberOfEvents": {event_count} | |
} | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment