alerta / alerta-contrib

Contributed integrations, plugins and custom webhooks
http://alerta.io
MIT License
119 stars 170 forks source link

create alerta plugin for dingtalk #258

Closed Komalgupta22722 closed 5 years ago

Komalgupta22722 commented 5 years ago

Issue Summary I m creating dingtalk plugin for alerta and getting this serror while running alerta

2019-05-15 17:13:08,070 - raven.base.Client[21866]: INFO - Raven is not configured (logging is disabled). Please see the documentation for more information. [in /usr/local/lib/python3.6/dist-packages/raven/base.py:220]
2019-05-15 17:13:08,084 - alerta.plugins[21866]: DEBUG - Server plugin 'transient' found. [in /usr/local/lib/python3.6/dist-packages/alerta/utils/plugin.py:34]
2019-05-15 17:13:08,090 - alerta.plugins[21866]: DEBUG - Server plugin 'pagerduty' found. [in /usr/local/lib/python3.6/dist-packages/alerta/utils/plugin.py:34]
2019-05-15 17:13:08,092 - alerta.plugins[21866]: DEBUG - Server plugin 'amqp' found. [in /usr/local/lib/python3.6/dist-packages/alerta/utils/plugin.py:34]
2019-05-15 17:13:08,111 - alerta.plugins[21866]: DEBUG - Server plugin 'blackout' found. [in /usr/local/lib/python3.6/dist-packages/alerta/utils/plugin.py:34]
2019-05-15 17:13:08,112 - alerta.plugins[21866]: DEBUG - Server plugin 'heartbeat' found. [in /usr/local/lib/python3.6/dist-packages/alerta/utils/plugin.py:34]
2019-05-15 17:13:08,112 - alerta.plugins[21866]: DEBUG - Server plugin 'reject' found. [in /usr/local/lib/python3.6/dist-packages/alerta/utils/plugin.py:34]
2019-05-15 17:13:08,112 - alerta.plugins[21866]: DEBUG - Server plugin 'remote_ip' found. [in /usr/local/lib/python3.6/dist-packages/alerta/utils/plugin.py:34]
2019-05-15 17:13:08,156 - alerta.plugins[21866]: ERROR - ****Failed to load plugin 'transient': name 'logging' is not defined [in /usr/local/lib/python3.6/dist-packages/alerta/utils/plugin.py:44]
2019-05-15 17:13:08,219 - alerta.plugins[21866]: INFO -**** 

    Add originating IP address of HTTP client as an alert attribute. This information
    can be used for debugging, access control, or generating geolocation data.

Environment

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....' or Run '...'
  3. Scroll down to '....'
  4. See error (include command output)

For web app issues, include any web browser JavaScript console errors.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context my transient.py:

from dingtalkchatbot.chatbot import DingtalkChatbot
import time
import json
import sys

try:
    from alerta.plugins import app  # alerta >= 5.0
except ImportError:
    from alerta.app import app  # alerta < 5.0
from alerta.plugins import PluginBase

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

DING_WEBHOOK_URL = os.environ.get('DING_WEBHOOK_URL') or app.config.get('DING_WEBHOOK_URL')
DING_SUMMARY_FMT = os.environ.get('DING_SUMMARY_FMT') or app.config.get('DING_SUMMARY_FMT', None)  # Message summary format
DASHBOARD_URL = os.environ.get('DASHBOARD_URL') or app.config.get('DASHBOARD_URL', '')

class ExamplePlugin(PluginBase):

    def __init__(self, name=None):

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

        super(ExamplePlugin, self).__init__(name)

    def pre_receive(self, alert):

        # reject or modify an alert before it hits the database

        return alert

    def post_receive(self, alert):

        # after alert saved in database, forward alert to external systems

        if alert.repeat:
            return

        if DING_SUMMARY_FMT:
            try:
                template = Template(DING_SUMMARY_FMT)
            except Exception as e:
                LOG.error('DING: ERROR - Template init failed: %s', e)
                return

            try:
                template_vars = {
                    'alert': alert,
                    'config': app.config
                }
                summary = template.render(**template_vars)
            except Exception as e:
                LOG.error('DING: ERROR - Template render failed: %s', e)
                return
        else:
            summary = ('<b>[{status}] {environment} {service} {severity} - <i>{event} on {resource}</i></b>').format(
                status=alert.status.capitalize(),
                environment=alert.environment.upper(),
                service=','.join(alert.service),
                severity=alert.severity.capitalize(),
                event=alert.event,
                resource=alert.resource
            )
            url = "%s/#/alert/%s" % (DASHBOARD_URL, alert.id)

        LOG.debug('DING payload: %s', summary)

        try:
            xiaoding = DingtalkChatbot(DING_WEBHOOK_URL)
            xiaoding.send()

        except Exception as e:
            raise RuntimeError("DING: ERROR - %s", e)

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

        # triggered by external status changes, used by integrations

        return

NOTE: Please provide as much information about your issue as possible. Failure to provide basic details about your specific environment make it impossible to know if an issue has already been fixed, can delay a response and may result in your issue being closed without a resolution.

satterly commented 5 years ago

You didn't copy the first line of the example plugin where it says import logging.

Komalgupta22722 commented 5 years ago

its solved already.... thanks

On Thu, May 16, 2019 at 1:35 AM Nick Satterly notifications@github.com wrote:

You didn't copy the first line of the example plugin where it says import logging.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/alerta/alerta-contrib/issues/258?email_source=notifications&email_token=ALJGXX7E2REOAKDCAK5YAYLPVRUKFA5CNFSM4HNCQHL2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVPZNNA#issuecomment-492803764, or mute the thread https://github.com/notifications/unsubscribe-auth/ALJGXX3LLQYVTKBAN5242PLPVRUKFANCNFSM4HNCQHLQ .

-- Thanks, Komal Gupta

shreyagarwal commented 5 years ago

Hi @satterly , we would like to contribute back the plugin we ( @Komalgupta22722 and our org) made for Dingtalk. How to contribute ?

satterly commented 5 years ago

Create a pull request against this repo and submit your plugin into a plugins/dingtalk subdirectory. Please include setup.py and README. Thanks!

deep7710 commented 4 years ago

has this plugin for dingtalk integration been merged!!

komalgupta2017 commented 4 years ago

Please merge this: https://github.com/alerta/alerta-contrib/pull/308