-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a Google Cloud Platform webhook receiver
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Google Cloud Platform Webhook | ||
============== | ||
|
||
Receive [GCP](https://cloud.google.com) alerts via webhook callbacks. | ||
|
||
For help, join [![Slack chat](https://img.shields.io/badge/chat-on%20slack-blue?logo=slack)](https://slack.alerta.dev) | ||
|
||
Installation | ||
------------ | ||
|
||
Clone the GitHub repo and run: | ||
|
||
$ python setup.py install | ||
|
||
Or, to install remotely from GitHub run: | ||
|
||
$ pip install git+https://github.com/alerta/alerta-contrib.git#subdirectory=webhooks/atlas | ||
|
||
Note: If Alerta is installed in a python virtual environment then plugins | ||
need to be installed into the same environment for Alerta to dynamically | ||
discover them. | ||
|
||
Configuration | ||
------------- | ||
|
||
The custom webhook will be auto-detected and added to the list of available API endpoints. | ||
|
||
Add the Alerta API webhook URL in the GCP webhook section | ||
|
||
|
||
References | ||
---------- | ||
|
||
* GCP notifications: https://cloud.google.com/monitoring/support/notification-options#webhooks | ||
|
||
License | ||
------- | ||
|
||
Copyright (c) 2020 Matthieu Serrepuy. Available under the MIT License. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from flask import request | ||
from alerta.models.alert import Alert | ||
from alerta.webhooks import WebhookBase | ||
import os | ||
import logging | ||
|
||
LOG = logging.getLogger('alerta.webhooks.gcp') | ||
|
||
class GoogleCloudPlatformWebhook(WebhookBase): | ||
|
||
def incoming(self, query_string, payload): | ||
gcp_alert = payload['incident'] | ||
|
||
if gcp_alert['state'] == 'OPEN': | ||
severity = os.environ.get('GCP_DEFAULT_ALERT_SEVERITY', 'warning') | ||
else: | ||
severity = 'normal' | ||
|
||
value = "N/A" | ||
try: | ||
value = gcp_alert['observed_value'] | ||
except: | ||
LOG.error("Unable to real alert observed_value") | ||
|
||
attributes = { | ||
"incident-id": gcp_alert.get('incident_id'), | ||
"documenation": gcp_alert.get('documentation'), | ||
"Source Alert": gcp_alert.get('url') | ||
} | ||
|
||
return Alert( | ||
resource=gcp_alert['resource_display_name'], | ||
event=gcp_alert['policy_name'], | ||
environment='Production', | ||
severity=severity, | ||
service=['GCP'], | ||
group='Cloud', | ||
value=value, | ||
text=gcp_alert['summary'], | ||
origin='gcp', | ||
attributes=attributes, | ||
raw_data=str(payload) | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from setuptools import setup, find_packages | ||
|
||
version = '0.0.1' | ||
|
||
setup( | ||
name="alerta-gcp", | ||
version=version, | ||
description='Alerta webhook for GCP', | ||
url='https://github.com/alerta/alerta-contrib', | ||
license='Apache License 2.0', | ||
author='Matthieu Serrepuy', | ||
author_email='[email protected]', | ||
packages=find_packages(), | ||
py_modules=['alerta_gcp'], | ||
install_requires=[], | ||
include_package_data=True, | ||
zip_safe=True, | ||
entry_points={ | ||
'alerta.webhooks': [ | ||
'gcp = alerta_gcp:GoogleCloudPlatformWebhook' | ||
] | ||
} | ||
) |