This commit does the following:
- Add a new option "keep_existing_alarm" when creating an alarm so,
if said alarm already exists, it won't be updated.
- Add a new method to clear alarms from a list. The input is a list
with each element being a tuple consisted of alarm_id and
entity_instance_id.
- Modified the existing method that created alarms from a list.
Previously, the client would loop through the list of alarms and send
requests to FM API. Now, alarms from the list are converted into
a vector of structs and passed to FM API in a single request.
Test plan (using FaultAPIsV2):
- PASS: Build package and install.
- PASS: Create a new alarm with keep_existing_alarm=True and verify
a new alarm was created.
- PASS: Create an existing alarm with keep_existing_alarm=True and
verify the original alarm was kept and the returned UUID
is correct.
- PASS: Create an existing alarm without keep_existing_alarm and
verify the original alarm was updated and the returned UUID
is correct.
- PASS: Create a list of alarms and verify they were correctly
created and it was faster than previous method.
- PASS: Clear a list of alarms that exist and verify they were
successfully cleared.
- PASS: Clear a list of alarms that don't exist and verify the API
didn't raise any errors.
- PASS: Stop pmond process and verify mtce raises the correct
200.006 alarm only once. Restart pmond and verify the alarm
is cleared.
Story: 2011311
Task: 52166
Change-Id: I2f901c4726c24f3522a8c5bae1d7d9b03ef24ce0
Signed-off-by: Victor Romano <victor.gluzromano@windriver.com>
109 lines
2.9 KiB
C++
109 lines
2.9 KiB
C++
//
|
|
// Copyright (c) 2014, 2025 Wind River Systems, Inc.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
|
|
#ifndef FMALARMUTILS_H_
|
|
#define FMALARMUTILS_H_
|
|
|
|
#include "fmAPI.h"
|
|
#include "fmMsg.h"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
enum EFmAlarmIndexMap {
|
|
FM_ALM_IX_UUID=0,
|
|
FM_ALM_IX_ALARM_ID,
|
|
FM_ALM_IX_ALARM_STATE,
|
|
FM_ALM_IX_ENTITY_ID,
|
|
FM_ALM_IX_INSTANCE_ID,
|
|
FM_ALM_IX_TIMESTAMP,
|
|
FM_ALM_IX_SEVERITY,
|
|
FM_ALM_IX_REASON,
|
|
FM_ALM_IX_ALARM_TYPE,
|
|
FM_ALM_IX_PROBABLE_CAUSE,
|
|
FM_ALM_IX_REPAIR_ACTION,
|
|
FM_ALM_IX_SERVICE_AFFECT,
|
|
FM_ALM_IX_SUPPRESSION,
|
|
FM_ALM_IX_INHIBIT_ALARM,
|
|
FM_ALM_IX_KEEP_EXISTING_ALARM,
|
|
FM_ALM_IX_MAX
|
|
};
|
|
|
|
enum EFmLogIndexMap {
|
|
FM_LOG_IX_UUID=0,
|
|
FM_LOG_IX_LOG_ID,
|
|
FM_LOG_IX_ENTITY_ID,
|
|
FM_LOG_IX_INSTANCE_ID,
|
|
FM_LOG_IX_TIMESTAMP,
|
|
FM_LOG_IX_SEVERITY,
|
|
FM_LOG_IX_REASON,
|
|
FM_LOG_IX_LOG_TYPE,
|
|
FM_LOG_IX_PROBABLE_CAUSE,
|
|
FM_LOG_IX_SERVICE_AFFECT,
|
|
FM_LOG_IX_MAX
|
|
};
|
|
|
|
enum EFmEventLogIndexMap {
|
|
FM_EVENT_LOG_IX_UUID=0,
|
|
FM_EVENT_LOG_IX_EVENT_ID,
|
|
FM_EVENT_LOG_IX_STATE,
|
|
FM_EVENT_LOG_IX_ENTITY_ID,
|
|
FM_EVENT_LOG_IX_INSTANCE_ID,
|
|
FM_EVENT_LOG_IX_TIMESTAMP,
|
|
FM_EVENT_LOG_IX_SEVERITY,
|
|
FM_EVENT_LOG_IX_REASON,
|
|
FM_EVENT_LOG_IX_EVENT_TYPE,
|
|
FM_EVENT_LOG_IX_PROBABLE_CAUSE,
|
|
FM_EVENT_LOG_IX_REPAIR_ACTION,
|
|
FM_EVENT_LOG_IX_SERVICE_AFFECT,
|
|
FM_EVENT_LOG_IX_SUPPRESSION,
|
|
FM_EVENT_LOG_IX_MAX
|
|
};
|
|
|
|
|
|
bool fm_alarm_set_field(EFmAlarmIndexMap field, SFmAlarmDataT *a,
|
|
std::string &val);
|
|
bool fm_alarm_get_field(EFmAlarmIndexMap field, const SFmAlarmDataT *a,
|
|
std::string &val);
|
|
bool fm_log_set_field(EFmLogIndexMap field, SFmAlarmDataT *a,
|
|
std::string &val);
|
|
bool fm_event_log_set_field(EFmEventLogIndexMap field, SFmAlarmDataT *a,
|
|
std::string &val);
|
|
void fm_formatted_str_to_vector(const std::string &s,
|
|
std::vector<std::string> &alarm);
|
|
bool fm_alarm_to_string(const SFmAlarmDataT *alarm,
|
|
std::string &str);
|
|
bool fm_alarm_from_string(const std::string &str,
|
|
SFmAlarmDataT *alarm);
|
|
|
|
/**
|
|
* This will create an alarm list from an alarm - will translate to string.
|
|
* The indexes of this API are based on EFmAlarmIndexMap
|
|
*/
|
|
void fm_alarm_to_list(const SFmAlarmDataT *a,
|
|
std::vector<std::string> &list);
|
|
bool fm_alarm_filter_to_string(const AlarmFilter *alarm,
|
|
std::string &str);
|
|
bool fm_alarm_filter_from_string(const std::string &str,
|
|
AlarmFilter *alarm);
|
|
|
|
/**
|
|
* Generate a FM UUID
|
|
*/
|
|
void fm_uuid_create(fm_uuid_t &uuid);
|
|
|
|
/**
|
|
* General utilities to conver alarm fields to and from strings
|
|
*/
|
|
EFmErrorT fm_error_from_string(const std::string &str);
|
|
std::string fm_error_from_int(EFmErrorT id);
|
|
|
|
void fm_log_request(fm_buff_t &req, bool failed=false);
|
|
void fm_log_response(fm_buff_t &req, fm_buff_t &resp, bool failed=false);
|
|
|
|
#endif /* FMALARMUTILS_H_ */
|