]> granicus.if.org Git - icinga2/blob - lib/cli/apisetupcommand.cpp
add some object locking to the Dump method (which could theoreticylly suffer from...
[icinga2] / lib / cli / apisetupcommand.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "cli/apisetupcommand.hpp"
4 #include "cli/apisetuputility.hpp"
5 #include "cli/variableutility.hpp"
6 #include "base/logger.hpp"
7 #include "base/console.hpp"
8 #include <iostream>
9
10 using namespace icinga;
11 namespace po = boost::program_options;
12
13 REGISTER_CLICOMMAND("api/setup", ApiSetupCommand);
14
15 String ApiSetupCommand::GetDescription() const
16 {
17         return "Setup for Icinga 2 API.";
18 }
19
20 String ApiSetupCommand::GetShortDescription() const
21 {
22         return "setup for API";
23 }
24
25 ImpersonationLevel ApiSetupCommand::GetImpersonationLevel() const
26 {
27         return ImpersonateIcinga;
28 }
29
30 int ApiSetupCommand::GetMaxArguments() const
31 {
32         return -1;
33 }
34
35 /**
36  * The entry point for the "api setup" CLI command.
37  *
38  * @returns An exit status.
39  */
40 int ApiSetupCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
41 {
42         String cn = VariableUtility::GetVariable("NodeName");
43
44         if (cn.IsEmpty())
45                 cn = Utility::GetFQDN();
46
47         if (!ApiSetupUtility::SetupMaster(cn, true))
48                 return 1;
49
50         return 0;
51 }