alerta/alerta

How to create new own plugins and deploy

Opened this issue · 4 comments

Hello,

Can we create new own plugins to alerta??
We are thinking create a plugin agains ticketing tool like remedy to open an update and close tickets.

We are checkin creating a file prueba.py:

import logging

from alerta.exceptions import RateLimit
from alerta.plugins import PluginBase

LOG = logging.getLogger('alerta.plugins.prueba')

class PruebaAlert(PluginBase):

def __init__(self, name=None):

    # plugin-specific init goes here
    # if not required, leave "__init__()" out completely

    super(PruebaAlert, self).__init__(name)

def pre_receive(self, alert):

    LOG.info("Estoy en pre_receive...")
    LOG.info({alert})
    #alerta send --resource web01 --event HttpError --correlate HttpOK --group Web --severity critical
    return alert

def post_receive(self, alert):

    #alerta send --resource web01 --event HttpError --correlate HttpOK --group Web --severity critical
    return

def status_change(self, alert, status, text):

    #alerta send --resource web01 --event HttpError --correlate HttpOK --group Web --severity critical
    return

def take_action(self, alert, action, text):

    LOG.info("Estoy en take_action...")
    LOG.info({alert})
    #alerta send --resource web01 --event HttpError --correlate HttpOK --group Web --severity critical
    return alert, action, text

We are getting this error, starting alerta in docker:

{"log":"2023-08-25 11:22:29,394 alerta.plugins[37]: [ERROR] Failed to load plugin 'prueba': 'prueba' [in /venv/lib/pyth on3.9/site-packages/alerta/utils/plugin.py:44]\n","stream":"stdout","time":"2023-08-25T11:22:29.394973708Z"}

Thanks and Regards.

You should consider using your python virtual environment to deploy your custom plugin.
Supposed you're in /opt, and you launched your command python3 -m venv alerta, you will now have your python virtual environment which is called alerta. Now place your prueba.py file in a path, example : /opt/webhooks, and launch this command : /opt/alerta/bin/pip install /opt/webhooks/
Hopefully this will solve your issue

Thanks Skander, I'm going on with tests, I need realise when operator write a new note in alarm, in my tests don't see anything in my plugin when add new note. How can I see new note in alarm??

Did you manage to deloy the plugin correctly ?
Can you show me the logs ?
Do you have any error message ? Or how to reproduce the issue ?
Anything can help

Hello Skander,

Yes my plugin run find, I see pre_receive, status_changes, take_actions and deletes.
I can do something every time operator add new note in alert, can I do with plugin or what do I need??

Thanks and Regards.