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 a plugin that have a callback for alert create #1881

Open
skather2811 opened this issue Sep 8, 2023 · 0 comments
Open

How to create a plugin that have a callback for alert create #1881

skather2811 opened this issue Sep 8, 2023 · 0 comments

Comments

@skather2811
Copy link

skather2811 commented Sep 8, 2023

Issue Summary
Need to create a plugin which adds an attribute to alert received from heartbeat . Main goal is blackout using that attribute instead of creating blackout for everyday . That plugin will add this attribute value true/false as per requirement

Environment

  • OS: Centos

  • For self-hosted, WSGI environment: uwsgi

  • Database: MongoDB

  • Server config:
    Auth enabled? No

  • Created a env using miniconda3

  • Located the plugins folder

  • create a sample file say holidaybalckout.py there

    `import logging
    from alerta.plugins import PluginBase
    LOG = logging.getLogger('alerta.plugins')
    class HolidayBlackoutReceiver(PluginBase):
    def pre_receive(self, alert, **kwargs):

      LOG.info('Enhancing alert...')
    
      day_of_week = alert.create_time.strftime('%a')
      hour_of_day = alert.create_time.hour
      if day_of_week in ['Sat', 'Sun'] or 8 > hour_of_day > 18:
          alert.attributes['isOutOfHours'] = True
      else:
          alert.attributes['isOutOfHours'] = False
      return alert
    

    def post_receive(self, alert, **kwargs):
    return

    def status_change(self, alert, status, text, **kwargs):
    return

    def take_action(self, alert, action, text, **kwargs):
    raise NotImplementedError

    def delete(self, alert, **kwargs) -> bool:
    raise NotImplementedError`

  • Added this file name in configuration file and then restarted uwsgi

Expecting to have an attribute in alert either true/false but nothing was there
Could you please help me with that and how can we have regex for blackout or can we define blackouts on based of attributes ?

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

1 participant