def create_alert(opsgenie_api_key, environment, deploy, queue_name, threshold, info, dev_test_mode=None): assert isinstance(dev_test_mode, bool) configuration.api_key['Authorization'] = opsgenie_api_key configuration.api_key_prefix['Authorization'] = 'GenieKey' alert_msg = generate_alert_message(environment, deploy, queue_name, threshold) alias = generate_alert_alias(environment, deploy, queue_name) if dev_test_mode: print(("Test Mode: would have created Alert: {}".format(alias))) else: print(("Creating Alert: {}".format(alias))) response = AlertApi().create_alert(body=CreateAlertRequest( message=alert_msg, alias=alias, description=info)) print(('request id: {}'.format(response.request_id))) print(('took: {}'.format(response.took))) print(('result: {}'.format(response.result)))
def create_alert(opsgenie_api_key, environment, deploy, queue_name, threshold, info): configuration.api_key['Authorization'] = opsgenie_api_key configuration.api_key_prefix['Authorization'] = 'GenieKey' alert_message = generate_alert_message(environment, deploy, queue_name, threshold) alias = generate_alert_alias(environment, deploy, queue_name) print("Creating Alert: {}".format(alias)) response = AlertApi().create_alert(body=CreateAlertRequest(message=alert_message, alias=alias, description=info)) print('request id: {}'.format(response.request_id)) print('took: {}'.format(response.took)) print('result: {}'.format(response.result))
def handle_alert_creation( key, note_created, action_list, desc, alert_source, msg, priority, teams_list, tags_list, alias, owner, entity_value, host_url, ): configure_authorization(key, host_url) body = CreateAlertRequest( note=note_created, actions=action_list, description=desc, source=alert_source, message=msg, priority=priority, teams=teams_list, tags=tags_list, alias=alias, user=owner, entity=entity_value, ) try: response = AlertApi().create_alert(body=body) sys.stdout.write('Request id: %s, successfully created alert.\n' % response.request_id) return 0 except ApiException as err: sys.stderr.write( 'Exception when calling AlertApi->create_alert: %s\n' % err) return 2
def _send_alert(message, priority, details=None): if this.is_enabled is False: return None return AlertApi().create_alert(body=CreateAlertRequest( message=message, priority=priority, details=details))