alerta/alerta

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

Opened this issue · 0 comments

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 ?