| Alexander Hansen | aa9c24a | 2025-10-30 13:59:26 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2017 IBM Corporation |
| Matt Spinler | 62b36bd | 2017-06-02 12:15:59 -0500 | [diff] [blame] | 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 | */ |
| Matt Spinler | 8b633b7 | 2017-06-02 12:35:59 -0500 | [diff] [blame] | 10 | #include "monitor.hpp" |
| Matt Spinler | 62b36bd | 2017-06-02 12:15:59 -0500 | [diff] [blame] | 11 | |
| Brad Bishop | 8c24362 | 2022-07-11 11:21:50 -0400 | [diff] [blame] | 12 | #include <CLI/CLI.hpp> |
| 13 | |
| Matt Spinler | cc6ee9c | 2018-09-19 13:23:13 -0500 | [diff] [blame] | 14 | #include <map> |
| Brad Bishop | 8c24362 | 2022-07-11 11:21:50 -0400 | [diff] [blame] | 15 | #include <string> |
| Matt Spinler | cc6ee9c | 2018-09-19 13:23:13 -0500 | [diff] [blame] | 16 | |
| Matt Spinler | 8b633b7 | 2017-06-02 12:35:59 -0500 | [diff] [blame] | 17 | using namespace phosphor::unit::failure; |
| 18 | |
| Ed Tanous | 167e237 | 2018-05-07 11:59:10 -0700 | [diff] [blame] | 19 | static const std::map<std::string, Monitor::Action> actions = { |
| 20 | {"start", Monitor::Action::start}, {"stop", Monitor::Action::stop}}; |
| Matt Spinler | 62b36bd | 2017-06-02 12:15:59 -0500 | [diff] [blame] | 21 | |
| 22 | int main(int argc, char** argv) |
| 23 | { |
| Brad Bishop | 8c24362 | 2022-07-11 11:21:50 -0400 | [diff] [blame] | 24 | CLI::App app; |
| 25 | std::string source; |
| 26 | std::string target; |
| 27 | Monitor::Action action{Monitor::Action::start}; |
| Matt Spinler | 62b36bd | 2017-06-02 12:15:59 -0500 | [diff] [blame] | 28 | |
| Brad Bishop | 8c24362 | 2022-07-11 11:21:50 -0400 | [diff] [blame] | 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)); |
| Matt Spinler | 8b633b7 | 2017-06-02 12:35:59 -0500 | [diff] [blame] | 36 | |
| Brad Bishop | 3d9fb99 | 2025-07-15 17:21:22 -0400 | [diff] [blame^] | 37 | try |
| 38 | { |
| 39 | app.parse(argc, argv); |
| 40 | } |
| 41 | catch (const CLI::ParseError& e) |
| 42 | { |
| 43 | return (app).exit(e); |
| 44 | } |
| Brad Bishop | 8c24362 | 2022-07-11 11:21:50 -0400 | [diff] [blame] | 45 | Monitor monitor{source, target, action}; |
| Matt Spinler | 8b633b7 | 2017-06-02 12:35:59 -0500 | [diff] [blame] | 46 | |
| 47 | monitor.analyze(); |
| Matt Spinler | 62b36bd | 2017-06-02 12:15:59 -0500 | [diff] [blame] | 48 | |
| 49 | return 0; |
| 50 | } |