2015-06-24 15:09:22 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2018-01-02 12:06:00 +01:00
|
|
|
* Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
|
2015-06-24 15:09:22 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "cli/apisetupcommand.hpp"
|
|
|
|
#include "cli/apisetuputility.hpp"
|
2015-11-26 08:09:24 +01:00
|
|
|
#include "cli/variableutility.hpp"
|
2015-06-24 15:09:22 +02:00
|
|
|
#include "base/logger.hpp"
|
|
|
|
#include "base/console.hpp"
|
2015-06-25 17:20:23 +02:00
|
|
|
#include <iostream>
|
2015-06-24 15:09:22 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
namespace po = boost::program_options;
|
|
|
|
|
|
|
|
REGISTER_CLICOMMAND("api/setup", ApiSetupCommand);
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
String ApiSetupCommand::GetDescription() const
|
2015-06-24 15:09:22 +02:00
|
|
|
{
|
|
|
|
return "Setup for Icinga 2 API.";
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
String ApiSetupCommand::GetShortDescription() const
|
2015-06-24 15:09:22 +02:00
|
|
|
{
|
2017-08-11 16:23:24 +02:00
|
|
|
return "setup for API";
|
2015-06-24 15:09:22 +02:00
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
ImpersonationLevel ApiSetupCommand::GetImpersonationLevel() const
|
2015-06-24 15:09:22 +02:00
|
|
|
{
|
|
|
|
return ImpersonateRoot;
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
int ApiSetupCommand::GetMaxArguments() const
|
2015-06-24 15:09:22 +02:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-26 07:03:41 +01:00
|
|
|
* The entry point for the "api setup" CLI command.
|
2015-06-24 15:09:22 +02:00
|
|
|
*
|
|
|
|
* @returns An exit status.
|
|
|
|
*/
|
|
|
|
int ApiSetupCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
|
|
|
{
|
2015-11-26 08:09:24 +01:00
|
|
|
String cn = VariableUtility::GetVariable("NodeName");
|
|
|
|
|
|
|
|
if (cn.IsEmpty())
|
|
|
|
cn = Utility::GetFQDN();
|
|
|
|
|
|
|
|
if (!ApiSetupUtility::SetupMaster(cn, true))
|
2015-10-22 15:56:27 +02:00
|
|
|
return 1;
|
2015-06-24 15:09:22 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|