Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame] | 1 | #include "systemd_target_parser.hpp" |
| 2 | #include "systemd_target_signal.hpp" |
| 3 | |
Andrew Geissler | ee3a2c8 | 2019-07-30 15:16:20 -0500 | [diff] [blame] | 4 | #include <CLI/CLI.hpp> |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame^] | 5 | #include <phosphor-logging/lg2.hpp> |
Andrew Geissler | 891213b | 2019-07-30 14:08:17 -0500 | [diff] [blame] | 6 | #include <sdbusplus/bus.hpp> |
| 7 | #include <sdeventplus/event.hpp> |
Andrew Geissler | e426b58 | 2020-05-28 12:40:55 -0500 | [diff] [blame] | 8 | |
| 9 | #include <iostream> |
Andrew Geissler | ee3a2c8 | 2019-07-30 15:16:20 -0500 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame^] | 12 | PHOSPHOR_LOG2_USING; |
Andrew Geissler | ee3a2c8 | 2019-07-30 15:16:20 -0500 | [diff] [blame] | 13 | |
Andrew Geissler | 693eaed | 2019-08-02 14:12:28 -0500 | [diff] [blame] | 14 | bool gVerbose = false; |
| 15 | |
| 16 | void dump_targets(const TargetErrorData& targetData) |
| 17 | { |
| 18 | std::cout << "## Data Structure of Json ##" << std::endl; |
| 19 | for (const auto& [target, value] : targetData) |
| 20 | { |
| 21 | std::cout << target << " " << value.errorToLog << std::endl; |
| 22 | std::cout << " "; |
| 23 | for (auto& eToMonitor : value.errorsToMonitor) |
| 24 | { |
| 25 | std::cout << eToMonitor << ", "; |
| 26 | } |
| 27 | std::cout << std::endl; |
| 28 | } |
| 29 | std::cout << std::endl; |
| 30 | } |
| 31 | |
Andrew Geissler | ee3a2c8 | 2019-07-30 15:16:20 -0500 | [diff] [blame] | 32 | void print_usage(void) |
| 33 | { |
| 34 | std::cout << "[-f <file1> -f <file2> ...] : Full path to json file(s) with " |
| 35 | "target/error mappings" |
| 36 | << std::endl; |
| 37 | return; |
| 38 | } |
Andrew Geissler | 891213b | 2019-07-30 14:08:17 -0500 | [diff] [blame] | 39 | |
| 40 | int main(int argc, char* argv[]) |
| 41 | { |
| 42 | auto bus = sdbusplus::bus::new_default(); |
| 43 | auto event = sdeventplus::Event::get_default(); |
| 44 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
Andrew Geissler | ee3a2c8 | 2019-07-30 15:16:20 -0500 | [diff] [blame] | 45 | std::vector<std::string> filePaths; |
Andrew Geissler | 891213b | 2019-07-30 14:08:17 -0500 | [diff] [blame] | 46 | |
Andrew Geissler | ee3a2c8 | 2019-07-30 15:16:20 -0500 | [diff] [blame] | 47 | CLI::App app{"OpenBmc systemd target monitor"}; |
| 48 | app.add_option("-f,--file", filePaths, |
| 49 | "Full path to json file(s) with target/error mappings"); |
Andrew Geissler | 693eaed | 2019-08-02 14:12:28 -0500 | [diff] [blame] | 50 | app.add_flag("-v", gVerbose, "Enable verbose output"); |
Andrew Geissler | ee3a2c8 | 2019-07-30 15:16:20 -0500 | [diff] [blame] | 51 | |
| 52 | CLI11_PARSE(app, argc, argv); |
| 53 | |
| 54 | if (filePaths.empty()) |
| 55 | { |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame^] | 56 | error("No input files"); |
Andrew Geissler | ee3a2c8 | 2019-07-30 15:16:20 -0500 | [diff] [blame] | 57 | print_usage(); |
| 58 | exit(-1); |
| 59 | } |
Andrew Geissler | 891213b | 2019-07-30 14:08:17 -0500 | [diff] [blame] | 60 | |
Andrew Geissler | 693eaed | 2019-08-02 14:12:28 -0500 | [diff] [blame] | 61 | TargetErrorData targetData = parseFiles(filePaths); |
| 62 | |
| 63 | if (targetData.size() == 0) |
| 64 | { |
Andrew Geissler | 8ffdb26 | 2021-09-20 15:25:19 -0500 | [diff] [blame^] | 65 | error("Invalid input files, no targets found"); |
Andrew Geissler | 693eaed | 2019-08-02 14:12:28 -0500 | [diff] [blame] | 66 | print_usage(); |
| 67 | exit(-1); |
| 68 | } |
| 69 | |
| 70 | if (gVerbose) |
| 71 | { |
| 72 | dump_targets(targetData); |
| 73 | } |
Andrew Geissler | 891213b | 2019-07-30 14:08:17 -0500 | [diff] [blame] | 74 | |
Andrew Geissler | 234a317 | 2019-08-09 14:30:02 -0500 | [diff] [blame] | 75 | phosphor::state::manager::SystemdTargetLogging targetMon(targetData, bus); |
| 76 | |
| 77 | // Subscribe to systemd D-bus signals indicating target completions |
| 78 | targetMon.subscribeToSystemdSignals(); |
Andrew Geissler | 891213b | 2019-07-30 14:08:17 -0500 | [diff] [blame] | 79 | |
| 80 | return event.loop(); |
| 81 | } |