blob: b0c76f00c98b7c2040eca946892fbbb66ac8b340 [file] [log] [blame]
Alexander Hansenaa9c24a2025-10-30 13:59:26 +01001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright 2017 IBM Corporation
Matt Spinler62b36bd2017-06-02 12:15:59 -05003
4/**
5 * This application will check the ActiveState property
6 * on the source unit passed in. If that state is 'failed',
7 * then it will either stop or start the target unit, depending
8 * on the command line arguments.
9 */
Matt Spinler8b633b72017-06-02 12:35:59 -050010#include "monitor.hpp"
Matt Spinler62b36bd2017-06-02 12:15:59 -050011
Brad Bishop8c243622022-07-11 11:21:50 -040012#include <CLI/CLI.hpp>
13
Matt Spinlercc6ee9c2018-09-19 13:23:13 -050014#include <map>
Brad Bishop8c243622022-07-11 11:21:50 -040015#include <string>
Matt Spinlercc6ee9c2018-09-19 13:23:13 -050016
Matt Spinler8b633b72017-06-02 12:35:59 -050017using namespace phosphor::unit::failure;
18
Ed Tanous167e2372018-05-07 11:59:10 -070019static const std::map<std::string, Monitor::Action> actions = {
20 {"start", Monitor::Action::start}, {"stop", Monitor::Action::stop}};
Matt Spinler62b36bd2017-06-02 12:15:59 -050021
22int main(int argc, char** argv)
23{
Brad Bishop8c243622022-07-11 11:21:50 -040024 CLI::App app;
25 std::string source;
26 std::string target;
27 Monitor::Action action{Monitor::Action::start};
Matt Spinler62b36bd2017-06-02 12:15:59 -050028
Brad Bishop8c243622022-07-11 11:21:50 -040029 app.add_option("-s,--source", source, "The source unit to monitor")
30 ->required();
31 app.add_option("-t,--target", target, "The target unit to start or stop")
32 ->required();
33 app.add_option("-a,--action", action, "Target unit action - start or stop")
34 ->required()
35 ->transform(CLI::CheckedTransformer(actions, CLI::ignore_space));
Matt Spinler8b633b72017-06-02 12:35:59 -050036
Brad Bishop3d9fb992025-07-15 17:21:22 -040037 try
38 {
39 app.parse(argc, argv);
40 }
41 catch (const CLI::ParseError& e)
42 {
43 return (app).exit(e);
44 }
Brad Bishop8c243622022-07-11 11:21:50 -040045 Monitor monitor{source, target, action};
Matt Spinler8b633b72017-06-02 12:35:59 -050046
47 monitor.analyze();
Matt Spinler62b36bd2017-06-02 12:15:59 -050048
49 return 0;
50}