blob: a83a4f02b908ec34a1714af08fccea23cfdb2f96 [file] [log] [blame]
Tomáš Peckaaae9fe32021-01-25 19:57:22 +01001#include <docopt.h>
2#include <spdlog/sinks/ansicolor_sink.h>
3#include <spdlog/spdlog.h>
Václav Kubernát7efd6d52021-11-09 01:31:11 +01004#include <sysrepo-cpp/Connection.hpp>
Tomáš Peckaaae9fe32021-01-25 19:57:22 +01005#include "VELIA_VERSION.h"
6#include "ietf-hardware/Factory.h"
7#include "ietf-hardware/IETFHardware.h"
8#include "ietf-hardware/sysrepo/Sysrepo.h"
9#include "utils/exceptions.h"
10#include "utils/journal.h"
Václav Kubernát6018f082021-02-11 01:32:18 +010011#include "utils/log.h"
Tomáš Peckaaae9fe32021-01-25 19:57:22 +010012#include "utils/log-init.h"
Tomáš Pecka41784702021-05-26 13:57:32 +020013#include "utils/sysrepo.h"
Tomáš Peckaaae9fe32021-01-25 19:57:22 +010014#include "utils/waitUntilSignalled.h"
15
Tomáš Peckaaae9fe32021-01-25 19:57:22 +010016static const char usage[] =
17 R"(Hardware monitoring via Sysrepo.
18
19Usage:
20 veliad-hardware
21 [--appliance=<Model>]
Tomáš Peckaaae9fe32021-01-25 19:57:22 +010022 [--sysrepo-log-level=<Level>]
23 [--hardware-log-level=<Level>]
24 veliad-hardware (-h | --help)
25 veliad-hardware --version
26
27Options:
28 -h --help Show this screen.
29 --version Show version.
30 --appliance=<Model> Initialize IETF Hardware and outputs for specific appliance.
Václav Kubernát5f57dec2021-02-11 02:02:46 +010031 --sysrepo-log-level=<N> Log level for the sysrepo library [default: 2]
Tomáš Peckaaae9fe32021-01-25 19:57:22 +010032 --hardware-log-level=<N> Log level for the hardware drivers [default: 3]
Václav Kubernát3da14672021-02-09 09:39:24 +010033 (0 -> critical, 1 -> error, 2 -> warning, 3 -> info,
34 4 -> debug, 5 -> trace)
Tomáš Peckaaae9fe32021-01-25 19:57:22 +010035)";
36
37int main(int argc, char* argv[])
38{
39 std::shared_ptr<spdlog::sinks::sink> loggingSink;
40 if (velia::utils::isJournaldActive()) {
41 loggingSink = velia::utils::create_journald_sink();
42 } else {
43 loggingSink = std::make_shared<spdlog::sinks::ansicolor_stderr_sink_mt>();
44 }
45
46 auto args = docopt::docopt(usage, {argv + 1, argv + argc}, true, "veliad-system " VELIA_VERSION, true);
47
48 velia::utils::initLogs(loggingSink);
Tomáš Pecka41784702021-05-26 13:57:32 +020049 velia::utils::initLogsSysrepo();
Tomáš Peckaaae9fe32021-01-25 19:57:22 +010050 spdlog::set_level(spdlog::level::info);
51
52 try {
Tomáš Peckaaae9fe32021-01-25 19:57:22 +010053 spdlog::get("sysrepo")->set_level(parseLogLevel("Sysrepo library", args["--sysrepo-log-level"]));
54 spdlog::get("hardware")->set_level(parseLogLevel("Hardware loggers", args["--hardware-log-level"]));
55
Václav Kubernát7efd6d52021-11-09 01:31:11 +010056 auto srConn = sysrepo::Connection{};
57 auto srSess = srConn.sessionStart();
Tomáš Peckaaae9fe32021-01-25 19:57:22 +010058
59 // initialize ietf-hardware
Tomáš Peckaaae9fe32021-01-25 19:57:22 +010060 std::shared_ptr<velia::ietf_hardware::IETFHardware> ietfHardware;
61 if (const auto& appliance = args["--appliance"]) {
62 ietfHardware = velia::ietf_hardware::create(appliance.asString());
63 } else {
64 ietfHardware = std::make_shared<velia::ietf_hardware::IETFHardware>();
65 }
66
Václav Kubernát7efd6d52021-11-09 01:31:11 +010067 auto sysrepoIETFHardware = velia::ietf_hardware::sysrepo::Sysrepo(srSess, ietfHardware);
Tomáš Peckaaae9fe32021-01-25 19:57:22 +010068
69 waitUntilSignaled();
70
71 return 0;
72 } catch (std::exception& e) {
73 velia::utils::fatalException(spdlog::get("main"), e, "main");
74 }
75}