Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Nick Satterly
fe2c997a4c Add debug plugin 2019-05-18 00:02:16 +02:00
3 changed files with 139 additions and 0 deletions

48
plugins/debug/README.md Normal file
View file

@ -0,0 +1,48 @@
Debug Plugin
============
Used for debugging only.
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/debug
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 `debug` 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 = ['debug']
```
**Example Configuration**
```python
DEBUG = True
```
References
----------
n/a
License
-------
Copyright (c) 2019 Nick Satterly. Available under the MIT License.

View file

@ -0,0 +1,67 @@
import os
import json
import logging
from alerta.plugins import PluginBase
LOG = logging.getLogger()
class DebugTracing(PluginBase):
"""
Test plugin for debug and tracing.
"""
def pre_receive(self, alert, **kwargs):
LOG.info('Debug plugin - pre_receive() start.')
DEBUG = self.get_config('DEBUG', default=False, type=bool, **kwargs)
LOG.info('DEBUG=%s' % DEBUG)
BOOL_VAR = self.get_config('BOOL_VAR', default=False, type=bool, **kwargs)
INT_VAR = self.get_config('INT_VAR', default=0, type=int, **kwargs)
FLOAT_VAR = self.get_config('FLOAT_VAR', default=0.1, type=float, **kwargs)
LIST_VAR = self.get_config('LIST_VAR', default=['default', 'list'], type=list, **kwargs)
STR_VAR = self.get_config('STR_VAR', default='default-string', type=str, **kwargs)
DICT_VAR = self.get_config('DICT_VAR', default={'default': 'dict'}, type=json.loads, **kwargs)
LOG.debug('BOOL_VAR=%s' % BOOL_VAR)
LOG.debug('INT_VAR=%s' % INT_VAR)
LOG.debug('FLOAT_VAR=%s' % FLOAT_VAR)
LOG.debug('LIST_VAR=%s' % LIST_VAR)
LOG.debug('STR_VAR=%s' % STR_VAR)
LOG.debug('DICT_VAR=%s' % DICT_VAR)
LOG.debug('-' * 40)
LOG.debug(os.environ)
LOG.debug('-' * 40)
LOG.debug('-' * 40)
LOG.debug(kwargs['config'])
LOG.debug('-' * 40)
LOG.info('Debug plugin - pre_receive() end.')
return alert
def post_receive(self, alert, **kwargs):
LOG.info('Debug plugin - post_receive() start.')
LOG.info('Debug plugin - post_receive() end.')
return
def status_change(self, alert, status, text, **kwargs):
LOG.info('Debug plugin - status_change() start.')
LOG.info('Debug plugin - status_change() end.')
return
def take_action(self, alert, action, text, **kwargs):
LOG.info('Debug plugin - take_action() start.')
LOG.info('Debug plugin - take_action() end.')
raise NotImplementedError

24
plugins/debug/setup.py Normal file
View file

@ -0,0 +1,24 @@
from setuptools import setup, find_packages
version = '7.0.0'
setup(
name="alerta-debug",
version=version,
description='Alerta plugin for debug & tracing',
url='https://github.com/alerta/alerta-contrib',
license='MIT',
author='Nick Satterly',
author_email='nick.satterly@gmail.com',
packages=find_packages(),
py_modules=['alerta_debug'],
include_package_data=True,
zip_safe=True,
entry_points={
'alerta.plugins': [
'debug = alerta_debug:DebugTracing'
]
},
python_requires='>=3.5'
)