Example #1
0
def notify(targetMarathonUrl, service):
    parsedMarathonUrl = urlparse(targetMarathonUrl)
    tags = ["environment:%s" % service.environment, "service:%s" % service.id]
    title = "Deployed %s to the %s environment" % (service.id,
                                                   service.environment)

    # Send HipChat notification
    notify_message = "Deployed <b>%s</b> with image <b>%s</b> to <b>%s</b> (%s)" % (
        service.id, service.image, service.environment,
        parsedMarathonUrl.netloc)
    if service.releaseNotes:
        notify_message += service.releaseNotes

    hipchat = HipChat(util.rget(service.document, 'hipchat', 'token'),
                      util.rget(service.document, 'hipchat', 'url'),
                      util.rget(service.document, 'hipchat', 'rooms'))
    hipchat.notify(notify_message)

    # Send NewRelic deployment notification
    newrelic = NewRelic(util.rget(service.document, 'newrelic', 'token'))
    newrelic.notify(util.rget(service.config, 'env', 'NEW_RELIC_APP_NAME'),
                    service.uniqueVersion)

    # Send Datadog deployment notification
    datadog = Datadog(
        util.rget(service.document, 'datadog', 'token'),
        util.toList(util.rget(service.document, 'datadog', 'tags')))
    datadog.notify(
        aggregation_key="%s_%s" % (service.environment, service.id),
        title=title,
        message=
        "%%%%%% \n Lighter deployed **%s** with image **%s** to **%s** (%s) \n %%%%%%"
        % (service.id, service.image, service.environment,
           parsedMarathonUrl.netloc),
        tags=tags)

    # Send Graphite deployment notification
    prefix = (util.rget(service.document, 'graphite', 'prefix')
              or 'lighter').strip('.')
    metricname = '%s.%s.%s.deployments' % (
        prefix, service.environment, '.'.join(
            filter(bool, service.id.split('/'))))

    graphite = Graphite(
        util.rget(service.document, 'graphite', 'address'),
        util.rget(service.document, 'graphite', 'url'),
        util.toList(util.rget(service.document, 'graphite', 'tags')))
    graphite.notify(metricname=metricname,
                    title=title,
                    message="Lighter deployed %s with image %s to %s (%s)" %
                    (service.id, service.image, service.environment,
                     parsedMarathonUrl.netloc),
                    tags=tags)
Example #2
0
 def testNotify(self, mock_jsonRequest):
     HipChat(token='abc', rooms=['123', '123',
                                 '456']).notify("Test message")
     mock_jsonRequest.assert_any_call(
         'https://api.hipchat.com/v2/room/123/notification?auth_token=abc',
         data=ANY,
         method='POST')
     mock_jsonRequest.assert_any_call(
         'https://api.hipchat.com/v2/room/456/notification?auth_token=abc',
         data=ANY,
         method='POST')
     self.assertEquals(mock_jsonRequest.call_count, 2)
Example #3
0
def notify(targetMarathonUrl, service):
    parsedMarathonUrl = urlparse(targetMarathonUrl)
    tags = ["environment:%s" % service.environment, "service:%s" % service.id]
    title = "Deployed %s to the %s environment" % (service.id,
                                                   service.environment)

    # Send HipChat notification
    notify_message = "Deployed <b>%s</b> with image <b>%s</b> to <b>%s</b> (%s)" % (
        service.id, service.image, service.environment,
        parsedMarathonUrl.netloc)
    if service.releaseNotes:
        notify_message += service.releaseNotes

    hipchat = HipChat(util.rget(service.document, 'hipchat', 'token'),
                      util.rget(service.document, 'hipchat', 'url'),
                      util.rget(service.document, 'hipchat', 'rooms'))
    hipchat.notify(notify_message)

    # Send Slack notification
    notify_payload = {
        "title_link":
        targetMarathonUrl,
        "fields": [{
            "title": "Service",
            "value": service.id,
            "short": 'true'
        }, {
            "title": "Environment",
            "value": service.environment,
            "short": 'true'
        }, {
            "title": "Image",
            "value": service.image,
            "short": 'true'
        }],
        "ts":
        int(time.time())
    }

    if service.releaseNotes:
        notify_payload = util.merge({'text': service.releaseNotes},
                                    notify_payload)

    slack = Slack(util.rget(service.document, 'slack', 'token'),
                  util.rget(service.document, 'slack', 'url'),
                  util.rget(service.document, 'slack', 'channels'))
    slack.notify(notify_payload)

    # Send NewRelic deployment notification
    newrelic = NewRelic(util.rget(service.document, 'newrelic', 'token'))
    newrelic.notify(util.rget(service.config, 'env', 'NEW_RELIC_APP_NAME'),
                    service.uniqueVersion)

    # Send Datadog deployment notification
    datadog = Datadog(
        util.rget(service.document, 'datadog', 'token'),
        util.toList(util.rget(service.document, 'datadog', 'tags')))
    datadog.notify(
        aggregation_key="%s_%s" % (service.environment, service.id),
        title=title,
        message=
        "%%%%%% \n Lighter deployed **%s** with image **%s** to **%s** (%s) \n %%%%%%"
        % (service.id, service.image, service.environment,
           parsedMarathonUrl.netloc),
        tags=tags)

    # Send Graphite deployment notification
    prefix = (util.rget(service.document, 'graphite', 'prefix')
              or 'lighter').strip('.')
    metricname = '%s.%s.%s.deployments' % (
        prefix, service.environment, '.'.join(
            filter(bool, service.id.split('/'))))

    graphite = Graphite(
        util.rget(service.document, 'graphite', 'address'),
        util.rget(service.document, 'graphite', 'url'),
        util.toList(util.rget(service.document, 'graphite', 'tags')))
    graphite.notify(metricname=metricname,
                    title=title,
                    message="Lighter deployed %s with image %s to %s (%s)" %
                    (service.id, service.image, service.environment,
                     parsedMarathonUrl.netloc),
                    tags=tags)