Beispiel #1
0
def record_deployment(artifact_description = None, node_description = None, datadog_api_key = None, datadog_tags = None):
    """
    Records Datadog event indicating deployment occurred. Git SHA included.
    :param artifact_description: defaults to git.get_sha()
    :param node_description: defaults to pretty_instance()
    :param datadog_api_key: interpreted via get_api_key
    :param datadog_tags: interpreted via get_datadog_tags
    """
    artifact_description = artifact_description or 'Git SHA %s' % git.get_sha()
    node_description = node_description or pretty_instance()
    message = '%s deployed to %s' % (artifact_description, node_description)
    debug("Recording in Datadog: %s"  % message)
    api.api_key = get_datadog_api_key(datadog_api_key)
    api.event_with_response("Deployment", message, tags=get_datadog_tags(datadog_tags))
def sendEvent():
    # create necessary values for event
    title = "Event created via Flask"
    text = "This event was created via a test module using flask"
    tags = ["version:1", "application:web"]
    # create event, store the event ID returned by the API call
    event_id = api.event_with_response(title, text, tags=tags)
    # debug statement: print "\n\nevent_id = %s\n\n" % str(event_id)
    # example event_id = '2399094330515743017'
    time.sleep(0.05)  # appears to take an average of 0.05 seconds for created event to be retreivable
    # get dict containing event information
    event_info = api.get_event(event_id)
    # sometimes the event is not retreivable, so try again until it is
    while "errors" in event_info:
        time.sleep(0.05)
        event_info = api.get_event(event_id)
    # debug statement: print "event_info = %s\n\n" % str(event_info)
    # format message to be emailed
    msg = Message(event_info["title"], sender=USERNAME, recipients=[USERNAME])
    msg.body = "Event created via Flask: \n"
    for item in event_info.keys():
        msg.body = msg.body + "%s: %s\n" % (item, event_info[item])
    # print "\n\nMessage Body:\n%s\n\n" % str(msg.body)
    # send message
    mail.send(msg)
    # return JSON containing info from the raised event
    return jsonify(event_info)
Beispiel #3
0
 def send_alert(self, message, device_id):
     title = 'Load balancer failure in {0}'.format(self.dd_env)
     text = 'Load balancer failed with message {0} {1}'.format(
         message, self.dd_message_tail
     )
     tags = self.dd_tags.split()
     resp = api.event_with_response(
         title, text, tags=tags, alert_type='error'
     )
     LOG.info('Datadog alert response: {0}'.format(resp))
Beispiel #4
0
 def send_alert(self, message, device_id):
     title = 'Load balancer failure in {0}'.format(self.dd_env)
     text = 'Load balancer failed with message {0} {1}'.format(
         message, self.dd_message_tail)
     tags = self.dd_tags.split()
     resp = api.event_with_response(title,
                                    text,
                                    tags=tags,
                                    alert_type='error')
     LOG.info('Datadog alert response: {0}'.format(resp))
Beispiel #5
0
 def send_delete(self, message, device_id):
     title = 'Load balancer unreachable in {0}'.\
         format(self.dd_env)
     text = 'Load balancer unreachable with message {0} {1}'.format(
         message, self.dd_message_tail
     )
     tags = self.dd_tags.split()
     resp = api.event_with_response(
         title, text, tags=tags, alert_type='success'
     )
     LOG.info('Datadog alert response: {0}'.format(resp))
Beispiel #6
0
 def send_delete(self, message, device_id):
     title = 'Load balancer unreachable in {0}'.\
         format(self.dd_env)
     text = 'Load balancer unreachable with message {0} {1}'.format(
         message, self.dd_message_tail)
     tags = self.dd_tags.split()
     resp = api.event_with_response(title,
                                    text,
                                    tags=tags,
                                    alert_type='success')
     LOG.info('Datadog alert response: {0}'.format(resp))
def send(data):
    title = template(title_template, **data)
    text = template(text_template, **data)
    tags = [tag for tag in TAGS if tag]
    tags.append('app:{}'.format(data['app']['short_name']))
    tags.append('subject_type:{}'.format(data['subject_type']))
    tags.append('organization:{}'.format(data['organization']['short_name']))
    subject_type = data.get('subject_type', '')
    if subject_type in ['release']:
        alert_type = 'success'
    elif subject_type in ['errorgroup']:
        alert_type = 'error'
    else:
        alert_type = 'info'
    tags.append(alert_type)
    api.event_with_response(
        title,
        text,
        tags=tags,
        alert_type=alert_type,
    )
Beispiel #8
0
        return
    if c < instance_count:
        print 'bees: error: the number of concurrent requests must be at least %d (num. instances)' % instance_count
        return
    if n < c:
        print 'bees: error: the number of concurrent requests (%d) must be at most the same as number of requests (%d)' % (c, n)
        return

    requests_per_instance = int(float(n) / instance_count)
    connections_per_instance = int(float(c) / instance_count)

    msg = 'Each of %i bees will fire %s rounds, %s at a time.' % (instance_count, requests_per_instance, connections_per_instance)
    print msg
    if options.get('dog_app_key', ''):
        msg = '%s url=(%s)' % (msg, url)
        api.event_with_response('bees attack', msg, source_type_name='bees', tags=dog_tags)

    params = []

    for i, instance in enumerate(instances):
        kwargs = {
            'i': i,
            'instance_id': instance.id,
            'url': url,
            'concurrent_requests': connections_per_instance,
            'num_requests': requests_per_instance,
            'username': username,
            'key_name': key_name,
            'headers': headers,
            'cookies': cookies,
            'post_file': options.get('post_file'),
from dogapi import dog_http_api as api

api.api_key = '9775a026f1ca7d1c6c5af9d94d9595a4'
api.application_key = '87ce4a24b5553d2e482ea8a8500e71b8ad4554ff'

title = "Something big happened!"
text = 'And let me tell you all about it here!'
tags = ['version:1', 'application:web']

# All optional parameters are specified as keyword arguments.
api.event_with_response(title, text, tags=tags)