blob: cc13711457bd43033fd9890e350b330e19601a3d [file] [log] [blame]
#include "systemd_target_parser.hpp"
#include "systemd_target_signal.hpp"
#include <CLI/CLI.hpp>
#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <sdeventplus/event.hpp>
#include <iostream>
#include <vector>
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 <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())
{
error("No input files");
print_usage();
exit(-1);
}
TargetErrorData targetData = parseFiles(filePaths);
if (targetData.size() == 0)
{
error("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();
}