mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-22 21:24:41 +02:00
parent
5eefda8b85
commit
79f1711a61
@ -16,8 +16,8 @@
|
|||||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
set(cli_SOURCES
|
set(cli_SOURCES
|
||||||
agentaddcommand.cpp agentblackandwhitelistcommand.cpp agentlistcommand.cpp agentremovecommand.cpp
|
nodeaddcommand.cpp nodeblackandwhitelistcommand.cpp nodelistcommand.cpp noderemovecommand.cpp
|
||||||
agentsetcommand.cpp agentsetupcommand.cpp agentupdateconfigcommand.cpp agentwizardcommand.cpp agentutility.cpp
|
nodesetcommand.cpp nodesetupcommand.cpp nodeupdateconfigcommand.cpp nodewizardcommand.cpp nodeutility.cpp
|
||||||
clicommand.cpp
|
clicommand.cpp
|
||||||
daemoncommand.cpp
|
daemoncommand.cpp
|
||||||
featureenablecommand.cpp featuredisablecommand.cpp featurelistcommand.cpp featureutility.cpp
|
featureenablecommand.cpp featuredisablecommand.cpp featurelistcommand.cpp featureutility.cpp
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "cli/agentaddcommand.hpp"
|
#include "cli/nodeaddcommand.hpp"
|
||||||
#include "cli/agentutility.hpp"
|
#include "cli/nodeutility.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
@ -31,19 +31,19 @@
|
|||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
REGISTER_CLICOMMAND("agent/add", AgentAddCommand);
|
REGISTER_CLICOMMAND("node/add", NodeAddCommand);
|
||||||
|
|
||||||
String AgentAddCommand::GetDescription(void) const
|
String NodeAddCommand::GetDescription(void) const
|
||||||
{
|
{
|
||||||
return "Add Icinga 2 agent.";
|
return "Add Icinga 2 agent.";
|
||||||
}
|
}
|
||||||
|
|
||||||
String AgentAddCommand::GetShortDescription(void) const
|
String NodeAddCommand::GetShortDescription(void) const
|
||||||
{
|
{
|
||||||
return "add agent";
|
return "add agent";
|
||||||
}
|
}
|
||||||
|
|
||||||
int AgentAddCommand::GetMinArguments(void) const
|
int NodeAddCommand::GetMinArguments(void) const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -53,9 +53,9 @@ int AgentAddCommand::GetMinArguments(void) const
|
|||||||
*
|
*
|
||||||
* @returns An exit status.
|
* @returns An exit status.
|
||||||
*/
|
*/
|
||||||
int AgentAddCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
int NodeAddCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
||||||
{
|
{
|
||||||
AgentUtility::AddAgent(ap[0]);
|
NodeUtility::AddNode(ap[0]);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -30,10 +30,10 @@ namespace icinga
|
|||||||
*
|
*
|
||||||
* @ingroup cli
|
* @ingroup cli
|
||||||
*/
|
*/
|
||||||
class AgentAddCommand : public CLICommand
|
class NodeAddCommand : public CLICommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(AgentAddCommand);
|
DECLARE_PTR_TYPEDEFS(NodeAddCommand);
|
||||||
|
|
||||||
virtual String GetDescription(void) const;
|
virtual String GetDescription(void) const;
|
||||||
virtual String GetShortDescription(void) const;
|
virtual String GetShortDescription(void) const;
|
@ -17,8 +17,8 @@
|
|||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "cli/agentblackandwhitelistcommand.hpp"
|
#include "cli/nodeblackandwhitelistcommand.hpp"
|
||||||
#include "cli/agentutility.hpp"
|
#include "cli/nodeutility.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
#include "base/objectlock.hpp"
|
#include "base/objectlock.hpp"
|
||||||
@ -40,7 +40,7 @@ RegisterBlackAndWhitelistCLICommandHelper::RegisterBlackAndWhitelistCLICommandHe
|
|||||||
boost::algorithm::to_lower(ltype);
|
boost::algorithm::to_lower(ltype);
|
||||||
|
|
||||||
std::vector<String> name;
|
std::vector<String> name;
|
||||||
name.push_back("agent");
|
name.push_back("node");
|
||||||
name.push_back(ltype);
|
name.push_back(ltype);
|
||||||
name.push_back("add");
|
name.push_back("add");
|
||||||
CLICommand::Register(name, make_shared<BlackAndWhitelistCommand>(type, BlackAndWhitelistCommandAdd));
|
CLICommand::Register(name, make_shared<BlackAndWhitelistCommand>(type, BlackAndWhitelistCommandAdd));
|
||||||
@ -124,7 +124,7 @@ void BlackAndWhitelistCommand::InitParameters(boost::program_options::options_de
|
|||||||
*/
|
*/
|
||||||
int BlackAndWhitelistCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
int BlackAndWhitelistCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
||||||
{
|
{
|
||||||
String list_path = AgentUtility::GetRepositoryPath() + "/" + m_Type + ".list";
|
String list_path = NodeUtility::GetRepositoryPath() + "/" + m_Type + ".list";
|
||||||
|
|
||||||
Dictionary::Ptr lists = make_shared<Dictionary>();
|
Dictionary::Ptr lists = make_shared<Dictionary>();
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ int BlackAndWhitelistCommand::Run(const boost::program_options::variables_map& v
|
|||||||
if (vm.count("service"))
|
if (vm.count("service"))
|
||||||
service_filter = vm["service"].as<std::string>();
|
service_filter = vm["service"].as<std::string>();
|
||||||
|
|
||||||
return AgentUtility::UpdateBlackAndWhiteList(m_Type, vm["agent"].as<std::string>(), vm["host"].as<std::string>(), service_filter);
|
return NodeUtility::UpdateBlackAndWhiteList(m_Type, vm["agent"].as<std::string>(), vm["host"].as<std::string>(), service_filter);
|
||||||
} else if (m_Command == BlackAndWhitelistCommandList) {
|
} else if (m_Command == BlackAndWhitelistCommandList) {
|
||||||
|
|
||||||
if (vm.count("agent") || vm.count("host") || vm.count("service")) {
|
if (vm.count("agent") || vm.count("host") || vm.count("service")) {
|
||||||
@ -155,7 +155,7 @@ int BlackAndWhitelistCommand::Run(const boost::program_options::variables_map& v
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return AgentUtility::PrintBlackAndWhiteList(std::cout, m_Type);
|
return NodeUtility::PrintBlackAndWhiteList(std::cout, m_Type);
|
||||||
} else if (m_Command == BlackAndWhitelistCommandRemove) {
|
} else if (m_Command == BlackAndWhitelistCommandRemove) {
|
||||||
if (!vm.count("agent")) {
|
if (!vm.count("agent")) {
|
||||||
Log(LogCritical, "cli", "At least the agent name filter is required!");
|
Log(LogCritical, "cli", "At least the agent name filter is required!");
|
||||||
@ -174,7 +174,7 @@ int BlackAndWhitelistCommand::Run(const boost::program_options::variables_map& v
|
|||||||
service_filter = vm["service"].as<std::string>();
|
service_filter = vm["service"].as<std::string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return AgentUtility::RemoveBlackAndWhiteList(m_Type, vm["agent"].as<std::string>(), vm["host"].as<std::string>(), service_filter);
|
return NodeUtility::RemoveBlackAndWhiteList(m_Type, vm["agent"].as<std::string>(), vm["host"].as<std::string>(), service_filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -17,8 +17,8 @@
|
|||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "cli/agentlistcommand.hpp"
|
#include "cli/nodelistcommand.hpp"
|
||||||
#include "cli/agentutility.hpp"
|
#include "cli/nodeutility.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
#include "base/console.hpp"
|
#include "base/console.hpp"
|
||||||
@ -32,19 +32,19 @@
|
|||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
REGISTER_CLICOMMAND("agent/list", AgentListCommand);
|
REGISTER_CLICOMMAND("node/list", NodeListCommand);
|
||||||
|
|
||||||
String AgentListCommand::GetDescription(void) const
|
String NodeListCommand::GetDescription(void) const
|
||||||
{
|
{
|
||||||
return "Lists all Icinga 2 agents.";
|
return "Lists all Icinga 2 agents.";
|
||||||
}
|
}
|
||||||
|
|
||||||
String AgentListCommand::GetShortDescription(void) const
|
String NodeListCommand::GetShortDescription(void) const
|
||||||
{
|
{
|
||||||
return "lists all agents";
|
return "lists all agents";
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentListCommand::InitParameters(boost::program_options::options_description& visibleDesc,
|
void NodeListCommand::InitParameters(boost::program_options::options_description& visibleDesc,
|
||||||
boost::program_options::options_description& hiddenDesc) const
|
boost::program_options::options_description& hiddenDesc) const
|
||||||
{
|
{
|
||||||
visibleDesc.add_options()
|
visibleDesc.add_options()
|
||||||
@ -56,7 +56,7 @@ void AgentListCommand::InitParameters(boost::program_options::options_descriptio
|
|||||||
*
|
*
|
||||||
* @returns An exit status.
|
* @returns An exit status.
|
||||||
*/
|
*/
|
||||||
int AgentListCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
int NodeListCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
||||||
{
|
{
|
||||||
if (!ap.empty()) {
|
if (!ap.empty()) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
@ -64,9 +64,9 @@ int AgentListCommand::Run(const boost::program_options::variables_map& vm, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (vm.count("batch"))
|
if (vm.count("batch"))
|
||||||
AgentUtility::PrintAgentsJson(std::cout);
|
NodeUtility::PrintNodesJson(std::cout);
|
||||||
else
|
else
|
||||||
AgentUtility::PrintAgents(std::cout);
|
NodeUtility::PrintNodes(std::cout);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -30,10 +30,10 @@ namespace icinga
|
|||||||
*
|
*
|
||||||
* @ingroup cli
|
* @ingroup cli
|
||||||
*/
|
*/
|
||||||
class AgentListCommand : public CLICommand
|
class NodeListCommand : public CLICommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(AgentListCommand);
|
DECLARE_PTR_TYPEDEFS(NodeListCommand);
|
||||||
|
|
||||||
virtual String GetDescription(void) const;
|
virtual String GetDescription(void) const;
|
||||||
virtual String GetShortDescription(void) const;
|
virtual String GetShortDescription(void) const;
|
@ -17,8 +17,8 @@
|
|||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "cli/agentremovecommand.hpp"
|
#include "cli/noderemovecommand.hpp"
|
||||||
#include "cli/agentutility.hpp"
|
#include "cli/nodeutility.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
@ -31,29 +31,29 @@
|
|||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
REGISTER_CLICOMMAND("agent/remove", AgentRemoveCommand);
|
REGISTER_CLICOMMAND("node/remove", NodeRemoveCommand);
|
||||||
|
|
||||||
String AgentRemoveCommand::GetDescription(void) const
|
String NodeRemoveCommand::GetDescription(void) const
|
||||||
{
|
{
|
||||||
return "Removes Icinga 2 agent.";
|
return "Removes Icinga 2 agent.";
|
||||||
}
|
}
|
||||||
|
|
||||||
String AgentRemoveCommand::GetShortDescription(void) const
|
String NodeRemoveCommand::GetShortDescription(void) const
|
||||||
{
|
{
|
||||||
return "removes agent";
|
return "removes agent";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<String> AgentRemoveCommand::GetPositionalSuggestions(const String& word) const
|
std::vector<String> NodeRemoveCommand::GetPositionalSuggestions(const String& word) const
|
||||||
{
|
{
|
||||||
return AgentUtility::GetAgentCompletionSuggestions(word);
|
return NodeUtility::GetNodeCompletionSuggestions(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
int AgentRemoveCommand::GetMinArguments(void) const
|
int NodeRemoveCommand::GetMinArguments(void) const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AgentRemoveCommand::GetMaxArguments(void) const
|
int NodeRemoveCommand::GetMaxArguments(void) const
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -63,10 +63,10 @@ int AgentRemoveCommand::GetMaxArguments(void) const
|
|||||||
*
|
*
|
||||||
* @returns An exit status.
|
* @returns An exit status.
|
||||||
*/
|
*/
|
||||||
int AgentRemoveCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
int NodeRemoveCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
||||||
{
|
{
|
||||||
BOOST_FOREACH(const String& agent, ap) {
|
BOOST_FOREACH(const String& agent, ap) {
|
||||||
AgentUtility::RemoveAgent(agent);
|
NodeUtility::RemoveNode(agent);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
@ -30,10 +30,10 @@ namespace icinga
|
|||||||
*
|
*
|
||||||
* @ingroup cli
|
* @ingroup cli
|
||||||
*/
|
*/
|
||||||
class AgentRemoveCommand : public CLICommand
|
class NodeRemoveCommand : public CLICommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(AgentRemoveCommand);
|
DECLARE_PTR_TYPEDEFS(NodeRemoveCommand);
|
||||||
|
|
||||||
virtual String GetDescription(void) const;
|
virtual String GetDescription(void) const;
|
||||||
virtual String GetShortDescription(void) const;
|
virtual String GetShortDescription(void) const;
|
@ -17,8 +17,8 @@
|
|||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "cli/agentsetcommand.hpp"
|
#include "cli/nodesetcommand.hpp"
|
||||||
#include "cli/agentutility.hpp"
|
#include "cli/nodeutility.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
@ -31,19 +31,19 @@
|
|||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
REGISTER_CLICOMMAND("agent/set", AgentSetCommand);
|
REGISTER_CLICOMMAND("node/set", NodeSetCommand);
|
||||||
|
|
||||||
String AgentSetCommand::GetDescription(void) const
|
String NodeSetCommand::GetDescription(void) const
|
||||||
{
|
{
|
||||||
return "Set agent attribute(s).";
|
return "Set agent attribute(s).";
|
||||||
}
|
}
|
||||||
|
|
||||||
String AgentSetCommand::GetShortDescription(void) const
|
String NodeSetCommand::GetShortDescription(void) const
|
||||||
{
|
{
|
||||||
return "set agent attributes";
|
return "set agent attributes";
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentSetCommand::InitParameters(boost::program_options::options_description& visibleDesc,
|
void NodeSetCommand::InitParameters(boost::program_options::options_description& visibleDesc,
|
||||||
boost::program_options::options_description& hiddenDesc) const
|
boost::program_options::options_description& hiddenDesc) const
|
||||||
{
|
{
|
||||||
visibleDesc.add_options()
|
visibleDesc.add_options()
|
||||||
@ -52,7 +52,7 @@ void AgentSetCommand::InitParameters(boost::program_options::options_description
|
|||||||
("log_duration", po::value<double>(), "Log duration (in seconds)");
|
("log_duration", po::value<double>(), "Log duration (in seconds)");
|
||||||
}
|
}
|
||||||
|
|
||||||
int AgentSetCommand::GetMinArguments(void) const
|
int NodeSetCommand::GetMinArguments(void) const
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -62,13 +62,13 @@ int AgentSetCommand::GetMinArguments(void) const
|
|||||||
*
|
*
|
||||||
* @returns An exit status.
|
* @returns An exit status.
|
||||||
*/
|
*/
|
||||||
int AgentSetCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
int NodeSetCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
||||||
{
|
{
|
||||||
String repoFile = AgentUtility::GetAgentRepositoryFile(ap[0]);
|
String repoFile = NodeUtility::GetNodeRepositoryFile(ap[0]);
|
||||||
|
|
||||||
if (!Utility::PathExists(repoFile)) {
|
if (!Utility::PathExists(repoFile)) {
|
||||||
Log(LogCritical, "cli")
|
Log(LogCritical, "cli")
|
||||||
<< "Agent '" << ap[0] << "' does not exist.";
|
<< "Node '" << ap[0] << "' does not exist.";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ int AgentSetCommand::Run(const boost::program_options::variables_map& vm, const
|
|||||||
if (vm.count("log_duration"))
|
if (vm.count("log_duration"))
|
||||||
log_duration = vm["log_duration"].as<double>();
|
log_duration = vm["log_duration"].as<double>();
|
||||||
|
|
||||||
AgentUtility::AddAgentSettings(ap[0], host, port, log_duration);
|
NodeUtility::AddNodeSettings(ap[0], host, port, log_duration);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -30,10 +30,10 @@ namespace icinga
|
|||||||
*
|
*
|
||||||
* @ingroup cli
|
* @ingroup cli
|
||||||
*/
|
*/
|
||||||
class AgentSetCommand : public CLICommand
|
class NodeSetCommand : public CLICommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(AgentSetCommand);
|
DECLARE_PTR_TYPEDEFS(NodeSetCommand);
|
||||||
|
|
||||||
virtual String GetDescription(void) const;
|
virtual String GetDescription(void) const;
|
||||||
virtual String GetShortDescription(void) const;
|
virtual String GetShortDescription(void) const;
|
@ -17,8 +17,8 @@
|
|||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "cli/agentsetupcommand.hpp"
|
#include "cli/nodesetupcommand.hpp"
|
||||||
#include "cli/agentutility.hpp"
|
#include "cli/nodeutility.hpp"
|
||||||
#include "cli/featureutility.hpp"
|
#include "cli/featureutility.hpp"
|
||||||
#include "cli/pkiutility.hpp"
|
#include "cli/pkiutility.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
@ -39,19 +39,19 @@
|
|||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
REGISTER_CLICOMMAND("agent/setup", AgentSetupCommand);
|
REGISTER_CLICOMMAND("node/setup", NodeSetupCommand);
|
||||||
|
|
||||||
String AgentSetupCommand::GetDescription(void) const
|
String NodeSetupCommand::GetDescription(void) const
|
||||||
{
|
{
|
||||||
return "Sets up an Icinga 2 agent.";
|
return "Sets up an Icinga 2 agent.";
|
||||||
}
|
}
|
||||||
|
|
||||||
String AgentSetupCommand::GetShortDescription(void) const
|
String NodeSetupCommand::GetShortDescription(void) const
|
||||||
{
|
{
|
||||||
return "set up agent";
|
return "set up agent";
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentSetupCommand::InitParameters(boost::program_options::options_description& visibleDesc,
|
void NodeSetupCommand::InitParameters(boost::program_options::options_description& visibleDesc,
|
||||||
boost::program_options::options_description& hiddenDesc) const
|
boost::program_options::options_description& hiddenDesc) const
|
||||||
{
|
{
|
||||||
visibleDesc.add_options()
|
visibleDesc.add_options()
|
||||||
@ -66,7 +66,7 @@ void AgentSetupCommand::InitParameters(boost::program_options::options_descripti
|
|||||||
("master", "Use setup for a master instance");
|
("master", "Use setup for a master instance");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<String> AgentSetupCommand::GetArgumentSuggestions(const String& argument, const String& word) const
|
std::vector<String> NodeSetupCommand::GetArgumentSuggestions(const String& argument, const String& word) const
|
||||||
{
|
{
|
||||||
if (argument == "key" || argument == "cert" || argument == "trustedcert")
|
if (argument == "key" || argument == "cert" || argument == "trustedcert")
|
||||||
return GetBashCompletionSuggestions("file", word);
|
return GetBashCompletionSuggestions("file", word);
|
||||||
@ -78,7 +78,7 @@ std::vector<String> AgentSetupCommand::GetArgumentSuggestions(const String& argu
|
|||||||
return CLICommand::GetArgumentSuggestions(argument, word);
|
return CLICommand::GetArgumentSuggestions(argument, word);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImpersonationLevel AgentSetupCommand::GetImpersonationLevel(void) const
|
ImpersonationLevel NodeSetupCommand::GetImpersonationLevel(void) const
|
||||||
{
|
{
|
||||||
return ImpersonateRoot;
|
return ImpersonateRoot;
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ ImpersonationLevel AgentSetupCommand::GetImpersonationLevel(void) const
|
|||||||
*
|
*
|
||||||
* @returns An exit status.
|
* @returns An exit status.
|
||||||
*/
|
*/
|
||||||
int AgentSetupCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
int NodeSetupCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
||||||
{
|
{
|
||||||
if (!ap.empty()) {
|
if (!ap.empty()) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
@ -98,20 +98,20 @@ int AgentSetupCommand::Run(const boost::program_options::variables_map& vm, cons
|
|||||||
if (vm.count("master"))
|
if (vm.count("master"))
|
||||||
return SetupMaster(vm, ap);
|
return SetupMaster(vm, ap);
|
||||||
else
|
else
|
||||||
return SetupAgent(vm, ap);
|
return SetupNode(vm, ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
int AgentSetupCommand::SetupMaster(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap)
|
int NodeSetupCommand::SetupMaster(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap)
|
||||||
{
|
{
|
||||||
/* Ignore not required parameters */
|
/* Ignore not required parameters */
|
||||||
if (vm.count("ticket"))
|
if (vm.count("ticket"))
|
||||||
Log(LogWarning, "cli", "Master for Agent setup: Ignoring --ticket");
|
Log(LogWarning, "cli", "Master for Node setup: Ignoring --ticket");
|
||||||
|
|
||||||
if (vm.count("endpoint"))
|
if (vm.count("endpoint"))
|
||||||
Log(LogWarning, "cli", "Master for Agent setup: Ignoring --endpoint");
|
Log(LogWarning, "cli", "Master for Node setup: Ignoring --endpoint");
|
||||||
|
|
||||||
if (vm.count("trustedcert"))
|
if (vm.count("trustedcert"))
|
||||||
Log(LogWarning, "cli", "Master for Agent setup: Ignoring --trustedcert");
|
Log(LogWarning, "cli", "Master for Node setup: Ignoring --trustedcert");
|
||||||
|
|
||||||
/* Generate a new CA, if not already existing */
|
/* Generate a new CA, if not already existing */
|
||||||
|
|
||||||
@ -205,7 +205,7 @@ int AgentSetupCommand::SetupMaster(const boost::program_options::variables_map&
|
|||||||
|
|
||||||
Log(LogInformation, "cli", "Generating zone and object configuration.");
|
Log(LogInformation, "cli", "Generating zone and object configuration.");
|
||||||
|
|
||||||
AgentUtility::GenerateAgentMasterIcingaConfig(cn);
|
NodeUtility::GenerateNodeMasterIcingaConfig(cn);
|
||||||
|
|
||||||
/* enable the ApiListener config */
|
/* enable the ApiListener config */
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ int AgentSetupCommand::SetupMaster(const boost::program_options::variables_map&
|
|||||||
FeatureUtility::EnableFeatures(enable);
|
FeatureUtility::EnableFeatures(enable);
|
||||||
|
|
||||||
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
||||||
AgentUtility::CreateBackupFile(apipath);
|
NodeUtility::CreateBackupFile(apipath);
|
||||||
|
|
||||||
String apipathtmp = apipath + ".tmp";
|
String apipathtmp = apipath + ".tmp";
|
||||||
|
|
||||||
@ -266,13 +266,13 @@ int AgentSetupCommand::SetupMaster(const boost::program_options::variables_map&
|
|||||||
|
|
||||||
Log(LogInformation, "cli", "Updating constants.conf.");
|
Log(LogInformation, "cli", "Updating constants.conf.");
|
||||||
|
|
||||||
AgentUtility::CreateBackupFile(Application::GetSysconfDir() + "/icinga2/constants.conf");
|
NodeUtility::CreateBackupFile(Application::GetSysconfDir() + "/icinga2/constants.conf");
|
||||||
|
|
||||||
AgentUtility::UpdateConstant("NodeName", cn);
|
NodeUtility::UpdateConstant("NodeName", cn);
|
||||||
|
|
||||||
String salt = RandomString(16);
|
String salt = RandomString(16);
|
||||||
|
|
||||||
AgentUtility::UpdateConstant("TicketSalt", salt);
|
NodeUtility::UpdateConstant("TicketSalt", salt);
|
||||||
|
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Edit the api feature config file '" << apipath << "' and set a secure 'ticket_salt' attribute.";
|
<< "Edit the api feature config file '" << apipath << "' and set a secure 'ticket_salt' attribute.";
|
||||||
@ -284,7 +284,7 @@ int AgentSetupCommand::SetupMaster(const boost::program_options::variables_map&
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AgentSetupCommand::SetupAgent(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap)
|
int NodeSetupCommand::SetupNode(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap)
|
||||||
{
|
{
|
||||||
/* require ticket number (generated on master) and at least one endpoint */
|
/* require ticket number (generated on master) and at least one endpoint */
|
||||||
|
|
||||||
@ -414,7 +414,7 @@ int AgentSetupCommand::SetupAgent(const boost::program_options::variables_map& v
|
|||||||
FeatureUtility::EnableFeatures(enable);
|
FeatureUtility::EnableFeatures(enable);
|
||||||
|
|
||||||
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
||||||
AgentUtility::CreateBackupFile(apipath);
|
NodeUtility::CreateBackupFile(apipath);
|
||||||
|
|
||||||
String apipathtmp = apipath + ".tmp";
|
String apipathtmp = apipath + ".tmp";
|
||||||
|
|
||||||
@ -460,7 +460,7 @@ int AgentSetupCommand::SetupAgent(const boost::program_options::variables_map& v
|
|||||||
|
|
||||||
Log(LogInformation, "cli", "Generating zone and object configuration.");
|
Log(LogInformation, "cli", "Generating zone and object configuration.");
|
||||||
|
|
||||||
AgentUtility::GenerateAgentIcingaConfig(vm["endpoint"].as<std::vector<std::string> >(), cn);
|
NodeUtility::GenerateNodeIcingaConfig(vm["endpoint"].as<std::vector<std::string> >(), cn);
|
||||||
|
|
||||||
/* update constants.conf with NodeName = CN */
|
/* update constants.conf with NodeName = CN */
|
||||||
if (cn != Utility::GetFQDN()) {
|
if (cn != Utility::GetFQDN()) {
|
||||||
@ -470,9 +470,9 @@ int AgentSetupCommand::SetupAgent(const boost::program_options::variables_map& v
|
|||||||
|
|
||||||
Log(LogInformation, "cli", "Updating constants.conf.");
|
Log(LogInformation, "cli", "Updating constants.conf.");
|
||||||
|
|
||||||
AgentUtility::CreateBackupFile(Application::GetSysconfDir() + "/icinga2/constants.conf");
|
NodeUtility::CreateBackupFile(Application::GetSysconfDir() + "/icinga2/constants.conf");
|
||||||
|
|
||||||
AgentUtility::UpdateConstant("NodeName", cn);
|
NodeUtility::UpdateConstant("NodeName", cn);
|
||||||
|
|
||||||
/* tell the user to reload icinga2 */
|
/* tell the user to reload icinga2 */
|
||||||
|
|
@ -30,10 +30,10 @@ namespace icinga
|
|||||||
*
|
*
|
||||||
* @ingroup cli
|
* @ingroup cli
|
||||||
*/
|
*/
|
||||||
class AgentSetupCommand : public CLICommand
|
class NodeSetupCommand : public CLICommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(AgentSetupCommand);
|
DECLARE_PTR_TYPEDEFS(NodeSetupCommand);
|
||||||
|
|
||||||
virtual String GetDescription(void) const;
|
virtual String GetDescription(void) const;
|
||||||
virtual String GetShortDescription(void) const;
|
virtual String GetShortDescription(void) const;
|
||||||
@ -45,7 +45,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
static int SetupMaster(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap);
|
static int SetupMaster(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap);
|
||||||
static int SetupAgent(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap);
|
static int SetupNode(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
@ -17,8 +17,8 @@
|
|||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "cli/agentupdateconfigcommand.hpp"
|
#include "cli/nodeupdateconfigcommand.hpp"
|
||||||
#include "cli/agentutility.hpp"
|
#include "cli/nodeutility.hpp"
|
||||||
#include "cli/repositoryutility.hpp"
|
#include "cli/repositoryutility.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
@ -34,19 +34,19 @@
|
|||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
REGISTER_CLICOMMAND("agent/update-config", AgentUpdateConfigCommand);
|
REGISTER_CLICOMMAND("node/update-config", NodeUpdateConfigCommand);
|
||||||
|
|
||||||
String AgentUpdateConfigCommand::GetDescription(void) const
|
String NodeUpdateConfigCommand::GetDescription(void) const
|
||||||
{
|
{
|
||||||
return "Update Icinga 2 agent config.";
|
return "Update Icinga 2 agent config.";
|
||||||
}
|
}
|
||||||
|
|
||||||
String AgentUpdateConfigCommand::GetShortDescription(void) const
|
String NodeUpdateConfigCommand::GetShortDescription(void) const
|
||||||
{
|
{
|
||||||
return "update agent config";
|
return "update agent config";
|
||||||
}
|
}
|
||||||
|
|
||||||
ImpersonationLevel AgentUpdateConfigCommand::GetImpersonationLevel(void) const
|
ImpersonationLevel NodeUpdateConfigCommand::GetImpersonationLevel(void) const
|
||||||
{
|
{
|
||||||
return ImpersonateRoot;
|
return ImpersonateRoot;
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ ImpersonationLevel AgentUpdateConfigCommand::GetImpersonationLevel(void) const
|
|||||||
*
|
*
|
||||||
* @returns An exit status.
|
* @returns An exit status.
|
||||||
*/
|
*/
|
||||||
int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
int NodeUpdateConfigCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
||||||
{
|
{
|
||||||
//If there are changes pending, abort the current operation
|
//If there are changes pending, abort the current operation
|
||||||
if (RepositoryUtility::ChangeLogHasPendingChanges()) {
|
if (RepositoryUtility::ChangeLogHasPendingChanges()) {
|
||||||
@ -67,7 +67,7 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
String inventory_path = AgentUtility::GetRepositoryPath() + "/inventory.index";
|
String inventory_path = NodeUtility::GetRepositoryPath() + "/inventory.index";
|
||||||
|
|
||||||
Dictionary::Ptr old_inventory = make_shared<Dictionary>();
|
Dictionary::Ptr old_inventory = make_shared<Dictionary>();
|
||||||
if (Utility::PathExists(inventory_path)) {
|
if (Utility::PathExists(inventory_path)) {
|
||||||
@ -79,13 +79,13 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Updating agent configuration for ";
|
<< "Updating agent configuration for ";
|
||||||
|
|
||||||
AgentUtility::PrintAgents(std::cout);
|
NodeUtility::PrintNodes(std::cout);
|
||||||
|
|
||||||
Utility::LoadExtensionLibrary("icinga");
|
Utility::LoadExtensionLibrary("icinga");
|
||||||
|
|
||||||
std::vector<String> object_paths = RepositoryUtility::GetObjects();
|
std::vector<String> object_paths = RepositoryUtility::GetObjects();
|
||||||
|
|
||||||
BOOST_FOREACH(const Dictionary::Ptr& agent, AgentUtility::GetAgents()) {
|
BOOST_FOREACH(const Dictionary::Ptr& agent, NodeUtility::GetNodes()) {
|
||||||
Dictionary::Ptr repository = agent->Get("repository");
|
Dictionary::Ptr repository = agent->Get("repository");
|
||||||
String zone = agent->Get("zone");
|
String zone = agent->Get("zone");
|
||||||
String endpoint = agent->Get("endpoint");
|
String endpoint = agent->Get("endpoint");
|
||||||
@ -138,8 +138,8 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||||||
skip_host = true;
|
skip_host = true;
|
||||||
|
|
||||||
/* check against black/whitelist before trying to add host */
|
/* check against black/whitelist before trying to add host */
|
||||||
if (AgentUtility::CheckAgainstBlackAndWhiteList("blacklist", agent_name, host, Empty) &&
|
if (NodeUtility::CheckAgainstBlackAndWhiteList("blacklist", agent_name, host, Empty) &&
|
||||||
!AgentUtility::CheckAgainstBlackAndWhiteList("whitelist", agent_name, host, Empty)) {
|
!NodeUtility::CheckAgainstBlackAndWhiteList("whitelist", agent_name, host, Empty)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
<< "Host '" << host << "' on agent '" << agent_name << "' is blacklisted, but not whitelisted. Skipping.";
|
<< "Host '" << host << "' on agent '" << agent_name << "' is blacklisted, but not whitelisted. Skipping.";
|
||||||
skip_host = true;
|
skip_host = true;
|
||||||
@ -192,8 +192,8 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check against black/whitelist before trying to add service */
|
/* check against black/whitelist before trying to add service */
|
||||||
if (AgentUtility::CheckAgainstBlackAndWhiteList("blacklist", endpoint, host, service) &&
|
if (NodeUtility::CheckAgainstBlackAndWhiteList("blacklist", endpoint, host, service) &&
|
||||||
!AgentUtility::CheckAgainstBlackAndWhiteList("whitelist", endpoint, host, service)) {
|
!NodeUtility::CheckAgainstBlackAndWhiteList("whitelist", endpoint, host, service)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
<< "Service '" << service << "' on host '" << host << "' on agent '"
|
<< "Service '" << service << "' on host '" << host << "' on agent '"
|
||||||
<< agent_name << "' is blacklisted, but not whitelisted. Skipping.";
|
<< agent_name << "' is blacklisted, but not whitelisted. Skipping.";
|
||||||
@ -256,14 +256,14 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||||||
|
|
||||||
if (!agent->Contains("parent_zone")) {
|
if (!agent->Contains("parent_zone")) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
<< "Agent '" << endpoint << "' does not have any parent zone defined. Using 'master' as default. Please verify the generated configuration.";
|
<< "Node '" << endpoint << "' does not have any parent zone defined. Using 'master' as default. Please verify the generated configuration.";
|
||||||
parent_zone = agent_parent_zone;
|
parent_zone = agent_parent_zone;
|
||||||
} else {
|
} else {
|
||||||
parent_zone = agent->Get("parent_zone");
|
parent_zone = agent->Get("parent_zone");
|
||||||
|
|
||||||
if (parent_zone.IsEmpty()) {
|
if (parent_zone.IsEmpty()) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
<< "Agent '" << endpoint << "' does not have any parent zone defined. Using 'master' as default. Please verify the generated configuration.";
|
<< "Node '" << endpoint << "' does not have any parent zone defined. Using 'master' as default. Please verify the generated configuration.";
|
||||||
parent_zone = agent_parent_zone;
|
parent_zone = agent_parent_zone;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -284,7 +284,7 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||||||
/* check if the agent was dropped */
|
/* check if the agent was dropped */
|
||||||
if (!inventory->Contains(old_agent_name)) {
|
if (!inventory->Contains(old_agent_name)) {
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Agent update found old agent '" << old_agent_name << "'. Removing it and all of its hosts/services.";
|
<< "Node update found old agent '" << old_agent_name << "'. Removing it and all of its hosts/services.";
|
||||||
|
|
||||||
//TODO Remove an agent and all of his hosts
|
//TODO Remove an agent and all of his hosts
|
||||||
Dictionary::Ptr old_agent = old_inventory->Get(old_agent_name);
|
Dictionary::Ptr old_agent = old_inventory->Get(old_agent_name);
|
||||||
@ -328,8 +328,8 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check against black/whitelist before trying to remove host */
|
/* check against black/whitelist before trying to remove host */
|
||||||
if (AgentUtility::CheckAgainstBlackAndWhiteList("blacklist", old_agent_name, old_host, Empty) &&
|
if (NodeUtility::CheckAgainstBlackAndWhiteList("blacklist", old_agent_name, old_host, Empty) &&
|
||||||
!AgentUtility::CheckAgainstBlackAndWhiteList("whitelist", old_agent_name, old_host, Empty)) {
|
!NodeUtility::CheckAgainstBlackAndWhiteList("whitelist", old_agent_name, old_host, Empty)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
<< "Host '" << old_agent << "' on agent '" << old_agent << "' is blacklisted, but not whitelisted. Skipping.";
|
<< "Host '" << old_agent << "' on agent '" << old_agent << "' is blacklisted, but not whitelisted. Skipping.";
|
||||||
continue;
|
continue;
|
||||||
@ -337,7 +337,7 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||||||
|
|
||||||
if (!new_agent_repository->Contains(old_host)) {
|
if (!new_agent_repository->Contains(old_host)) {
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Agent update found old host '" << old_host << "' on agent '" << old_agent_name << "'. Removing it.";
|
<< "Node update found old host '" << old_host << "' on agent '" << old_agent_name << "'. Removing it.";
|
||||||
|
|
||||||
Dictionary::Ptr host_attrs = make_shared<Dictionary>();
|
Dictionary::Ptr host_attrs = make_shared<Dictionary>();
|
||||||
host_attrs->Set("name", old_host);
|
host_attrs->Set("name", old_host);
|
||||||
@ -350,8 +350,8 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||||||
ObjectLock ylock(old_services);
|
ObjectLock ylock(old_services);
|
||||||
BOOST_FOREACH(const String& old_service, old_services) {
|
BOOST_FOREACH(const String& old_service, old_services) {
|
||||||
/* check against black/whitelist before trying to remove service */
|
/* check against black/whitelist before trying to remove service */
|
||||||
if (AgentUtility::CheckAgainstBlackAndWhiteList("blacklist", old_agent_name, old_host, old_service) &&
|
if (NodeUtility::CheckAgainstBlackAndWhiteList("blacklist", old_agent_name, old_host, old_service) &&
|
||||||
!AgentUtility::CheckAgainstBlackAndWhiteList("whitelist", old_agent_name, old_host, old_service)) {
|
!NodeUtility::CheckAgainstBlackAndWhiteList("whitelist", old_agent_name, old_host, old_service)) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
<< "Service '" << old_service << "' on host '" << old_host << "' on agent '"
|
<< "Service '" << old_service << "' on host '" << old_host << "' on agent '"
|
||||||
<< old_agent_name << "' is blacklisted, but not whitelisted. Skipping.";
|
<< old_agent_name << "' is blacklisted, but not whitelisted. Skipping.";
|
||||||
@ -360,7 +360,7 @@ int AgentUpdateConfigCommand::Run(const boost::program_options::variables_map& v
|
|||||||
|
|
||||||
if (!new_services->Contains(old_service)) {
|
if (!new_services->Contains(old_service)) {
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Agent update found old service '" << old_service << "' on host '" << old_host
|
<< "Node update found old service '" << old_service << "' on host '" << old_host
|
||||||
<< "' on agent '" << old_agent_name << "'. Removing it.";
|
<< "' on agent '" << old_agent_name << "'. Removing it.";
|
||||||
|
|
||||||
Dictionary::Ptr service_attrs = make_shared<Dictionary>();
|
Dictionary::Ptr service_attrs = make_shared<Dictionary>();
|
@ -30,10 +30,10 @@ namespace icinga
|
|||||||
*
|
*
|
||||||
* @ingroup cli
|
* @ingroup cli
|
||||||
*/
|
*/
|
||||||
class AgentUpdateConfigCommand : public CLICommand
|
class NodeUpdateConfigCommand : public CLICommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(AgentUpdateConfigCommand);
|
DECLARE_PTR_TYPEDEFS(NodeUpdateConfigCommand);
|
||||||
|
|
||||||
virtual String GetDescription(void) const;
|
virtual String GetDescription(void) const;
|
||||||
virtual String GetShortDescription(void) const;
|
virtual String GetShortDescription(void) const;
|
@ -17,7 +17,7 @@
|
|||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "cli/agentutility.hpp"
|
#include "cli/nodeutility.hpp"
|
||||||
#include "cli/clicommand.hpp"
|
#include "cli/clicommand.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
#include "base/application.hpp"
|
#include "base/application.hpp"
|
||||||
@ -40,50 +40,50 @@
|
|||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
String AgentUtility::GetRepositoryPath(void)
|
String NodeUtility::GetRepositoryPath(void)
|
||||||
{
|
{
|
||||||
return Application::GetLocalStateDir() + "/lib/icinga2/api/repository";
|
return Application::GetLocalStateDir() + "/lib/icinga2/api/repository";
|
||||||
}
|
}
|
||||||
|
|
||||||
String AgentUtility::GetAgentRepositoryFile(const String& name)
|
String NodeUtility::GetNodeRepositoryFile(const String& name)
|
||||||
{
|
{
|
||||||
return GetRepositoryPath() + "/" + SHA256(name) + ".repo";
|
return GetRepositoryPath() + "/" + SHA256(name) + ".repo";
|
||||||
}
|
}
|
||||||
|
|
||||||
String AgentUtility::GetAgentSettingsFile(const String& name)
|
String NodeUtility::GetNodeSettingsFile(const String& name)
|
||||||
{
|
{
|
||||||
return GetRepositoryPath() + "/" + SHA256(name) + ".settings";
|
return GetRepositoryPath() + "/" + SHA256(name) + ".settings";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<String> AgentUtility::GetAgentCompletionSuggestions(const String& word)
|
std::vector<String> NodeUtility::GetNodeCompletionSuggestions(const String& word)
|
||||||
{
|
{
|
||||||
std::vector<String> suggestions;
|
std::vector<String> suggestions;
|
||||||
|
|
||||||
BOOST_FOREACH(const Dictionary::Ptr& agent, GetAgents()) {
|
BOOST_FOREACH(const Dictionary::Ptr& node, GetNodes()) {
|
||||||
String agent_name = agent->Get("endpoint");
|
String node_name = node->Get("endpoint");
|
||||||
|
|
||||||
if (agent_name.Find(word) == 0)
|
if (node_name.Find(word) == 0)
|
||||||
suggestions.push_back(agent_name);
|
suggestions.push_back(node_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return suggestions;
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentUtility::PrintAgents(std::ostream& fp)
|
void NodeUtility::PrintNodes(std::ostream& fp)
|
||||||
{
|
{
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
|
||||||
BOOST_FOREACH(const Dictionary::Ptr& agent, GetAgents()) {
|
BOOST_FOREACH(const Dictionary::Ptr& node, GetNodes()) {
|
||||||
if (first)
|
if (first)
|
||||||
first = false;
|
first = false;
|
||||||
else
|
else
|
||||||
fp << "\n";
|
fp << "\n";
|
||||||
|
|
||||||
fp << "Agent '"
|
fp << "Node '"
|
||||||
<< ConsoleColorTag(Console_ForegroundBlue | Console_Bold) << agent->Get("endpoint") << ConsoleColorTag(Console_Normal)
|
<< ConsoleColorTag(Console_ForegroundBlue | Console_Bold) << node->Get("endpoint") << ConsoleColorTag(Console_Normal)
|
||||||
<< "' (";
|
<< "' (";
|
||||||
|
|
||||||
Dictionary::Ptr settings = agent->Get("settings");
|
Dictionary::Ptr settings = node->Get("settings");
|
||||||
|
|
||||||
if (settings) {
|
if (settings) {
|
||||||
String host = settings->Get("host");
|
String host = settings->Get("host");
|
||||||
@ -96,13 +96,13 @@ void AgentUtility::PrintAgents(std::ostream& fp)
|
|||||||
fp << "log duration: " << Utility::FormatDuration(log_duration) << ", ";
|
fp << "log duration: " << Utility::FormatDuration(log_duration) << ", ";
|
||||||
}
|
}
|
||||||
|
|
||||||
fp << "last seen: " << Utility::FormatDateTime("%c", agent->Get("seen")) << ")\n";
|
fp << "last seen: " << Utility::FormatDateTime("%c", node->Get("seen")) << ")\n";
|
||||||
|
|
||||||
PrintAgentRepository(fp, agent->Get("repository"));
|
PrintNodeRepository(fp, node->Get("repository"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentUtility::PrintAgentRepository(std::ostream& fp, const Dictionary::Ptr& repository)
|
void NodeUtility::PrintNodeRepository(std::ostream& fp, const Dictionary::Ptr& repository)
|
||||||
{
|
{
|
||||||
if (!repository)
|
if (!repository)
|
||||||
return;
|
return;
|
||||||
@ -120,37 +120,37 @@ void AgentUtility::PrintAgentRepository(std::ostream& fp, const Dictionary::Ptr&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentUtility::PrintAgentsJson(std::ostream& fp)
|
void NodeUtility::PrintNodesJson(std::ostream& fp)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr result = make_shared<Dictionary>();
|
Dictionary::Ptr result = make_shared<Dictionary>();
|
||||||
|
|
||||||
BOOST_FOREACH(const Dictionary::Ptr& agent, GetAgents()) {
|
BOOST_FOREACH(const Dictionary::Ptr& node, GetNodes()) {
|
||||||
result->Set(agent->Get("endpoint"), agent);
|
result->Set(node->Get("endpoint"), node);
|
||||||
}
|
}
|
||||||
|
|
||||||
fp << JsonEncode(result);
|
fp << JsonEncode(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentUtility::AddAgent(const String& name)
|
void NodeUtility::AddNode(const String& name)
|
||||||
{
|
{
|
||||||
String path = GetAgentRepositoryFile(name);
|
String path = GetNodeRepositoryFile(name);
|
||||||
|
|
||||||
if (Utility::PathExists(path) ) {
|
if (Utility::PathExists(path) ) {
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Agent '" << name << "' exists already.";
|
<< "Node '" << name << "' exists already.";
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr agent = make_shared<Dictionary>();
|
Dictionary::Ptr node = make_shared<Dictionary>();
|
||||||
|
|
||||||
agent->Set("seen", Utility::GetTime());
|
node->Set("seen", Utility::GetTime());
|
||||||
agent->Set("endpoint", name);
|
node->Set("endpoint", name);
|
||||||
agent->Set("zone", name);
|
node->Set("zone", name);
|
||||||
agent->Set("repository", Empty);
|
node->Set("repository", Empty);
|
||||||
|
|
||||||
Utility::SaveJsonFile(path, agent);
|
Utility::SaveJsonFile(path, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentUtility::AddAgentSettings(const String& name, const String& host,
|
void NodeUtility::AddNodeSettings(const String& name, const String& host,
|
||||||
const String& port, double log_duration)
|
const String& port, double log_duration)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr settings = make_shared<Dictionary>();
|
Dictionary::Ptr settings = make_shared<Dictionary>();
|
||||||
@ -159,12 +159,12 @@ void AgentUtility::AddAgentSettings(const String& name, const String& host,
|
|||||||
settings->Set("port", port);
|
settings->Set("port", port);
|
||||||
settings->Set("log_duration", log_duration);
|
settings->Set("log_duration", log_duration);
|
||||||
|
|
||||||
Utility::SaveJsonFile(GetAgentSettingsFile(name), settings);
|
Utility::SaveJsonFile(GetNodeSettingsFile(name), settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentUtility::RemoveAgent(const String& name)
|
void NodeUtility::RemoveNode(const String& name)
|
||||||
{
|
{
|
||||||
String repoPath = GetAgentRepositoryFile(name);
|
String repoPath = GetNodeRepositoryFile(name);
|
||||||
|
|
||||||
if (!Utility::PathExists(repoPath))
|
if (!Utility::PathExists(repoPath))
|
||||||
return;
|
return;
|
||||||
@ -179,7 +179,7 @@ void AgentUtility::RemoveAgent(const String& name)
|
|||||||
<< boost::errinfo_file_name(repoPath));
|
<< boost::errinfo_file_name(repoPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
String settingsPath = GetAgentSettingsFile(name);
|
String settingsPath = GetNodeSettingsFile(name);
|
||||||
|
|
||||||
if (Utility::PathExists(settingsPath)) {
|
if (Utility::PathExists(settingsPath)) {
|
||||||
if (unlink(settingsPath.CStr()) < 0) {
|
if (unlink(settingsPath.CStr()) < 0) {
|
||||||
@ -194,36 +194,36 @@ void AgentUtility::RemoveAgent(const String& name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Dictionary::Ptr> AgentUtility::GetAgents(void)
|
std::vector<Dictionary::Ptr> NodeUtility::GetNodes(void)
|
||||||
{
|
{
|
||||||
std::vector<Dictionary::Ptr> agents;
|
std::vector<Dictionary::Ptr> nodes;
|
||||||
|
|
||||||
Utility::Glob(GetRepositoryPath() + "/*.repo",
|
Utility::Glob(GetRepositoryPath() + "/*.repo",
|
||||||
boost::bind(&AgentUtility::CollectAgents, _1, boost::ref(agents)), GlobFile);
|
boost::bind(&NodeUtility::CollectNodes, _1, boost::ref(nodes)), GlobFile);
|
||||||
|
|
||||||
return agents;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr AgentUtility::LoadAgentFile(const String& agent_file)
|
Dictionary::Ptr NodeUtility::LoadNodeFile(const String& node_file)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr agent = Utility::LoadJsonFile(agent_file);
|
Dictionary::Ptr node = Utility::LoadJsonFile(node_file);
|
||||||
|
|
||||||
if (!agent)
|
if (!node)
|
||||||
return Dictionary::Ptr();
|
return Dictionary::Ptr();
|
||||||
|
|
||||||
String settingsFile = GetAgentSettingsFile(agent->Get("endpoint"));
|
String settingsFile = GetNodeSettingsFile(node->Get("endpoint"));
|
||||||
|
|
||||||
if (Utility::PathExists(settingsFile))
|
if (Utility::PathExists(settingsFile))
|
||||||
agent->Set("settings", Utility::LoadJsonFile(settingsFile));
|
node->Set("settings", Utility::LoadJsonFile(settingsFile));
|
||||||
else
|
else
|
||||||
agent->Remove("settings");
|
node->Remove("settings");
|
||||||
|
|
||||||
return agent;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentUtility::CollectAgents(const String& agent_file, std::vector<Dictionary::Ptr>& agents)
|
void NodeUtility::CollectNodes(const String& agent_file, std::vector<Dictionary::Ptr>& agents)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr agent = LoadAgentFile(agent_file);
|
Dictionary::Ptr agent = LoadNodeFile(agent_file);
|
||||||
|
|
||||||
if (!agent)
|
if (!agent)
|
||||||
return;
|
return;
|
||||||
@ -232,10 +232,10 @@ void AgentUtility::CollectAgents(const String& agent_file, std::vector<Dictionar
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Agent Setup helpers
|
* Node Setup helpers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int AgentUtility::GenerateAgentIcingaConfig(const std::vector<std::string>& endpoints, const String& nodename)
|
int NodeUtility::GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints, const String& nodename)
|
||||||
{
|
{
|
||||||
Array::Ptr my_config = make_shared<Array>();
|
Array::Ptr my_config = make_shared<Array>();
|
||||||
|
|
||||||
@ -305,12 +305,12 @@ int AgentUtility::GenerateAgentIcingaConfig(const std::vector<std::string>& endp
|
|||||||
/* write the newly generated configuration */
|
/* write the newly generated configuration */
|
||||||
String zones_path = Application::GetSysconfDir() + "/icinga2/zones.conf";
|
String zones_path = Application::GetSysconfDir() + "/icinga2/zones.conf";
|
||||||
|
|
||||||
AgentUtility::WriteAgentConfigObjects(zones_path, my_config);
|
NodeUtility::WriteNodeConfigObjects(zones_path, my_config);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AgentUtility::GenerateAgentMasterIcingaConfig(const String& nodename)
|
int NodeUtility::GenerateNodeMasterIcingaConfig(const String& nodename)
|
||||||
{
|
{
|
||||||
Array::Ptr my_config = make_shared<Array>();
|
Array::Ptr my_config = make_shared<Array>();
|
||||||
|
|
||||||
@ -336,7 +336,7 @@ int AgentUtility::GenerateAgentMasterIcingaConfig(const String& nodename)
|
|||||||
/* write the newly generated configuration */
|
/* write the newly generated configuration */
|
||||||
String zones_path = Application::GetSysconfDir() + "/icinga2/zones.conf";
|
String zones_path = Application::GetSysconfDir() + "/icinga2/zones.conf";
|
||||||
|
|
||||||
AgentUtility::WriteAgentConfigObjects(zones_path, my_config);
|
NodeUtility::WriteNodeConfigObjects(zones_path, my_config);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -345,7 +345,7 @@ int AgentUtility::GenerateAgentMasterIcingaConfig(const String& nodename)
|
|||||||
* This is ugly and requires refactoring into a generic config writer class.
|
* This is ugly and requires refactoring into a generic config writer class.
|
||||||
* TODO.
|
* TODO.
|
||||||
*/
|
*/
|
||||||
bool AgentUtility::WriteAgentConfigObjects(const String& filename, const Array::Ptr& objects)
|
bool NodeUtility::WriteNodeConfigObjects(const String& filename, const Array::Ptr& objects)
|
||||||
{
|
{
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Dumping config items to file '" << filename << "'.";
|
<< "Dumping config items to file '" << filename << "'.";
|
||||||
@ -393,12 +393,12 @@ bool AgentUtility::WriteAgentConfigObjects(const String& filename, const Array::
|
|||||||
/*
|
/*
|
||||||
* Black/Whitelist helpers
|
* Black/Whitelist helpers
|
||||||
*/
|
*/
|
||||||
String AgentUtility::GetBlackAndWhiteListPath(const String& type)
|
String NodeUtility::GetBlackAndWhiteListPath(const String& type)
|
||||||
{
|
{
|
||||||
return AgentUtility::GetRepositoryPath() + "/" + type + ".list";
|
return NodeUtility::GetRepositoryPath() + "/" + type + ".list";
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr AgentUtility::GetBlackAndWhiteList(const String& type)
|
Dictionary::Ptr NodeUtility::GetBlackAndWhiteList(const String& type)
|
||||||
{
|
{
|
||||||
String list_path = GetBlackAndWhiteListPath(type);
|
String list_path = GetBlackAndWhiteListPath(type);
|
||||||
|
|
||||||
@ -411,7 +411,7 @@ Dictionary::Ptr AgentUtility::GetBlackAndWhiteList(const String& type)
|
|||||||
return lists;
|
return lists;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AgentUtility::UpdateBlackAndWhiteList(const String& type, const String& agent_filter, const String& host_filter, const String& service_filter)
|
int NodeUtility::UpdateBlackAndWhiteList(const String& type, const String& agent_filter, const String& host_filter, const String& service_filter)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr lists = GetBlackAndWhiteList(type);
|
Dictionary::Ptr lists = GetBlackAndWhiteList(type);
|
||||||
|
|
||||||
@ -446,7 +446,7 @@ int AgentUtility::UpdateBlackAndWhiteList(const String& type, const String& agen
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AgentUtility::RemoveBlackAndWhiteList(const String& type, const String& agent_filter, const String& host_filter, const String& service_filter)
|
int NodeUtility::RemoveBlackAndWhiteList(const String& type, const String& agent_filter, const String& host_filter, const String& service_filter)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr lists = GetBlackAndWhiteList(type);
|
Dictionary::Ptr lists = GetBlackAndWhiteList(type);
|
||||||
|
|
||||||
@ -477,7 +477,7 @@ int AgentUtility::RemoveBlackAndWhiteList(const String& type, const String& agen
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AgentUtility::PrintBlackAndWhiteList(std::ostream& fp, const String& type)
|
int NodeUtility::PrintBlackAndWhiteList(std::ostream& fp, const String& type)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr lists = GetBlackAndWhiteList(type);
|
Dictionary::Ptr lists = GetBlackAndWhiteList(type);
|
||||||
|
|
||||||
@ -488,14 +488,14 @@ int AgentUtility::PrintBlackAndWhiteList(std::ostream& fp, const String& type)
|
|||||||
String agent_filter = kv.first;
|
String agent_filter = kv.first;
|
||||||
Dictionary::Ptr host_service = kv.second;
|
Dictionary::Ptr host_service = kv.second;
|
||||||
|
|
||||||
fp << "Agent " << type << ": '" << agent_filter << "' Host: '"
|
fp << "Node " << type << ": '" << agent_filter << "' Host: '"
|
||||||
<< host_service->Get("host_filter") << "' Service: '" << host_service->Get("service_filter") << "'.\n";
|
<< host_service->Get("host_filter") << "' Service: '" << host_service->Get("service_filter") << "'.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AgentUtility::CheckAgainstBlackAndWhiteList(const String& type, const String& agent, const String& host, const String& service)
|
bool NodeUtility::CheckAgainstBlackAndWhiteList(const String& type, const String& agent, const String& host, const String& service)
|
||||||
{
|
{
|
||||||
Dictionary::Ptr lists = GetBlackAndWhiteList(type);
|
Dictionary::Ptr lists = GetBlackAndWhiteList(type);
|
||||||
|
|
||||||
@ -513,12 +513,12 @@ bool AgentUtility::CheckAgainstBlackAndWhiteList(const String& type, const Strin
|
|||||||
service_filter = host_service->Get("service_filter");
|
service_filter = host_service->Get("service_filter");
|
||||||
|
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Checking Agent '" << agent << "' =~ '" << agent_filter << "', host '" << host << "' =~ '" << host_filter
|
<< "Checking Node '" << agent << "' =~ '" << agent_filter << "', host '" << host << "' =~ '" << host_filter
|
||||||
<< "', service '" << service << "' =~ '" << service_filter << "'.";
|
<< "', service '" << service << "' =~ '" << service_filter << "'.";
|
||||||
|
|
||||||
if (Utility::Match(agent_filter, agent)) {
|
if (Utility::Match(agent_filter, agent)) {
|
||||||
Log(LogNotice, "cli")
|
Log(LogNotice, "cli")
|
||||||
<< "Agent '" << agent << "' matches filter '" << agent_filter << "'";
|
<< "Node '" << agent << "' matches filter '" << agent_filter << "'";
|
||||||
|
|
||||||
if (Utility::Match(host_filter, host)) {
|
if (Utility::Match(host_filter, host)) {
|
||||||
Log(LogNotice, "cli")
|
Log(LogNotice, "cli")
|
||||||
@ -545,7 +545,7 @@ bool AgentUtility::CheckAgainstBlackAndWhiteList(const String& type, const Strin
|
|||||||
/*
|
/*
|
||||||
* We generally don't overwrite files without backup before
|
* We generally don't overwrite files without backup before
|
||||||
*/
|
*/
|
||||||
bool AgentUtility::CreateBackupFile(const String& target)
|
bool NodeUtility::CreateBackupFile(const String& target)
|
||||||
{
|
{
|
||||||
if (!Utility::PathExists(target))
|
if (!Utility::PathExists(target))
|
||||||
return false;
|
return false;
|
||||||
@ -566,7 +566,7 @@ bool AgentUtility::CreateBackupFile(const String& target)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentUtility::SerializeObject(std::ostream& fp, const String& name, const String& type, const Dictionary::Ptr& object)
|
void NodeUtility::SerializeObject(std::ostream& fp, const String& name, const String& type, const Dictionary::Ptr& object)
|
||||||
{
|
{
|
||||||
fp << "object " << type << " \"" << name << "\" {\n";
|
fp << "object " << type << " \"" << name << "\" {\n";
|
||||||
ObjectLock olock(object);
|
ObjectLock olock(object);
|
||||||
@ -581,7 +581,7 @@ void AgentUtility::SerializeObject(std::ostream& fp, const String& name, const S
|
|||||||
fp << "}\n\n";
|
fp << "}\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentUtility::FormatValue(std::ostream& fp, const Value& val)
|
void NodeUtility::FormatValue(std::ostream& fp, const Value& val)
|
||||||
{
|
{
|
||||||
if (val.IsObjectType<Array>()) {
|
if (val.IsObjectType<Array>()) {
|
||||||
FormatArray(fp, val);
|
FormatArray(fp, val);
|
||||||
@ -596,7 +596,7 @@ void AgentUtility::FormatValue(std::ostream& fp, const Value& val)
|
|||||||
fp << Convert::ToString(val);
|
fp << Convert::ToString(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentUtility::FormatArray(std::ostream& fp, const Array::Ptr& arr)
|
void NodeUtility::FormatArray(std::ostream& fp, const Array::Ptr& arr)
|
||||||
{
|
{
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
|
||||||
@ -620,7 +620,7 @@ void AgentUtility::FormatArray(std::ostream& fp, const Array::Ptr& arr)
|
|||||||
fp << "]";
|
fp << "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgentUtility::UpdateConstant(const String& name, const String& value)
|
void NodeUtility::UpdateConstant(const String& name, const String& value)
|
||||||
{
|
{
|
||||||
String constantsFile = Application::GetSysconfDir() + "/icinga2/constants.conf";
|
String constantsFile = Application::GetSysconfDir() + "/icinga2/constants.conf";
|
||||||
String tempFile = constantsFile + ".tmp";
|
String tempFile = constantsFile + ".tmp";
|
@ -33,32 +33,32 @@ namespace icinga
|
|||||||
/**
|
/**
|
||||||
* @ingroup cli
|
* @ingroup cli
|
||||||
*/
|
*/
|
||||||
class AgentUtility
|
class NodeUtility
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static String GetRepositoryPath(void);
|
static String GetRepositoryPath(void);
|
||||||
static String GetAgentRepositoryFile(const String& name);
|
static String GetNodeRepositoryFile(const String& name);
|
||||||
static String GetAgentSettingsFile(const String& name);
|
static String GetNodeSettingsFile(const String& name);
|
||||||
static std::vector<String> GetAgentCompletionSuggestions(const String& word);
|
static std::vector<String> GetNodeCompletionSuggestions(const String& word);
|
||||||
|
|
||||||
static void PrintAgents(std::ostream& fp);
|
static void PrintNodes(std::ostream& fp);
|
||||||
static void PrintAgentsJson(std::ostream& fp);
|
static void PrintNodesJson(std::ostream& fp);
|
||||||
static void PrintAgentRepository(std::ostream& fp, const Dictionary::Ptr& repository);
|
static void PrintNodeRepository(std::ostream& fp, const Dictionary::Ptr& repository);
|
||||||
static void AddAgent(const String& name);
|
static void AddNode(const String& name);
|
||||||
static void AddAgentSettings(const String& name, const String& host, const String& port, double log_duration);
|
static void AddNodeSettings(const String& name, const String& host, const String& port, double log_duration);
|
||||||
static void RemoveAgent(const String& name);
|
static void RemoveNode(const String& name);
|
||||||
|
|
||||||
static std::vector<Dictionary::Ptr> GetAgents(void);
|
static std::vector<Dictionary::Ptr> GetNodes(void);
|
||||||
|
|
||||||
static bool CreateBackupFile(const String& target);
|
static bool CreateBackupFile(const String& target);
|
||||||
|
|
||||||
static bool WriteAgentConfigObjects(const String& filename, const Array::Ptr& objects);
|
static bool WriteNodeConfigObjects(const String& filename, const Array::Ptr& objects);
|
||||||
|
|
||||||
static void UpdateConstant(const String& name, const String& value);
|
static void UpdateConstant(const String& name, const String& value);
|
||||||
|
|
||||||
/* agent setup helpers */
|
/* agent setup helpers */
|
||||||
static int GenerateAgentIcingaConfig(const std::vector<std::string>& endpoints, const String& nodename);
|
static int GenerateNodeIcingaConfig(const std::vector<std::string>& endpoints, const String& nodename);
|
||||||
static int GenerateAgentMasterIcingaConfig(const String& nodename);
|
static int GenerateNodeMasterIcingaConfig(const String& nodename);
|
||||||
|
|
||||||
/* black/whitelist */
|
/* black/whitelist */
|
||||||
static String GetBlackAndWhiteListPath(const String& type);
|
static String GetBlackAndWhiteListPath(const String& type);
|
||||||
@ -72,10 +72,10 @@ public:
|
|||||||
static bool CheckAgainstBlackAndWhiteList(const String& type, const String& agent, const String& host, const String& service);
|
static bool CheckAgainstBlackAndWhiteList(const String& type, const String& agent, const String& host, const String& service);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AgentUtility(void);
|
NodeUtility(void);
|
||||||
static bool RemoveAgentFile(const String& path);
|
static bool RemoveNodeFile(const String& path);
|
||||||
static Dictionary::Ptr LoadAgentFile(const String& agent_file);
|
static Dictionary::Ptr LoadNodeFile(const String& agent_file);
|
||||||
static void CollectAgents(const String& agent_file, std::vector<Dictionary::Ptr>& agents);
|
static void CollectNodes(const String& agent_file, std::vector<Dictionary::Ptr>& agents);
|
||||||
|
|
||||||
static void SerializeObject(std::ostream& fp, const String& name, const String& type, const Dictionary::Ptr& object);
|
static void SerializeObject(std::ostream& fp, const String& name, const String& type, const Dictionary::Ptr& object);
|
||||||
static void FormatValue(std::ostream& fp, const Value& val);
|
static void FormatValue(std::ostream& fp, const Value& val);
|
@ -17,8 +17,8 @@
|
|||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "cli/agentwizardcommand.hpp"
|
#include "cli/nodewizardcommand.hpp"
|
||||||
#include "cli/agentutility.hpp"
|
#include "cli/nodeutility.hpp"
|
||||||
#include "cli/pkiutility.hpp"
|
#include "cli/pkiutility.hpp"
|
||||||
#include "cli/featureutility.hpp"
|
#include "cli/featureutility.hpp"
|
||||||
#include "base/logger.hpp"
|
#include "base/logger.hpp"
|
||||||
@ -38,24 +38,24 @@
|
|||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
REGISTER_CLICOMMAND("agent/wizard", AgentWizardCommand);
|
REGISTER_CLICOMMAND("node/wizard", NodeWizardCommand);
|
||||||
|
|
||||||
String AgentWizardCommand::GetDescription(void) const
|
String NodeWizardCommand::GetDescription(void) const
|
||||||
{
|
{
|
||||||
return "Wizard for Icinga 2 agent setup.";
|
return "Wizard for Icinga 2 agent setup.";
|
||||||
}
|
}
|
||||||
|
|
||||||
String AgentWizardCommand::GetShortDescription(void) const
|
String NodeWizardCommand::GetShortDescription(void) const
|
||||||
{
|
{
|
||||||
return "wizard for agent setup";
|
return "wizard for agent setup";
|
||||||
}
|
}
|
||||||
|
|
||||||
ImpersonationLevel AgentWizardCommand::GetImpersonationLevel(void) const
|
ImpersonationLevel NodeWizardCommand::GetImpersonationLevel(void) const
|
||||||
{
|
{
|
||||||
return ImpersonateRoot;
|
return ImpersonateRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AgentWizardCommand::GetMaxArguments(void) const
|
int NodeWizardCommand::GetMaxArguments(void) const
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ int AgentWizardCommand::GetMaxArguments(void) const
|
|||||||
*
|
*
|
||||||
* @returns An exit status.
|
* @returns An exit status.
|
||||||
*/
|
*/
|
||||||
int AgentWizardCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
int NodeWizardCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* The wizard will get all information from the user,
|
* The wizard will get all information from the user,
|
||||||
@ -112,7 +112,7 @@ int AgentWizardCommand::Run(const boost::program_options::variables_map& vm, con
|
|||||||
|
|
||||||
if (is_agent_setup) {
|
if (is_agent_setup) {
|
||||||
/* agent setup part */
|
/* agent setup part */
|
||||||
std::cout << "Starting the Agent setup routine...\n";
|
std::cout << "Starting the Node setup routine...\n";
|
||||||
|
|
||||||
/* CN */
|
/* CN */
|
||||||
std::cout << "Please specifiy the common name (CN) [" << Utility::GetFQDN() << "]: ";
|
std::cout << "Please specifiy the common name (CN) [" << Utility::GetFQDN() << "]: ";
|
||||||
@ -348,7 +348,7 @@ wizard_ticket:
|
|||||||
FeatureUtility::EnableFeatures(enable);
|
FeatureUtility::EnableFeatures(enable);
|
||||||
|
|
||||||
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
||||||
AgentUtility::CreateBackupFile(apipath);
|
NodeUtility::CreateBackupFile(apipath);
|
||||||
|
|
||||||
String apipathtmp = apipath + ".tmp";
|
String apipathtmp = apipath + ".tmp";
|
||||||
|
|
||||||
@ -388,7 +388,7 @@ wizard_ticket:
|
|||||||
/* apilistener config */
|
/* apilistener config */
|
||||||
std::cout << "Generating local zones.conf.\n";
|
std::cout << "Generating local zones.conf.\n";
|
||||||
|
|
||||||
AgentUtility::GenerateAgentIcingaConfig(endpoints, cn);
|
NodeUtility::GenerateNodeIcingaConfig(endpoints, cn);
|
||||||
|
|
||||||
if (cn != Utility::GetFQDN()) {
|
if (cn != Utility::GetFQDN()) {
|
||||||
Log(LogWarning, "cli")
|
Log(LogWarning, "cli")
|
||||||
@ -397,9 +397,9 @@ wizard_ticket:
|
|||||||
|
|
||||||
std::cout << "Updating constants.conf\n";
|
std::cout << "Updating constants.conf\n";
|
||||||
|
|
||||||
AgentUtility::CreateBackupFile(Application::GetSysconfDir() + "/icinga2/constants.conf");
|
NodeUtility::CreateBackupFile(Application::GetSysconfDir() + "/icinga2/constants.conf");
|
||||||
|
|
||||||
AgentUtility::UpdateConstant("NodeName", cn);
|
NodeUtility::UpdateConstant("NodeName", cn);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* master setup */
|
/* master setup */
|
||||||
@ -493,7 +493,7 @@ wizard_ticket:
|
|||||||
<< "Cannot set ownership for user '" << user << "' group '" << group << "' on file '" << csr << "'. Verify it yourself!";
|
<< "Cannot set ownership for user '" << user << "' group '" << group << "' on file '" << csr << "'. Verify it yourself!";
|
||||||
}
|
}
|
||||||
|
|
||||||
AgentUtility::GenerateAgentMasterIcingaConfig(cn);
|
NodeUtility::GenerateNodeMasterIcingaConfig(cn);
|
||||||
|
|
||||||
/* apilistener config */
|
/* apilistener config */
|
||||||
std::cout << "Please specify the API bind host/port (optional):\n";
|
std::cout << "Please specify the API bind host/port (optional):\n";
|
||||||
@ -520,7 +520,7 @@ wizard_ticket:
|
|||||||
FeatureUtility::EnableFeatures(enable);
|
FeatureUtility::EnableFeatures(enable);
|
||||||
|
|
||||||
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
String apipath = FeatureUtility::GetFeaturesAvailablePath() + "/api.conf";
|
||||||
AgentUtility::CreateBackupFile(apipath);
|
NodeUtility::CreateBackupFile(apipath);
|
||||||
|
|
||||||
String apipathtmp = apipath + ".tmp";
|
String apipathtmp = apipath + ".tmp";
|
||||||
|
|
||||||
@ -565,13 +565,13 @@ wizard_ticket:
|
|||||||
|
|
||||||
Log(LogInformation, "cli", "Updating constants.conf.");
|
Log(LogInformation, "cli", "Updating constants.conf.");
|
||||||
|
|
||||||
AgentUtility::CreateBackupFile(Application::GetSysconfDir() + "/icinga2/constants.conf");
|
NodeUtility::CreateBackupFile(Application::GetSysconfDir() + "/icinga2/constants.conf");
|
||||||
|
|
||||||
AgentUtility::UpdateConstant("NodeName", cn);
|
NodeUtility::UpdateConstant("NodeName", cn);
|
||||||
|
|
||||||
String salt = RandomString(16);
|
String salt = RandomString(16);
|
||||||
|
|
||||||
AgentUtility::UpdateConstant("TicketSalt", salt);
|
NodeUtility::UpdateConstant("TicketSalt", salt);
|
||||||
|
|
||||||
Log(LogInformation, "cli")
|
Log(LogInformation, "cli")
|
||||||
<< "Edit the api feature config file '" << apipath << "' and set a secure 'ticket_salt' attribute.";
|
<< "Edit the api feature config file '" << apipath << "' and set a secure 'ticket_salt' attribute.";
|
@ -30,10 +30,10 @@ namespace icinga
|
|||||||
*
|
*
|
||||||
* @ingroup cli
|
* @ingroup cli
|
||||||
*/
|
*/
|
||||||
class AgentWizardCommand : public CLICommand
|
class NodeWizardCommand : public CLICommand
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_PTR_TYPEDEFS(AgentWizardCommand);
|
DECLARE_PTR_TYPEDEFS(NodeWizardCommand);
|
||||||
|
|
||||||
virtual String GetDescription(void) const;
|
virtual String GetDescription(void) const;
|
||||||
virtual String GetShortDescription(void) const;
|
virtual String GetShortDescription(void) const;
|
Loading…
x
Reference in New Issue
Block a user