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

How to create new own plugins and deploy #1877

Open
prueba-ai opened this issue Aug 25, 2023 · 4 comments
Open

How to create new own plugins and deploy #1877

prueba-ai opened this issue Aug 25, 2023 · 4 comments

Comments

@prueba-ai
Copy link

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.

@SkanderRedjel
Copy link

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

@prueba-ai
Copy link
Author

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??

@SkanderRedjel
Copy link

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

@prueba-ai
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants