-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cli commands: Add basic agent command set
refs #7248
- Loading branch information
Michael Friedrich
committed
Oct 17, 2014
1 parent
ac47649
commit d33b850
Showing
19 changed files
with
1,098 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/****************************************************************************** | ||
* Icinga 2 * | ||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) * | ||
* * | ||
* 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/agentaddcommand.hpp" | ||
#include "base/logger_fwd.hpp" | ||
#include "base/clicommand.hpp" | ||
#include "base/application.hpp" | ||
#include <boost/foreach.hpp> | ||
#include <boost/algorithm/string/join.hpp> | ||
#include <boost/algorithm/string/replace.hpp> | ||
#include <fstream> | ||
#include <vector> | ||
#include <string> | ||
#include <unistd.h> | ||
|
||
using namespace icinga; | ||
namespace po = boost::program_options; | ||
|
||
REGISTER_CLICOMMAND("agent/add", AgentAddCommand); | ||
|
||
String AgentAddCommand::GetDescription(void) const | ||
{ | ||
return "Add Icinga 2 agent."; | ||
} | ||
|
||
String AgentAddCommand::GetShortDescription(void) const | ||
{ | ||
return "add agent"; | ||
} | ||
|
||
void AgentAddCommand::InitParameters(boost::program_options::options_description& visibleDesc, | ||
boost::program_options::options_description& hiddenDesc, | ||
ArgumentCompletionDescription& argCompletionDesc) const | ||
{ | ||
/* Command doesn't support any parameters. */ | ||
} | ||
|
||
/** | ||
* The entry point for the "feature list" CLI command. | ||
* | ||
* @returns An exit status. | ||
*/ | ||
int AgentAddCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const | ||
{ | ||
if (!ap.empty()) { | ||
Log(LogWarning, "cli", "Ignoring parameters: " + boost::algorithm::join(ap, " ")); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/****************************************************************************** | ||
* Icinga 2 * | ||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) * | ||
* * | ||
* 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. * | ||
******************************************************************************/ | ||
|
||
#ifndef AGENTADDCOMMAND_H | ||
#define AGENTADDCOMMAND_H | ||
|
||
#include "base/qstring.hpp" | ||
#include "base/clicommand.hpp" | ||
|
||
namespace icinga | ||
{ | ||
|
||
/** | ||
* The "agent add" command. | ||
* | ||
* @ingroup cli | ||
*/ | ||
class AgentAddCommand : public CLICommand | ||
{ | ||
public: | ||
DECLARE_PTR_TYPEDEFS(AgentAddCommand); | ||
|
||
virtual String GetDescription(void) const; | ||
virtual String GetShortDescription(void) const; | ||
virtual void InitParameters(boost::program_options::options_description& visibleDesc, | ||
boost::program_options::options_description& hiddenDesc, | ||
ArgumentCompletionDescription& argCompletionDesc) const; | ||
virtual int Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const; | ||
}; | ||
|
||
} | ||
|
||
#endif /* AGENTADDCOMMAND_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/****************************************************************************** | ||
* Icinga 2 * | ||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) * | ||
* * | ||
* 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/agentblackandwhitelistcommand.hpp" | ||
#include "base/logger_fwd.hpp" | ||
#include "base/clicommand.hpp" | ||
#include "base/application.hpp" | ||
#include "base/tlsutility.hpp" | ||
#include <boost/algorithm/string/case_conv.hpp> | ||
#include <fstream> | ||
|
||
using namespace icinga; | ||
|
||
REGISTER_BLACKANDWHITELIST_CLICOMMAND("whitelist"); | ||
REGISTER_BLACKANDWHITELIST_CLICOMMAND("blacklist"); | ||
|
||
RegisterBlackAndWhitelistCLICommandHelper::RegisterBlackAndWhitelistCLICommandHelper(const String& type) | ||
{ | ||
String ltype = type; | ||
boost::algorithm::to_lower(ltype); | ||
|
||
std::vector<String> name; | ||
name.push_back("agent"); | ||
name.push_back(ltype); | ||
name.push_back("add"); | ||
CLICommand::Register(name, make_shared<BlackAndWhitelistCommand>(type, BlackAndWhitelistCommandAdd)); | ||
|
||
name[2] = "remove"; | ||
CLICommand::Register(name, make_shared<BlackAndWhitelistCommand>(type, BlackAndWhitelistCommandRemove)); | ||
|
||
name[2] = "list"; | ||
CLICommand::Register(name, make_shared<BlackAndWhitelistCommand>(type, BlackAndWhitelistCommandList)); | ||
} | ||
|
||
BlackAndWhitelistCommand::BlackAndWhitelistCommand(const String& type, BlackAndWhitelistCommandType command) | ||
: m_Type(type), m_Command(command) | ||
{ } | ||
|
||
String BlackAndWhitelistCommand::GetDescription(void) const | ||
{ | ||
String description; | ||
|
||
switch (m_Command) { | ||
case BlackAndWhitelistCommandAdd: | ||
description = "Adds a new"; | ||
break; | ||
case BlackAndWhitelistCommandRemove: | ||
description = "Removes a"; | ||
break; | ||
case BlackAndWhitelistCommandList: | ||
description = "Lists all"; | ||
break; | ||
} | ||
|
||
description += " " + m_Type + " filter"; | ||
|
||
if (m_Command == BlackAndWhitelistCommandList) | ||
description += "s"; | ||
|
||
return description; | ||
} | ||
|
||
String BlackAndWhitelistCommand::GetShortDescription(void) const | ||
{ | ||
String description; | ||
|
||
switch (m_Command) { | ||
case BlackAndWhitelistCommandAdd: | ||
description = "adds a new"; | ||
break; | ||
case BlackAndWhitelistCommandRemove: | ||
description = "removes a"; | ||
break; | ||
case BlackAndWhitelistCommandList: | ||
description = "lists all"; | ||
break; | ||
} | ||
|
||
description += " " + m_Type + " filter"; | ||
|
||
if (m_Command == BlackAndWhitelistCommandList) | ||
description += "s"; | ||
|
||
return description; | ||
} | ||
|
||
void BlackAndWhitelistCommand::InitParameters(boost::program_options::options_description& visibleDesc, | ||
boost::program_options::options_description& hiddenDesc, | ||
ArgumentCompletionDescription& argCompletionDesc) const | ||
{ | ||
visibleDesc.add_options() | ||
("agent", po::value<std::string>(), "The name of the agent") | ||
("host", po::value<std::string>(), "The name of the host") | ||
("service", po::value<std::string>(), "The name of the service"); | ||
|
||
if (m_Command == BlackAndWhitelistCommandAdd) { | ||
//TODO: call list functionality | ||
} | ||
} | ||
|
||
/** | ||
* The entry point for the "repository <type> <add/remove/list>" CLI command. | ||
* | ||
* @returns An exit status. | ||
*/ | ||
int BlackAndWhitelistCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const | ||
{ | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/****************************************************************************** | ||
* Icinga 2 * | ||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) * | ||
* * | ||
* 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. * | ||
******************************************************************************/ | ||
|
||
#ifndef BLACKANDWHITELISTCOMMAND_H | ||
#define BLACKANDWHITELISTCOMMAND_H | ||
|
||
#include "base/qstring.hpp" | ||
#include "base/clicommand.hpp" | ||
|
||
namespace icinga | ||
{ | ||
|
||
enum BlackAndWhitelistCommandType | ||
{ | ||
BlackAndWhitelistCommandAdd, | ||
BlackAndWhitelistCommandRemove, | ||
BlackAndWhitelistCommandList | ||
}; | ||
|
||
/** | ||
* The "repository <type> <add/remove/list>" command. | ||
* | ||
* @ingroup cli | ||
*/ | ||
class BlackAndWhitelistCommand : public CLICommand | ||
{ | ||
public: | ||
DECLARE_PTR_TYPEDEFS(BlackAndWhitelistCommand); | ||
|
||
BlackAndWhitelistCommand(const String& type, BlackAndWhitelistCommandType command); | ||
|
||
virtual String GetDescription(void) const; | ||
virtual String GetShortDescription(void) const; | ||
virtual void InitParameters(boost::program_options::options_description& visibleDesc, | ||
boost::program_options::options_description& hiddenDesc, | ||
ArgumentCompletionDescription& argCompletionDesc) const; | ||
virtual int Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const; | ||
|
||
private: | ||
String m_Type; | ||
BlackAndWhitelistCommandType m_Command; | ||
}; | ||
|
||
/** | ||
* Helper class for registering repository CLICommand implementation classes. | ||
* | ||
* @ingroup cli | ||
*/ | ||
class I2_BASE_API RegisterBlackAndWhitelistCLICommandHelper | ||
{ | ||
public: | ||
RegisterBlackAndWhitelistCLICommandHelper(const String& type); | ||
}; | ||
|
||
#define REGISTER_BLACKANDWHITELIST_CLICOMMAND(type) \ | ||
namespace { namespace UNIQUE_NAME(cli) { \ | ||
I2_EXPORT icinga::RegisterBlackAndWhitelistCLICommandHelper l_RegisterBlackAndWhitelistCLICommand(type); \ | ||
} } | ||
|
||
} | ||
|
||
#endif /* BLACKANDWHITELISTCOMMAND_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/****************************************************************************** | ||
* Icinga 2 * | ||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) * | ||
* * | ||
* 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/agentlistcommand.hpp" | ||
#include "base/logger_fwd.hpp" | ||
#include "base/clicommand.hpp" | ||
#include "base/application.hpp" | ||
#include <boost/foreach.hpp> | ||
#include <boost/algorithm/string/join.hpp> | ||
#include <boost/algorithm/string/replace.hpp> | ||
#include <fstream> | ||
#include <vector> | ||
#include <string> | ||
#include <unistd.h> | ||
|
||
using namespace icinga; | ||
namespace po = boost::program_options; | ||
|
||
REGISTER_CLICOMMAND("agent/list", AgentListCommand); | ||
|
||
String AgentListCommand::GetDescription(void) const | ||
{ | ||
return "Lists all Icinga 2 agents."; | ||
} | ||
|
||
String AgentListCommand::GetShortDescription(void) const | ||
{ | ||
return "lists all agents"; | ||
} | ||
|
||
void AgentListCommand::InitParameters(boost::program_options::options_description& visibleDesc, | ||
boost::program_options::options_description& hiddenDesc, | ||
ArgumentCompletionDescription& argCompletionDesc) const | ||
{ | ||
/* Command doesn't support any parameters. */ | ||
} | ||
|
||
/** | ||
* The entry point for the "feature list" CLI command. | ||
* | ||
* @returns An exit status. | ||
*/ | ||
int AgentListCommand::Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const | ||
{ | ||
if (!ap.empty()) { | ||
Log(LogWarning, "cli", "Ignoring parameters: " + boost::algorithm::join(ap, " ")); | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.