0
0
Fork 0
mirror of https://github.com/alerta/alerta-contrib.git synced 2025-03-16 21:43:30 +00:00

HipChat has been discontinued ()

This commit is contained in:
Nick Satterly 2020-06-26 22:02:45 +02:00 committed by GitHub
parent 862c47064a
commit a08fd9be3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 0 additions and 191 deletions

View file

@ -41,7 +41,6 @@ Plugins
* [Enhance](plugins/enhance)
* [Forward](plugins/forward)
* [GeoIP](plugins/geoip)
* [HipChat](plugins/hipchat)
* [InfluxDB](plugins/influxdb)
* [Logstash](plugins/logstash)
* [Mattermost](plugins/mattermost)

View file

@ -1,63 +0,0 @@
HipChat Plugin
==============
Send HipChat messages for new alerts.
If you have the Python Jinja2 package installed you can customize the
HipChat message format.
For help, join [![Gitter chat](https://badges.gitter.im/alerta/chat.png)](https://gitter.im/alerta/chat)
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=plugins/hipchat
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
-------------
Add `hipchat` to the list of enabled `PLUGINS` in `alertad.conf` server
configuration file and set plugin-specific variables either in the
server configuration file or as environment variables.
```python
PLUGINS = ['hipchat']
HIPCHAT_ROOM = 'alerts'
HIPCHAT_API_KEY = 'W4Dll5plS0qrqXCpPwjwzF9pO2TJI2Oou9Xaq8je'
DASHBOARD_URL = 'http://try.alerta.io'
HIPCHAT_URL = 'https://api.hipchat.com/v2'
HIPCHAT_VERIFY_SSL = True
```
The `HIPCHAT_SUMMARY_FMT` configuration variable is a Jinja2 template
string and accepts any Jinja2 syntax. The formatter has access to two
variables in the template environment, 'alert' for all alert details
and 'config' for access to the alerta configuration.
If you have Jinja2 available you can try customizing the message like
this:
```python
HIPCHAT_SUMMARY_FMT = '<b>[{{ alert.status|capitalize }}]</b> [{{ alert.severity|upper }}] Event {{ alert.event }} on <b>{{ alert.resource }}</b> <a href="{{ config.DASHBOARD_URL }}/#/alert/{{ alert.id }}">{{ alert.id[:8] }}</a>'
```
References
----------
* HipChat room notification API: https://www.hipchat.com/docs/apiv2/method/send_room_notification
* Jinja2 templating language for Python: http://jinja.pocoo.org/docs/dev/
License
-------
Copyright (c) 2016 Nick Satterly. Available under the MIT License.

View file

@ -1,100 +0,0 @@
import json
import logging
import os
import requests
try:
from alerta.plugins import app # alerta >= 5.0
except ImportError:
from alerta.app import app # alerta < 5.0
from alerta.plugins import PluginBase
LOG = logging.getLogger('alerta.plugins.hipchat')
try:
from jinja2 import Template
except Exception as e:
LOG.error('HipChat: ERROR - Jinja template error: %s, template functionality will be unavailable', e)
class SendRoomNotification(PluginBase):
def pre_receive(self, alert, **kwargs):
return alert
def post_receive(self, alert, **kwargs):
HIPCHAT_URL = self.get_config('HIPCHAT_URL', default='https://api.hipchat.com/v2', type=str, **kwargs) # Hipchat URL, change if using privately hosted Hipchat
HIPCHAT_API_KEY = self.get_config('HIPCHAT_API_KEY', **kwargs) # Room Notification Token
HIPCHAT_SUMMARY_FMT = self.get_config('HIPCHAT_SUMMARY_FMT', **kwargs) # Message summary format
HIPCHAT_VERIFY_SSL = self.get_config('HIPCHAT_VERIFY_SSL', default=True, type=bool, **kwargs) # Verify SSL cert from Hipchat
DASHBOARD_URL = self.get_config('DASHBOARD_URL', default='', type=str, **kwargs)
HIPCHAT_ROOM = self.get_config('HIPCHAT_ROOM', **kwargs) # Room Name or Room API ID
if alert.repeat:
return
if HIPCHAT_SUMMARY_FMT:
try:
template = Template(HIPCHAT_SUMMARY_FMT)
except Exception as e:
LOG.error('HipChat: ERROR - Template init failed: %s', e)
return
try:
template_vars = {
'alert': alert,
'config': app.config
}
summary = template.render(**template_vars)
except Exception as e:
LOG.error('HipChat: ERROR - Template render failed: %s', e)
return
else:
summary = ('<b>[{status}] {environment} {service} {severity} - <i>{event} on {resource}</i></b> <a href="{dashboard}/#/alert/{alert_id}">{short_id}</a>').format(
status=alert.status.capitalize(),
environment=alert.environment.upper(),
service=','.join(alert.service),
severity=alert.severity.capitalize(),
event=alert.event,
resource=alert.resource,
alert_id=alert.id,
short_id=alert.get_id(short=True),
dashboard=DASHBOARD_URL
)
if alert.severity == 'critical':
color = "red"
elif alert.severity == 'major':
color = "purple"
elif alert.severity == 'minor':
color = "yellow"
elif alert.severity == 'warning':
color = "gray"
else:
color = "green"
payload = {
"color": color,
"message": summary,
"notify": True,
"message_format": "html"
}
LOG.debug('HipChat payload: %s', payload)
url = '%s/room/%s/notification' % (HIPCHAT_URL, HIPCHAT_ROOM)
headers = {
'Authorization': 'Bearer ' + HIPCHAT_API_KEY,
'Content-type': 'application/json'
}
LOG.debug('HipChat: Notification sent to %s', url)
try:
r = requests.post(url, data=json.dumps(payload), headers=headers, timeout=2, verify=HIPCHAT_VERIFY_SSL)
except Exception as e:
raise RuntimeError("HipChat: ERROR - %s", e)
LOG.debug('HipChat: %s - %s', r.status_code, r.text)
def status_change(self, alert, status, text, **kwargs):
return

View file

@ -1,27 +0,0 @@
from setuptools import setup, find_packages
version = '5.3.4'
setup(
name="alerta-hipchat",
version=version,
description='Alerta plugin for HipChat',
url='https://github.com/alerta/alerta-contrib',
license='MIT',
author='Nick Satterly',
author_email='nick.satterly@theguardian.com',
packages=find_packages(),
py_modules=['alerta_hipchat'],
install_requires=[
'requests',
'jinja2'
],
include_package_data=True,
zip_safe=True,
entry_points={
'alerta.plugins': [
'hipchat = alerta_hipchat:SendRoomNotification'
]
}
)