def testNoID(self, mock_jsonRequest): Datadog('abc').notify(title='test title', message='test message', aggregation_key='', tags=['environment:test'], priority='normal', alert_type='info') self.assertEquals(mock_jsonRequest.call_count, 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)
def testNotify(self, mock_jsonRequest): Datadog('abc').notify(title='test title', message='test message', aggregation_key='/jenkins/test', tags=['environment:test'], priority='normal', alert_type='info') self.assertEquals(mock_jsonRequest.call_count, 2) mock_jsonRequest.assert_any_call( 'https://app.datadoghq.com/api/v1/events?api_key=abc', data=ANY, method='POST') mock_jsonRequest.assert_any_call( 'https://app.datadoghq.com/api/v1/series?api_key=abc', data=ANY, method='POST')
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)