How to use the datadog.api.Event.create function in datadog

To help you get started, we’ve selected a few datadog examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / testpilot / testpilot / metrics / views.py View on Github external
def handle_metric(metric):
    # will eventually handle multiple types of metrics, including
    # statsd types.
    datadog.api.Event.create(title=metric['title'], text=json.dumps(metric),
                             tags=metric['event-data']['tags'])
github DataDog / datadogpy / tests / unit / api / test_api.py View on Github external
def test_submit_event_wrong_alert_type(self):
        """
        Assess that an event submitted with a wrong alert_type raises the correct Exception
        """
        with pytest.raises(ApiError) as excinfo:
            Event.create(
                title="test no hostname", text="test no hostname", attach_host_name=False, alert_type="wrong_type"
            )
        assert "Parameter alert_type must be either error, warning, info or success" in str(excinfo.value)
github ansible / ansible / lib / ansible / modules / monitoring / datadog / datadog_event.py View on Github external
def _post_event(module):
    try:
        if module.params['host'] is None:
            module.params['host'] = platform.node().split('.')[0]
        msg = api.Event.create(title=module.params['title'],
                               text=module.params['text'],
                               host=module.params['host'],
                               tags=module.params['tags'],
                               priority=module.params['priority'],
                               alert_type=module.params['alert_type'],
                               aggregation_key=module.params['aggregation_key'],
                               source_type_name='ansible')
        if msg['status'] != 'ok':
            module.fail_json(msg=msg)

        module.exit_json(changed=True, msg=msg)
    except Exception as e:
        module.fail_json(msg=to_native(e), exception=traceback.format_exc())
github dimagi / commcare-hq / corehq / apps / hqadmin / management / commands / record_deploy_success.py View on Github external
else:
                channel = '#hq-ops'
            requests.post(settings.MIA_THE_DEPLOY_BOT_API, data=json.dumps({
                "username": "Igor the Iguana",
                "channel": channel,
                "text": deploy_notification_text.format(
                    dashboard_link=dashboard_link(STYLE_SLACK, DASHBOARD_URL),
                    diff_link=link,
                    integration_tests_link=integration_tests_link(STYLE_SLACK, INTEGRATION_TEST_URL)
                ),
            }))

        if settings.DATADOG_API_KEY:
            tags = ['environment:{}'.format(options['environment'])]
            link = diff_link(STYLE_MARKDOWN, compare_url)
            datadog_api.Event.create(
                title="Deploy Success",
                text=deploy_notification_text.format(
                    dashboard_link=dashboard_link(STYLE_MARKDOWN, DASHBOARD_URL),
                    diff_link=link,
                    integration_tests_link=integration_tests_link(STYLE_MARKDOWN, INTEGRATION_TEST_URL)
                ),
                tags=tags,
                alert_type="success"
            )

            print("\n=============================================================\n" \
                  "Congratulations! Deploy Complete.\n\n" \
                  "Don't forget to keep an eye on the deploy dashboard to " \
                  "make sure everything is running smoothly.\n\n" \
                  "https://p.datadoghq.com/sb/5c4af2ac8-1f739e93ef" \
                  "\n=============================================================\n")
github dimagi / commcare-hq / corehq / util / datadog / utils.py View on Github external
def create_datadog_event(title, text, alert_type=ALERT_INFO, tags=None, aggregation_key=None):
    tags = COMMON_TAGS + (tags or [])
    if datadog_initialized():
        try:
            api.Event.create(
                title=title, text=text, tags=tags,
                alert_type=alert_type, aggregation_key=aggregation_key,
            )
        except Exception as e:
            datadog_logger.exception('Error creating Datadog event', e)
    else:
        datadog_logger.debug('Datadog event: (%s) %s\n%s', alert_type, title, text)
github DataDog / integrations-core / .github / actions / trello_release / action.py View on Github external
def emit_dd_event(status, msg):
    options = {
        'api_key': os.environ['DD_API_KEY'],
    }
    initialize(**options)

    title = f"Trello Card creation {status}"
    text = msg
    tags = ['team:agent-integrations', 'application:trello_github_action']

    api.Event.create(title=title, text=text, tags=tags)
github dimagi / commcare-cloud / ansible / plugins / callback / datadog_callback.py View on Github external
def _send_event(self, title, alert_type=None, text=None, tags=None, host=None, event_type=None, event_object=None):
        if tags is None:
            tags = []
        tags.extend(self.default_tags)
        priority = 'normal' if alert_type == 'error' else 'low'
        host = self._generate_datadog_hostname(host)
        try:
            datadog.api.Event.create(
                title=title,
                text=text,
                alert_type=alert_type,
                priority=priority,
                tags=tags,
                host=host,
                source_type_name='ansible',
                event_type=event_type,
                event_object=event_object,
            )
        except Exception as e:
            # We don't want Ansible to fail on an API error
            print('Couldn\'t send event "{0}" to Datadog'.format(title))
            print(e)
github ansible / ansible / lib / ansible / modules / extras / monitoring / datadog_event.py View on Github external
def _post_event(module):
    try:
        msg = api.Event.create(title=module.params['title'],
                               text=module.params['text'],
                               tags=module.params['tags'],
                               priority=module.params['priority'],
                               alert_type=module.params['alert_type'],
                               aggregation_key=module.params['aggregation_key'],
                               source_type_name='ansible')
        if msg['status'] != 'ok':
            module.fail_json(msg=msg)

        module.exit_json(changed=True, msg=msg)
    except Exception:
        e = get_exception()
        module.fail_json(msg=str(e))
github DataDog / integrations-core / .gitlab / reminder / remind.py View on Github external
def emit_dd_event(title, message):
    dd.api.Event.create(title=title, text=message, tags=TAGS)