| #include <CLI/CLI.hpp> |
| #include <iostream> |
| #include <phosphor-logging/log.hpp> |
| #include <sdbusplus/bus.hpp> |
| #include <sdeventplus/event.hpp> |
| #include <systemd_target_parser.hpp> |
| #include <systemd_target_signal.hpp> |
| #include <vector> |
| |
| using phosphor::logging::level; |
| using phosphor::logging::log; |
| |
| bool gVerbose = false; |
| |
| void dump_targets(const TargetErrorData& targetData) |
| { |
| std::cout << "## Data Structure of Json ##" << std::endl; |
| for (const auto& [target, value] : targetData) |
| { |
| std::cout << target << " " << value.errorToLog << std::endl; |
| std::cout << " "; |
| for (auto& eToMonitor : value.errorsToMonitor) |
| { |
| std::cout << eToMonitor << ", "; |
| } |
| std::cout << std::endl; |
| } |
| std::cout << std::endl; |
| } |
| |
| void print_usage(void) |
| { |
| std::cout << "[-f <file1> -f <file2> ...] : Full path to json file(s) with " |
| "target/error mappings" |
| << std::endl; |
| return; |
| } |
| |
| int main(int argc, char* argv[]) |
| { |
| auto bus = sdbusplus::bus::new_default(); |
| auto event = sdeventplus::Event::get_default(); |
| bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
| std::vector<std::string> filePaths; |
| |
| CLI::App app{"OpenBmc systemd target monitor"}; |
| app.add_option("-f,--file", filePaths, |
| "Full path to json file(s) with target/error mappings"); |
| app.add_flag("-v", gVerbose, "Enable verbose output"); |
| |
| CLI11_PARSE(app, argc, argv); |
| |
| if (filePaths.empty()) |
| { |
| log<level::ERR>("No input files"); |
| print_usage(); |
| exit(-1); |
| } |
| |
| TargetErrorData targetData = parseFiles(filePaths); |
| |
| if (targetData.size() == 0) |
| { |
| log<level::ERR>("Invalid input files, no targets found"); |
| print_usage(); |
| exit(-1); |
| } |
| |
| if (gVerbose) |
| { |
| dump_targets(targetData); |
| } |
| |
| phosphor::state::manager::SystemdTargetLogging targetMon(targetData, bus); |
| |
| // Subscribe to systemd D-bus signals indicating target completions |
| targetMon.subscribeToSystemdSignals(); |
| |
| return event.loop(); |
| } |