blob: d5e7a38b902be42ada2e8f71b2c4dcfa38f1d8e0 [file] [log] [blame]
Andrew Geisslere426b582020-05-28 12:40:55 -05001#include "systemd_target_parser.hpp"
2#include "systemd_target_signal.hpp"
3
Andrew Geissleree3a2c82019-07-30 15:16:20 -05004#include <CLI/CLI.hpp>
Andrew Geissleree3a2c82019-07-30 15:16:20 -05005#include <phosphor-logging/log.hpp>
Andrew Geissler891213b2019-07-30 14:08:17 -05006#include <sdbusplus/bus.hpp>
7#include <sdeventplus/event.hpp>
Andrew Geisslere426b582020-05-28 12:40:55 -05008
9#include <iostream>
Andrew Geissleree3a2c82019-07-30 15:16:20 -050010#include <vector>
11
12using phosphor::logging::level;
13using phosphor::logging::log;
14
Andrew Geissler693eaed2019-08-02 14:12:28 -050015bool gVerbose = false;
16
17void dump_targets(const TargetErrorData& targetData)
18{
19 std::cout << "## Data Structure of Json ##" << std::endl;
20 for (const auto& [target, value] : targetData)
21 {
22 std::cout << target << " " << value.errorToLog << std::endl;
23 std::cout << " ";
24 for (auto& eToMonitor : value.errorsToMonitor)
25 {
26 std::cout << eToMonitor << ", ";
27 }
28 std::cout << std::endl;
29 }
30 std::cout << std::endl;
31}
32
Andrew Geissleree3a2c82019-07-30 15:16:20 -050033void print_usage(void)
34{
35 std::cout << "[-f <file1> -f <file2> ...] : Full path to json file(s) with "
36 "target/error mappings"
37 << std::endl;
38 return;
39}
Andrew Geissler891213b2019-07-30 14:08:17 -050040
41int main(int argc, char* argv[])
42{
43 auto bus = sdbusplus::bus::new_default();
44 auto event = sdeventplus::Event::get_default();
45 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
Andrew Geissleree3a2c82019-07-30 15:16:20 -050046 std::vector<std::string> filePaths;
Andrew Geissler891213b2019-07-30 14:08:17 -050047
Andrew Geissleree3a2c82019-07-30 15:16:20 -050048 CLI::App app{"OpenBmc systemd target monitor"};
49 app.add_option("-f,--file", filePaths,
50 "Full path to json file(s) with target/error mappings");
Andrew Geissler693eaed2019-08-02 14:12:28 -050051 app.add_flag("-v", gVerbose, "Enable verbose output");
Andrew Geissleree3a2c82019-07-30 15:16:20 -050052
53 CLI11_PARSE(app, argc, argv);
54
55 if (filePaths.empty())
56 {
57 log<level::ERR>("No input files");
58 print_usage();
59 exit(-1);
60 }
Andrew Geissler891213b2019-07-30 14:08:17 -050061
Andrew Geissler693eaed2019-08-02 14:12:28 -050062 TargetErrorData targetData = parseFiles(filePaths);
63
64 if (targetData.size() == 0)
65 {
66 log<level::ERR>("Invalid input files, no targets found");
67 print_usage();
68 exit(-1);
69 }
70
71 if (gVerbose)
72 {
73 dump_targets(targetData);
74 }
Andrew Geissler891213b2019-07-30 14:08:17 -050075
Andrew Geissler234a3172019-08-09 14:30:02 -050076 phosphor::state::manager::SystemdTargetLogging targetMon(targetData, bus);
77
78 // Subscribe to systemd D-bus signals indicating target completions
79 targetMon.subscribeToSystemdSignals();
Andrew Geissler891213b2019-07-30 14:08:17 -050080
81 return event.loop();
82}