def put(self, alert_rules_id): json_data = request.get_json(force=True) action = json_data['action'] if action['method'] == 'modify': statistical_period = action['param']['statistical_period'] # statistical_approach = action['param']['statistical_approach'] compute_mode = action['param']['compute_mode'] threshold_value = action['param']['threshold_value'] contact_groups = action['param']['contact_groups'] notify_type = action['param']['notify_type'] try: data_res = AlertManager.get_alert_rules(alert_rules_id) host_id = data_res['host_id'] port = data_res['port'] service = data_res['service'] monitor_items = data_res['monitor_items'] Ansible.check(MONITOR_SERVER) inv_file = Ansible.init_target_yaml(MONITOR_SERVER) instance = host_id + ":" + str(port) yml_file = Ansible.init_metrics_yaml(service, monitor_items, host_id, instance, threshold_value, statistical_period, compute_mode) Ansible.execute(yml_file, inv_file, alert_rules_id) data_res = AlertManager.update_alert_rules( alert_rules_id, statistical_period, compute_mode, threshold_value, contact_groups, notify_type) except Exception as e: raise Error(str(e)) elif action['method'] == 'disable': try: silence_time = action['param']['silence_time'] silence_time_hour = str(silence_time) + 'h' data_res = AlertManager.get_alert_rules(alert_rules_id) alert_name = data_res['service'] + '_' + data_res[ 'monitor_items'] + '_' + data_res['host_id'] + ':' + str( data_res['port']) AlertManager.disable_alert(alert_name, silence_time_hour) AlertRulesData.update_silence_time(alert_rules_id, int(silence_time)) except Exception as e: raise Error(str(e)) elif action['method'] == 'enable': data_res = AlertManager.get_alert_rules(alert_rules_id) alert_name = data_res['service'] + '_' + data_res[ 'monitor_items'] + '_' + data_res['host_id'] + ':' + str( data_res['port']) AlertManager.enable_alert(alert_name) AlertRulesData.update_silence_time(alert_rules_id, 0) return {'status': 'ok'}, 201
def put(self): json_data = request.get_json(force=True) host_id = json_data['id'] # need get from db port = 9100 service = json_data['service'] temp_name = json_data['name'] rules = json_data['rules'] contact_groups = json_data['contact_groups'] notify_type = json_data['notify_type'] for rule in rules: monitor_items = rule['monitor_items'] alert_rules = AlertManager.get_alert_rules_by_name(host_id, port, monitor_items) alert_rules_id = alert_rules[1] #default statistical_period = '5s' # default statistical_approach = 'max' compute_mode = rule['compute_mode'] threshold_value = rule['threshold_value'] silence_tage = rule['silence'] try: if silence_tage == 0: # running # update mysql data_res = AlertManager.update_alert_rules(alert_rules_id, statistical_period, compute_mode, threshold_value, ','.join(contact_groups), ','.join(notify_type), 0) Ansible.check(MONITOR_SERVER) inv_file = Ansible.init_target_yaml(MONITOR_SERVER) instance = host_id + ":" + str(port) yml_file = Ansible.init_metrics_yaml(service, monitor_items, host_id, instance, threshold_value, statistical_period, compute_mode) Ansible.execute(yml_file, inv_file, alert_rules_id) elif silence_tage == 1: silence_time = 2400 silence_time_hour = str(silence_time) + 'h' data_res = AlertManager.get_alert_rules(alert_rules_id) alert_name = data_res['service'] + '_' + data_res['monitor_items'] + '_' + data_res[ 'host_id'] + ':' + str(data_res['port']) AlertManager.disable_alert(alert_name, silence_time_hour) AlertRulesData.update_silence_time(alert_rules_id, int(silence_time)) elif silence_tage == 2: data_res = AlertManager.get_alert_rules(alert_rules_id) alert_name = data_res['service'] + '_' + data_res['monitor_items'] + '_' + data_res[ 'host_id'] + ':' + str(data_res['port']) AlertManager.enable_alert(alert_name) AlertRulesData.update_silence_time(alert_rules_id, 0) except Exception as e: raise Error(e) return {'status': 'ok'}, 201