#include "systemd_service_parser.hpp" #include "systemd_target_parser.hpp" #include "systemd_target_signal.hpp" #include #include #include #include #include #include PHOSPHOR_LOG2_USING; 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 -f ...] : Full path to json file(s) with " "target/error mappings" << std::endl; std::cout << "[-s -s ...] : Full path to json file(s) with " "services to monitor for errors" << 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 targetFilePaths; std::vector serviceFilePaths; CLI::App app{"OpenBmc systemd target and service monitor"}; app.add_option("-f,--file", targetFilePaths, "Full path to json file(s) with target/error mappings"); app.add_option("-s,--service", serviceFilePaths, "Full path to json file(s) with services to monitor"); app.add_flag("-v", gVerbose, "Enable verbose output"); CLI11_PARSE(app, argc, argv); // target file input required if (targetFilePaths.empty()) { error("No input files"); print_usage(); exit(-1); } TargetErrorData targetData = parseFiles(targetFilePaths); if (targetData.size() == 0) { error("Invalid input files, no targets found"); print_usage(); exit(-1); } ServiceMonitorData serviceData; if (!serviceFilePaths.empty()) { serviceData = parseServiceFiles(serviceFilePaths); } if (gVerbose) { dump_targets(targetData); } phosphor::state::manager::SystemdTargetLogging targetMon(targetData, serviceData, bus); // Subscribe to systemd D-bus signals indicating target completions targetMon.subscribeToSystemdSignals(); return event.loop(); }