def process_message(self, message): (alarm_id, metrics, new_state, old_state, link, lifecycle_state, state_change_reason, sub_alarms_json_snake_case, tenant_id, time_stamp) = parse_alarm_state_hist_message(message) name = 'alarm_state_history' fields = [] fields.append('tenant_id=' + line_utils.escape_value(tenant_id)) fields.append('alarm_id=' + line_utils.escape_value(alarm_id)) fields.append( 'metrics=' + line_utils.escape_value(json.dumps(metrics, ensure_ascii=False))) fields.append('new_state=' + line_utils.escape_value(new_state)) fields.append('old_state=' + line_utils.escape_value(old_state)) fields.append('link=' + line_utils.escape_value(link)) fields.append('lifecycle_state=' + line_utils.escape_value(lifecycle_state)) fields.append('reason=' + line_utils.escape_value(state_change_reason)) fields.append('reason_data=' + line_utils.escape_value("{}")) fields.append('sub_alarms=' + line_utils.escape_value(sub_alarms_json_snake_case)) line = name + ',tenant_id=' + line_utils.escape_tag(tenant_id) line += ' ' + ','.join(fields) line += ' ' + str(int(time_stamp)) LOG.debug(line) return line, tenant_id
def process_message(self, message): (alarm_id, metrics, new_state, old_state, link, lifecycle_state, state_change_reason, sub_alarms_json_snake_case, tenant_id, time_stamp) = parse_alarm_state_hist_message( message) name = u'alarm_state_history' fields = [] fields.append(u'tenant_id=' + line_utils.escape_value(tenant_id)) fields.append(u'alarm_id=' + line_utils.escape_value(alarm_id)) fields.append(u'metrics=' + line_utils.escape_value( json.dumps(metrics, ensure_ascii=False))) fields.append(u'new_state=' + line_utils.escape_value(new_state)) fields.append(u'old_state=' + line_utils.escape_value(old_state)) fields.append(u'link=' + line_utils.escape_value(link)) fields.append(u'lifecycle_state=' + line_utils.escape_value( lifecycle_state)) fields.append(u'reason=' + line_utils.escape_value( state_change_reason)) fields.append(u'reason_data=' + line_utils.escape_value("{}")) fields.append(u'sub_alarms=' + line_utils.escape_value( sub_alarms_json_snake_case)) line = name + u',tenant_id=' + line_utils.escape_tag(tenant_id) line += u' ' + u','.join(fields) line += u' ' + str(int(time_stamp)) LOG.debug(line) return line
def process_message(message): (dimensions, metric_name, region, tenant_id, time_stamp, value, value_meta) = parse_measurement_message(message) tags = dimensions tags[u'_tenant_id'] = tenant_id tags[u'_region'] = region if not value_meta: value_meta_str = u'"{}"' else: value_meta_str = line_utils.escape_value(json.dumps(value_meta, ensure_ascii=False)) key_values = [line_utils.escape_tag(metric_name)] # tags should be sorted client-side to take load off server for key in sorted(tags.keys()): key_tag = line_utils.escape_tag(key) value_tag = line_utils.escape_tag(tags[key]) key_values.append(key_tag + u'=' + value_tag) key_values = u','.join(key_values) value_field = u'value={}'.format(value) value_meta_field = u'value_meta=' + value_meta_str data = key_values + u' ' + value_field + u',' + \ value_meta_field + u' ' + str(int(time_stamp)) LOG.debug(data) return data
def process_message(self, message): (dimensions, metric_name, region, tenant_id, time_stamp, value, value_meta) = parse_measurement_message(message) tags = dimensions tags[u'_tenant_id'] = tenant_id tags[u'_region'] = region if not value_meta: value_meta_str = u'"{}"' else: value_meta_str = line_utils.escape_value( json.dumps(value_meta, ensure_ascii=False)) key_values = [line_utils.escape_tag(metric_name)] # tags should be sorted client-side to take load off server for key in sorted(tags.keys()): key_tag = line_utils.escape_tag(key) value_tag = line_utils.escape_tag(tags[key]) key_values.append(key_tag + u'=' + value_tag) key_values = u','.join(key_values) value_field = u'value={}'.format(value) value_meta_field = u'value_meta=' + value_meta_str data = key_values + u' ' + value_field + u',' + value_meta_field + u' ' + str( int(time_stamp)) LOG.debug(data) return data
def test_line_utils_escape_value(self): simple = u"aaaaa" self.assertEqual(u'"' + simple + u'"', line_utils.escape_value(simple)) complex = u"a\\b\"\n" self.assertEqual(u"\"a\\\\b\\\"\\n\"", line_utils.escape_value(complex))
def test_line_utils_handles_utf8(self): utf8_name = u'name' self.assertEqual(u'"' + utf8_name + u'"', line_utils.escape_value(utf8_name)) self.assertEqual(utf8_name, line_utils.escape_tag(utf8_name))