Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a Google Cloud Platform webhook receiver #383

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions webhooks/gcp/README.md
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.

43 changes: 43 additions & 0 deletions webhooks/gcp/alerta_gcp.py
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'].lower() == 'closed':
severity = 'normal'
else:
severity = os.environ.get('GCP_DEFAULT_ALERT_SEVERITY', 'warning')

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.get('resource_display_name','N/A'),
event=gcp_alert.get('policy_name','GCPEvent'),
environment='Production',
severity=severity,
service=['GCP'],
group='Cloud',
value=value,
text=gcp_alert.get('summary', 'Something happened in GCP'),
origin='gcp',
attributes=attributes,
raw_data=str(payload)
)
23 changes: 23 additions & 0 deletions webhooks/gcp/setup.py
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'
]
}
)