]> granicus.if.org Git - icinga2/blob - lib/cli/apisetupcommand.cpp
ApiListener#ApiTimerHandler(): delete all replayed logs
[icinga2] / lib / cli / apisetupcommand.cpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/)      *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #include "cli/apisetupcommand.hpp"
21 #include "cli/apisetuputility.hpp"
22 #include "cli/variableutility.hpp"
23 #include "base/logger.hpp"
24 #include "base/console.hpp"
25 #include <iostream>
26
27 using namespace icinga;
28 namespace po = boost::program_options;
29
30 REGISTER_CLICOMMAND("api/setup", ApiSetupCommand);
31
32 String ApiSetupCommand::GetDescription() const
33 {
34         return "Setup for Icinga 2 API.";
35 }
36
37 String ApiSetupCommand::GetShortDescription() const
38 {
39         return "setup for API";
40 }
41
42 ImpersonationLevel ApiSetupCommand::GetImpersonationLevel() const
43 {
44         return ImpersonateRoot;
45 }
46
47 int ApiSetupCommand::GetMaxArguments() const
48 {
49         return -1;
50 }
51
52 /**
53  * The entry point for the "api setup" CLI command.
54  *
55  * @returns An exit status.
56  */
57 int ApiSetupCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
58 {
59         String cn = VariableUtility::GetVariable("NodeName");
60
61         if (cn.IsEmpty())
62                 cn = Utility::GetFQDN();
63
64         if (!ApiSetupUtility::SetupMaster(cn, true))
65                 return 1;
66
67         return 0;
68 }