| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #include "json-keys.h" |
| 4 | |
| 5 | // Static key name structures |
| 6 | static const JSON_KEY_NAMES json_short_keys = { |
| 7 | .selected = "sl", |
| 8 | .excluded = "ex", |
| 9 | .queried = "qr", |
| 10 | .failed = "fl", |
| 11 | .dimensions = "ds", |
| 12 | .instances = "is", |
| 13 | .contexts = "ctx", |
| 14 | .alerts = "al", |
| 15 | .statistics = "sts", |
| 16 | .name = "nm", |
| 17 | .hostname = "nm", |
| 18 | .node_id = "nd", |
| 19 | .value = "vl", |
| 20 | .label_values = "vl", |
| 21 | .machine_guid = "mg", |
| 22 | .agent_index = "ai", |
| 23 | .clear = "cl", |
| 24 | .warning = "wr", |
| 25 | .critical = "cr", |
| 26 | .error = "er", |
| 27 | .other = "ot", |
| 28 | .count = "cnt", |
| 29 | .volume = "vol", |
| 30 | .anomaly_rate = "arp", |
| 31 | .anomaly_count = "arc", |
| 32 | .contribution = "con", |
| 33 | .point_annotations = "pa", |
| 34 | .point_schema = "point", |
| 35 | .priority = "pri", |
| 36 | .update_every = "ue", |
| 37 | .tier = "tr", |
| 38 | .after = "af", |
| 39 | .before = "bf", |
| 40 | .status = "st", |
| 41 | .first_entry = "fe", |
| 42 | .last_entry = "le", |
| 43 | .node_index = "ni", |
| 44 | .units = "un", |
| 45 | .weight = "wg", |
| 46 | .summary = "sum", |
| 47 | .instances_count = "in", |
| 48 | .nodes_count = "nd", |
| 49 | .configurations_count = "cfg", |
| 50 | .instance_id = "ch", |
| 51 | .instance_name = "ch_n", |
| 52 | .family = "fami", |
| 53 | .context = "ctx", |
| 54 | |
| 55 | .alerts_index_id = "ati", |
| 56 | .alert_global_id = "gi", |
| 57 | .alert_name = "nm", |
| 58 | .last_transition_id = "tr_i", |
| 59 | .last_transition_value = "tr_v", |
| 60 | .last_transition_timestamp = "tr_t", |
| 61 | .last_updated_value = "v", |
| 62 | .last_updated_timestamp = "t", |
| 63 | |
| 64 | .classification = "cl", |
| 65 | .classifications = "cls", |
| 66 | .component = "cm", |
| 67 | .components = "cp", |
| 68 | .type = "tp", |
| 69 | .types = "ty", |
| 70 | .recipients = "to", |
| 71 | .source = "src", |
| 72 | .config_hash_id = "cfg", |
| 73 | }; |
| 74 | |
| 75 | static const JSON_KEY_NAMES json_long_keys = { |
| 76 | .selected = "selected", |
| 77 | .excluded = "excluded", |
| 78 | .queried = "queried", |
| 79 | .failed = "failed", |
| 80 | .dimensions = "dimensions", |
| 81 | .instances = "instances", |
| 82 | .contexts = "contexts", |
| 83 | .alerts = "alerts", |
| 84 | .statistics = "statistics", |
| 85 | .name = "name", |
| 86 | .hostname = "hostname", |
| 87 | .node_id = "node_id", |
| 88 | .value = "value", |
| 89 | .label_values = "label_values", |
| 90 | .machine_guid = "machine_guid", |
| 91 | .agent_index = "agents_array_index", |
| 92 | .clear = "clear", |
| 93 | .warning = "warning", |
| 94 | .critical = "critical", |
| 95 | .error = "error", |
| 96 | .other = "other", |
| 97 | .count = "count", |
| 98 | .volume = "volume", |
| 99 | .anomaly_rate = "anomaly_rate_percent", |
| 100 | .anomaly_count = "anomalous_points_count", |
| 101 | .contribution = "contribution_percent", |
| 102 | .point_annotations = "point_annotations_bitmap", |
| 103 | .point_schema = "point_schema", |
| 104 | .priority = "priority", |
| 105 | .update_every = "update_every", |
| 106 | .tier = "tier", |
| 107 | .after = "after", |
| 108 | .before = "before", |
| 109 | .status = "status", |
| 110 | .first_entry = "first_entry", |
| 111 | .last_entry = "last_entry", |
| 112 | .node_index = "nodes_array_index", |
| 113 | .units = "units", |
| 114 | .weight = "weight", |
| 115 | .summary = "summary", |
| 116 | .instances_count = "instances_count", |
| 117 | .nodes_count = "nodes_count", |
| 118 | .configurations_count = "configurations_count", |
| 119 | .instance_id = "instance_id", |
| 120 | .instance_name = "instance", |
| 121 | .family = "family", |
| 122 | .context = "context", |
| 123 | |
| 124 | .alerts_index_id = "alerts_array_index_id", |
| 125 | .alert_global_id = "global_id", |
| 126 | .alert_name = "alert", |
| 127 | .last_transition_id = "last_transition_id", |
| 128 | .last_transition_value = "last_transition_value", |
| 129 | .last_transition_timestamp = "last_transition_timestamp", |
| 130 | .last_updated_value = "last_updated_value", |
| 131 | .last_updated_timestamp = "last_updated_timestamp", |
| 132 | |
| 133 | .classification = "classification", |
| 134 | .classifications = "classifications", |
| 135 | .component = "component", |
| 136 | .components = "components", |
| 137 | .type = "type", |
| 138 | .types = "types", |
| 139 | .recipients = "recipients", |
| 140 | .source = "source", |
| 141 | .config_hash_id = "config_hash_id", |
| 142 | }; |
| 143 | |
| 144 | // Thread-local pointer to the current key names |
| 145 | __thread const JSON_KEY_NAMES *json_keys = &json_short_keys; |
| 146 | |
| 147 | void json_keys_init(JSON_KEYS_OPTIONS options) { |
| 148 | if(options & JSON_KEYS_OPTION_LONG_KEYS) |
| 149 | json_keys = &json_long_keys; |
| 150 | else |
| 151 | json_keys = &json_short_keys; |
| 152 | } |
| 153 | |
| 154 | void json_keys_reset(void) { |
| 155 | json_keys = &json_short_keys; |
| 156 | } |
| 157 | |
| 158 | bool json_keys_are_long(void) { |
| 159 | return json_keys == &json_long_keys; |
| 160 | } |