Exemplo n.º 1
0
    def testNoGraphiteUrl(self, mock_jsonRequest):
        graphite = Graphite('', '')

        graphite.notify('lighter.myservice.deployments', 'Deployed myservice',
                        'Deployed myservice to production environment')

        self.assertEquals(mock_jsonRequest.call_count, 0)
Exemplo n.º 2
0
    def testNoGraphiteUrl(self, mock_jsonRequest):
        graphite = Graphite('', '')

        graphite.notify(
            'lighter.myservice.deployments',
            'Deployed myservice', 'Deployed myservice to production environment')

        self.assertEquals(mock_jsonRequest.call_count, 0)
Exemplo n.º 3
0
    def testNotify(self, mock_jsonRequest):
        graphite = Graphite('localhost:2003', 'http://localhost:80/')

        graphite.notify(
            'lighter.myservice.deployments',
            'Deployed myservice', 'Deployed myservice to production environment')
        graphite.notify(
            'lighter.myservice.deployments',
            'Deployed myservice', 'Deployed myservice to production environment', ['subsystem:something'])

        self.assertEquals(mock_jsonRequest.call_count, 2)
Exemplo n.º 4
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)
Exemplo n.º 5
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
    hipchat = HipChat(
        util.rget(service.document, 'hipchat', 'token'),
        util.rget(service.document, 'hipchat', 'url'),
        util.rget(service.document, 'hipchat', 'rooms'))
    hipchat.notify("Deployed <b>%s</b> with image <b>%s</b> to <b>%s</b> (%s)" %
                   (service.id, service.image, service.environment, parsedMarathonUrl.netloc))

    # 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)
Exemplo n.º 6
0
    def testNotify(self, mock_jsonRequest):
        graphite = Graphite('localhost:2003', 'http://localhost:80/')

        graphite.notify('lighter.myservice.deployments', 'Deployed myservice',
                        'Deployed myservice to production environment')
        graphite.notify('lighter.myservice.deployments', 'Deployed myservice',
                        'Deployed myservice to production environment',
                        ['subsystem:something'])

        self.assertEquals(mock_jsonRequest.call_count, 2)
Exemplo n.º 7
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)