diff options
author | Timotej S <6674623+underhood@users.noreply.github.com> | 2021-10-15 12:48:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-15 12:48:03 +0200 |
commit | 81e23e71ceeca221342f382576f58a8d45163474 (patch) | |
tree | 76e541de0f093049144a39bc561896b34fbc50c0 /aclk/schema-wrappers | |
parent | 83d32780f683b03e73a618e27f1cffa6efae278d (diff) |
Adds new alarm status protocol messages (#11612)
Adds new message parsers and generators for the Alarm Snapshot messages
Diffstat (limited to 'aclk/schema-wrappers')
-rw-r--r-- | aclk/schema-wrappers/alarm_config.cc | 2 | ||||
-rw-r--r-- | aclk/schema-wrappers/alarm_stream.cc | 186 | ||||
-rw-r--r-- | aclk/schema-wrappers/alarm_stream.h | 24 |
3 files changed, 154 insertions, 58 deletions
diff --git a/aclk/schema-wrappers/alarm_config.cc b/aclk/schema-wrappers/alarm_config.cc index e6c9e9974e..56d7e6f39f 100644 --- a/aclk/schema-wrappers/alarm_config.cc +++ b/aclk/schema-wrappers/alarm_config.cc @@ -8,7 +8,7 @@ #include "schema_wrapper_utils.h" -using namespace alarmconfig::v1; +using namespace alarms::v1; void destroy_aclk_alarm_configuration(struct aclk_alarm_configuration *cfg) { diff --git a/aclk/schema-wrappers/alarm_stream.cc b/aclk/schema-wrappers/alarm_stream.cc index 98d9d842c8..5868e5d679 100644 --- a/aclk/schema-wrappers/alarm_stream.cc +++ b/aclk/schema-wrappers/alarm_stream.cc @@ -8,12 +8,14 @@ #include "schema_wrapper_utils.h" +using namespace alarms::v1; + struct start_alarm_streaming parse_start_alarm_streaming(const char *data, size_t len) { struct start_alarm_streaming ret; memset(&ret, 0, sizeof(ret)); - alarmstream::v1::StartAlarmStreaming msg; + StartAlarmStreaming msg; if (!msg.ParseFromArray(data, len)) return ret; @@ -27,7 +29,7 @@ struct start_alarm_streaming parse_start_alarm_streaming(const char *data, size_ char *parse_send_alarm_log_health(const char *data, size_t len) { - alarmstream::v1::SendAlarmLogHealth msg; + SendAlarmLogHealth msg; if (!msg.ParseFromArray(data, len)) return NULL; return strdupz(msg.node_id().c_str()); @@ -35,22 +37,22 @@ char *parse_send_alarm_log_health(const char *data, size_t len) char *generate_alarm_log_health(size_t *len, struct alarm_log_health *data) { - alarmstream::v1::AlarmLogHealth msg; - alarmstream::v1::LogEntries *entries; + AlarmLogHealth msg; + LogEntries *entries; msg.set_claim_id(data->claim_id); msg.set_node_id(data->node_id); msg.set_enabled(data->enabled); switch (data->status) { - case ALARM_LOG_STATUS_IDLE: - msg.set_status(alarmstream::v1::ALARM_LOG_STATUS_IDLE); + case alarm_log_status_aclk::ALARM_LOG_STATUS_IDLE: + msg.set_status(alarms::v1::ALARM_LOG_STATUS_IDLE); break; - case ALARM_LOG_STATUS_RUNNING: - msg.set_status(alarmstream::v1::ALARM_LOG_STATUS_RUNNING); + case alarm_log_status_aclk::ALARM_LOG_STATUS_RUNNING: + msg.set_status(alarms::v1::ALARM_LOG_STATUS_RUNNING); break; - case ALARM_LOG_STATUS_UNSPECIFIED: - msg.set_status(alarmstream::v1::ALARM_LOG_STATUS_UNSPECIFIED); + case alarm_log_status_aclk::ALARM_LOG_STATUS_UNSPECIFIED: + msg.set_status(alarms::v1::ALARM_LOG_STATUS_UNSPECIFIED); break; default: error("Unknown status of AlarmLogHealth LogEntry"); @@ -72,26 +74,26 @@ char *generate_alarm_log_health(size_t *len, struct alarm_log_health *data) return bin; } -static alarmstream::v1::AlarmStatus aclk_alarm_status_to_proto(enum aclk_alarm_status status) +static alarms::v1::AlarmStatus aclk_alarm_status_to_proto(enum aclk_alarm_status status) { switch (status) { - case ALARM_STATUS_NULL: - return alarmstream::v1::ALARM_STATUS_NULL; - case ALARM_STATUS_UNKNOWN: - return alarmstream::v1::ALARM_STATUS_UNKNOWN; - case ALARM_STATUS_REMOVED: - return alarmstream::v1::ALARM_STATUS_REMOVED; - case ALARM_STATUS_NOT_A_NUMBER: - return alarmstream::v1::ALARM_STATUS_NOT_A_NUMBER; - case ALARM_STATUS_CLEAR: - return alarmstream::v1::ALARM_STATUS_CLEAR; - case ALARM_STATUS_WARNING: - return alarmstream::v1::ALARM_STATUS_WARNING; - case ALARM_STATUS_CRITICAL: - return alarmstream::v1::ALARM_STATUS_CRITICAL; + case aclk_alarm_status::ALARM_STATUS_NULL: + return alarms::v1::ALARM_STATUS_NULL; + case aclk_alarm_status::ALARM_STATUS_UNKNOWN: + return alarms::v1::ALARM_STATUS_UNKNOWN; + case aclk_alarm_status::ALARM_STATUS_REMOVED: + return alarms::v1::ALARM_STATUS_REMOVED; + case aclk_alarm_status::ALARM_STATUS_NOT_A_NUMBER: + return alarms::v1::ALARM_STATUS_NOT_A_NUMBER; + case aclk_alarm_status::ALARM_STATUS_CLEAR: + return alarms::v1::ALARM_STATUS_CLEAR; + case aclk_alarm_status::ALARM_STATUS_WARNING: + return alarms::v1::ALARM_STATUS_WARNING; + case aclk_alarm_status::ALARM_STATUS_CRITICAL: + return alarms::v1::ALARM_STATUS_CRITICAL; default: error("Unknown alarm status"); - return alarmstream::v1::ALARM_STATUS_UNKNOWN; + return alarms::v1::ALARM_STATUS_UNKNOWN; } } @@ -118,54 +120,59 @@ void destroy_alarm_log_entry(struct alarm_log_entry *entry) freez(entry->rendered_info); } -char *generate_alarm_log_entry(size_t *len, struct alarm_log_entry *data) +static void fill_alarm_log_entry(struct alarm_log_entry *data, AlarmLogEntry *proto) { - alarmstream::v1::AlarmLogEntry le; - - le.set_node_id(data->node_id); - le.set_claim_id(data->claim_id); + proto->set_node_id(data->node_id); + proto->set_claim_id(data->claim_id); - le.set_chart(data->chart); - le.set_name(data->name); + proto->set_chart(data->chart); + proto->set_name(data->name); if (data->family) - le.set_family(data->family); + proto->set_family(data->family); - le.set_batch_id(data->batch_id); - le.set_sequence_id(data->sequence_id); - le.set_when(data->when); + proto->set_batch_id(data->batch_id); + proto->set_sequence_id(data->sequence_id); + proto->set_when(data->when); - le.set_config_hash(data->config_hash); + proto->set_config_hash(data->config_hash); - le.set_utc_offset(data->utc_offset); - le.set_timezone(data->timezone); + proto->set_utc_offset(data->utc_offset); + proto->set_timezone(data->timezone); - le.set_exec_path(data->exec_path); - le.set_conf_source(data->conf_source); - le.set_command(data->command); + proto->set_exec_path(data->exec_path); + proto->set_conf_source(data->conf_source); + proto->set_command(data->command); - le.set_duration(data->duration); - le.set_non_clear_duration(data->non_clear_duration); + proto->set_duration(data->duration); + proto->set_non_clear_duration(data->non_clear_duration); - le.set_status(aclk_alarm_status_to_proto(data->status)); - le.set_old_status(aclk_alarm_status_to_proto(data->old_status)); - le.set_delay(data->delay); - le.set_delay_up_to_timestamp(data->delay_up_to_timestamp); + proto->set_status(aclk_alarm_status_to_proto(data->status)); + proto->set_old_status(aclk_alarm_status_to_proto(data->old_status)); + proto->set_delay(data->delay); + proto->set_delay_up_to_timestamp(data->delay_up_to_timestamp); - le.set_last_repeat(data->last_repeat); - le.set_silenced(data->silenced); + proto->set_last_repeat(data->last_repeat); + proto->set_silenced(data->silenced); if (data->value_string) - le.set_value_string(data->value_string); + proto->set_value_string(data->value_string); if (data->old_value_string) - le.set_old_value_string(data->old_value_string); + proto->set_old_value_string(data->old_value_string); + + proto->set_value(data->value); + proto->set_old_value(data->old_value); + + proto->set_updated(data->updated); - le.set_value(data->value); - le.set_old_value(data->old_value); + proto->set_rendered_info(data->rendered_info); +} - le.set_updated(data->updated); +char *generate_alarm_log_entry(size_t *len, struct alarm_log_entry *data) +{ + AlarmLogEntry le; - le.set_rendered_info(data->rendered_info); + fill_alarm_log_entry(data, &le); *len = PROTO_COMPAT_MSG_SIZE(le); char *bin = (char*)mallocz(*len); @@ -174,3 +181,68 @@ char *generate_alarm_log_entry(size_t *len, struct alarm_log_entry *data) return bin; } + +struct send_alarm_snapshot *parse_send_alarm_snapshot(const char *data, size_t len) +{ + SendAlarmSnapshot msg; + if (!msg.ParseFromArray(data, len)) + return NULL; + + struct send_alarm_snapshot *ret = (struct send_alarm_snapshot*)callocz(1, sizeof(struct send_alarm_snapshot)); + if (msg.claim_id().c_str()) + ret->claim_id = strdupz(msg.claim_id().c_str()); + if (msg.node_id().c_str()) + ret->node_id = strdupz(msg.node_id().c_str()); + ret->snapshot_id = msg.snapshot_id(); + ret->sequence_id = msg.sequence_id(); + + return ret; +} + +void destroy_send_alarm_snapshot(struct send_alarm_snapshot *ptr) +{ + freez(ptr->claim_id); + freez(ptr->node_id); + freez(ptr); +} + +alarm_snapshot_proto_ptr_t generate_alarm_snapshot_proto(struct alarm_snapshot *data) +{ + AlarmSnapshot *msg = new AlarmSnapshot; + if (unlikely(!msg)) fatal("Cannot allocate memory for AlarmSnapshot"); + + msg->set_node_id(data->node_id); + msg->set_claim_id(data->claim_id); + msg->set_snapshot_id(data->snapshot_id); + msg->set_chunks(data->chunks); + msg->set_chunk(data->chunk); + + // this is handled automatically by add_alarm_log_entry2snapshot function + msg->set_chunk_size(0); + + return msg; +} + +void add_alarm_log_entry2snapshot(alarm_snapshot_proto_ptr_t snapshot, struct alarm_log_entry *data) +{ + AlarmSnapshot *alarm_snapshot = (AlarmSnapshot *)snapshot; + AlarmLogEntry *alarm_log_entry = alarm_snapshot->add_alarms(); + + fill_alarm_log_entry(data, alarm_log_entry); + + alarm_snapshot->set_chunk_size(alarm_snapshot->chunk_size() + 1); +} + +char *generate_alarm_snapshot_bin(size_t *len, alarm_snapshot_proto_ptr_t snapshot) +{ + AlarmSnapshot *alarm_snapshot = (AlarmSnapshot *)snapshot; + *len = PROTO_COMPAT_MSG_SIZE_PTR(alarm_snapshot); + char *bin = (char*)mallocz(*len); + if (!alarm_snapshot->SerializeToArray(bin, *len)) { + delete alarm_snapshot; + return NULL; + } + + delete alarm_snapshot; + return bin; +} diff --git a/aclk/schema-wrappers/alarm_stream.h b/aclk/schema-wrappers/alarm_stream.h index a81834149a..2932bb192f 100644 --- a/aclk/schema-wrappers/alarm_stream.h +++ b/aclk/schema-wrappers/alarm_stream.h @@ -99,10 +99,34 @@ struct alarm_log_entry { char *rendered_info; }; +struct send_alarm_snapshot { + char *node_id; + char *claim_id; + uint64_t snapshot_id; + uint64_t sequence_id; +}; + +struct alarm_snapshot { + char *node_id; + char *claim_id; + uint64_t snapshot_id; + uint32_t chunks; + uint32_t chunk; +}; + +typedef void* alarm_snapshot_proto_ptr_t; + void destroy_alarm_log_entry(struct alarm_log_entry *entry); char *generate_alarm_log_entry(size_t *len, struct alarm_log_entry *data); +struct send_alarm_snapshot *parse_send_alarm_snapshot(const char *data, size_t len); +void destroy_send_alarm_snapshot(struct send_alarm_snapshot *ptr); + +alarm_snapshot_proto_ptr_t generate_alarm_snapshot_proto(struct alarm_snapshot *data); +void add_alarm_log_entry2snapshot(alarm_snapshot_proto_ptr_t snapshot, struct alarm_log_entry *data); +char *generate_alarm_snapshot_bin(size_t *len, alarm_snapshot_proto_ptr_t snapshot); + #ifdef __cplusplus } #endif |