blob: 3b95bb0f8ed2b6e3eef0413d1c1490f726326130 [file] [log] [blame]
/*
* Copyright (C) 2024 CESNET, https://photonics.cesnet.cz/
*
* Written by Tomáš Pecka <tomas.pecka@cesnet.cz>
*
*/
#include "alarms.h"
AlarmWatcher::AlarmWatcher(sysrepo::Session& session)
: datastoreWatcher(session, "/ietf-alarms:alarms/alarm-inventory")
, rpcWatcher(session, "/sysrepo-ietf-alarms:create-or-update-alarm")
{
}
void AlarmWatcher::AlarmInventory::add(const std::string& alarmTypeId, const std::set<std::string>& resources, const std::set<std::string>& severities)
{
auto& alarm = inventory[alarmTypeId];
alarm.resources.insert(resources.begin(), resources.end());
alarm.severities.insert(severities.begin(), severities.end());
}
bool AlarmWatcher::AlarmInventory::contains(const std::string& alarmTypeId, const std::optional<std::string>& resource, const std::optional<std::string>& severity) const
{
if (auto it = inventory.find(alarmTypeId); it != inventory.end()) {
const auto& alarm = it->second;
if (resource && !alarm.resources.empty() && !alarm.resources.contains(*resource)) {
return false;
}
if (severity && *severity != "cleared" && !alarm.severities.empty() && !alarm.severities.contains(*severity)) {
return false;
}
}
return true;
}