health: populate alarms' alarm-inventory container

RFC 8632 says [1] that we MUST populate alarm inventory list with data
about all the alarms that can appear. We don't have many alarms in
velia yet, so this is quite straightforward.

[1] https://www.rfc-editor.org/rfc/rfc8632.html#page-16

Change-Id: Iae1c237cfc0cc54eff835a6c83962598e5bf96ac
diff --git a/src/health/alarms/alarms.cpp b/src/health/alarms/alarms.cpp
index e5c6e36..c47dd08 100644
--- a/src/health/alarms/alarms.cpp
+++ b/src/health/alarms/alarms.cpp
@@ -4,11 +4,15 @@
  * Written by Tomáš Pecka <tomas.pecka@fit.cvut.cz>
  *
  */
+#include <sysrepo-cpp/Enum.hpp>
 #include "alarms.h"
+#include "utils/UniqueResource.h"
+#include "utils/libyang.h"
 
 using namespace std::string_literals;
 
 namespace {
+const auto alarmInventory = "/ietf-alarms:alarms/alarm-inventory"s;
 const auto alarmRpc = "/sysrepo-ietf-alarms:create-or-update-alarm";
 }
 
@@ -25,4 +29,46 @@
 
     session.sendRPC(inputNode);
 }
+
+void createOrUpdateAlarmInventoryEntry(sysrepo::Session session, const std::string& alarmId, const std::optional<std::string>& alarmTypeQualifier, const std::vector<std::string>& severities, bool willClear, const std::string& description)
+{
+    const auto prefix = alarmInventory + "/alarm-type[alarm-type-id='" + alarmId + "'][alarm-type-qualifier='" + alarmTypeQualifier.value_or("") + "']";
+
+    sysrepo::Datastore originalDS;
+    auto restoreDatastore = make_unique_resource(
+        [&]() {
+            originalDS = session.activeDatastore();
+            session.switchDatastore(sysrepo::Datastore::Operational);
+        },
+        [&]() {
+            session.switchDatastore(originalDS);
+        });
+
+    session.setItem(prefix + "/will-clear", willClear ? "true" : "false");
+    session.setItem(prefix + "/description", description);
+
+    for (const auto& severity : severities) {
+        session.setItem(prefix + "/severity-level", severity);
+    }
+
+    session.applyChanges();
+}
+
+void addResourceToAlarmInventoryEntry(sysrepo::Session session, const std::string& alarmId, const std::optional<std::string>& alarmTypeQualifier, const std::string& resource)
+{
+    const auto prefix = alarmInventory + "/alarm-type[alarm-type-id='" + alarmId + "'][alarm-type-qualifier='" + alarmTypeQualifier.value_or("") + "']";
+
+    sysrepo::Datastore originalDS;
+    auto restoreDatastore = make_unique_resource(
+        [&]() {
+            originalDS = session.activeDatastore();
+            session.switchDatastore(sysrepo::Datastore::Operational);
+        },
+        [&]() {
+            session.switchDatastore(originalDS);
+        });
+
+    session.setItem(prefix + "/resource", resource);
+    session.applyChanges();
+}
 }