Tomáš Pecka | 6a2334b | 2022-07-12 13:57:54 +0200 | [diff] [blame] | 1 | /* |
| 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áš Pecka | 0f8f15b | 2023-05-17 20:00:48 +0200 | [diff] [blame^] | 10 | #include <mutex> |
Tomáš Pecka | 6a2334b | 2022-07-12 13:57:54 +0200 | [diff] [blame] | 11 | #include <sdbus-c++/sdbus-c++.h> |
| 12 | #include <set> |
| 13 | #include <sysrepo-cpp/Session.hpp> |
| 14 | #include "utils/log-fwd.h" |
| 15 | |
| 16 | namespace velia::health { |
| 17 | |
| 18 | /** @brief Watches for systemd units state via DBus and reports their state changes via ietf-alarms */ |
| 19 | class SystemdUnits { |
| 20 | public: |
| 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 | |
| 25 | private: |
| 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áš Pecka | 0f8f15b | 2023-05-17 20:00:48 +0200 | [diff] [blame^] | 34 | std::mutex m_mtx; |
| 35 | |
Tomáš Pecka | 6a2334b | 2022-07-12 13:57:54 +0200 | [diff] [blame] | 36 | /** 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áš Pecka | 0e87484 | 2023-05-18 09:28:49 +0200 | [diff] [blame] | 42 | void registerSystemdUnit(sdbus::IConnection& connection, const std::string& unitName, const sdbus::ObjectPath& unitObjectPath); |
Tomáš Pecka | 6a2334b | 2022-07-12 13:57:54 +0200 | [diff] [blame] | 43 | void onUnitStateChange(const std::string& name, const std::string& activeState, const std::string& nSubState); |
| 44 | }; |
| 45 | |
| 46 | } |