blob: ed9c82aca54cb47149581e643ecc880ad7b12853 [file] [log] [blame]
Tomáš Pecka6a2334b2022-07-12 13:57:54 +02001/*
2 * Copyright (C) 2020 - 2022 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Tomáš Pecka <tomas.pecka@fit.cvut.cz>
5 *
6 */
7#pragma once
8
9#include <memory>
Tomáš Pecka0f8f15b2023-05-17 20:00:48 +020010#include <mutex>
Tomáš Pecka6a2334b2022-07-12 13:57:54 +020011#include <sdbus-c++/sdbus-c++.h>
12#include <set>
13#include <sysrepo-cpp/Session.hpp>
14#include "utils/log-fwd.h"
15
16namespace velia::health {
17
18/** @brief Watches for systemd units state via DBus and reports their state changes via ietf-alarms */
19class SystemdUnits {
20public:
21 SystemdUnits(sysrepo::Session session, sdbus::IConnection& connection);
22 SystemdUnits(sysrepo::Session session, sdbus::IConnection& connection, const std::string& busname, const std::string& managerObjectPath, const std::string& managerIface, const std::string& unitIface);
23 ~SystemdUnits();
24
25private:
26 velia::Log m_log;
27
28 sysrepo::Session m_srSession;
29
30 std::string m_busName;
31 std::string m_unitIface;
32 std::unique_ptr<sdbus::IProxy> m_proxyManager;
33
Tomáš Pecka0f8f15b2023-05-17 20:00:48 +020034 std::mutex m_mtx;
35
Tomáš Pecka6a2334b2022-07-12 13:57:54 +020036 /** List of registered unit watchers */
37 std::map<sdbus::ObjectPath, std::unique_ptr<sdbus::IProxy>> m_proxyUnits;
38
39 /** Current unit state. */
40 std::map<std::string, std::pair<std::string, std::string>> m_unitState;
41
Tomáš Pecka0e874842023-05-18 09:28:49 +020042 void registerSystemdUnit(sdbus::IConnection& connection, const std::string& unitName, const sdbus::ObjectPath& unitObjectPath);
Tomáš Pecka6a2334b2022-07-12 13:57:54 +020043 void onUnitStateChange(const std::string& name, const std::string& activeState, const std::string& nSubState);
44};
45
46}