1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright 2017 IBM Corporation
3
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 */
10 #include "monitor.hpp"
11
12 #include <CLI/CLI.hpp>
13
14 #include <map>
15 #include <string>
16
17 using namespace phosphor::unit::failure;
18
19 static const std::map<std::string, Monitor::Action> actions = {
20 {"start", Monitor::Action::start}, {"stop", Monitor::Action::stop}};
21
main(int argc,char ** argv)22 int main(int argc, char** argv)
23 {
24 CLI::App app;
25 std::string source;
26 std::string target;
27 Monitor::Action action{Monitor::Action::start};
28
29 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));
36
37 try
38 {
39 app.parse(argc, argv);
40 }
41 catch (const CLI::ParseError& e)
42 {
43 return (app).exit(e);
44 }
45 Monitor monitor{source, target, action};
46
47 monitor.analyze();
48
49 return 0;
50 }
51