mirror of
https://github.com/Icinga/icinga2.git
synced 2025-05-21 23:10:17 +02:00
Implemented support for external commands.
This commit is contained in:
parent
624b17be1a
commit
c20ae866b7
@ -174,6 +174,9 @@ void CompatComponent::ProcessCommand(const String& command)
|
|||||||
stringstream msgbuf;
|
stringstream msgbuf;
|
||||||
msgbuf << "Received command (@" << ts << "), command: " << argv[0] << ", " << argv.size() - 1 << " arguments; raw: " << command;
|
msgbuf << "Received command (@" << ts << "), command: " << argv[0] << ", " << argv.size() - 1 << " arguments; raw: " << command;
|
||||||
Logger::Write(LogInformation, "compat", msgbuf.str());
|
Logger::Write(LogInformation, "compat", msgbuf.str());
|
||||||
|
|
||||||
|
vector<String> argvExtra(argv.begin() + 1, argv.end());
|
||||||
|
ExternalCommand::Execute(argv[0], argvExtra);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompatComponent::DumpHostStatus(ofstream& fp, const Host::Ptr& host)
|
void CompatComponent::DumpHostStatus(ofstream& fp, const Host::Ptr& host)
|
||||||
|
@ -7,6 +7,8 @@ pkglib_LTLIBRARIES = \
|
|||||||
libicinga_la_SOURCES = \
|
libicinga_la_SOURCES = \
|
||||||
cib.cpp \
|
cib.cpp \
|
||||||
cib.h \
|
cib.h \
|
||||||
|
externalcommand.cpp \
|
||||||
|
externalcommand.h \
|
||||||
host.cpp \
|
host.cpp \
|
||||||
hostgroup.cpp \
|
hostgroup.cpp \
|
||||||
hostgroup.h \
|
hostgroup.h \
|
||||||
|
55
lib/icinga/externalcommand.cpp
Normal file
55
lib/icinga/externalcommand.cpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Icinga 2 *
|
||||||
|
* Copyright (C) 2012 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 "i2-icinga.h"
|
||||||
|
|
||||||
|
using namespace icinga;
|
||||||
|
|
||||||
|
bool I2_EXPORT ExternalCommand::m_Initialized;
|
||||||
|
map<String, ExternalCommand::Callback> I2_EXPORT ExternalCommand::m_Commands;
|
||||||
|
|
||||||
|
int ExternalCommand::Execute(const String& command, const vector<String>& arguments)
|
||||||
|
{
|
||||||
|
if (!m_Initialized) {
|
||||||
|
RegisterCommand("HELLO_WORLD", &ExternalCommand::HelloWorld);
|
||||||
|
|
||||||
|
m_Initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
map<String, ExternalCommand::Callback>::iterator it;
|
||||||
|
it = m_Commands.find(command);
|
||||||
|
|
||||||
|
if (it == m_Commands.end())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return it->second(arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExternalCommand::RegisterCommand(const String& command, const ExternalCommand::Callback& callback)
|
||||||
|
{
|
||||||
|
m_Commands[command] = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ExternalCommand::HelloWorld(const vector<String>& arguments)
|
||||||
|
{
|
||||||
|
Logger::Write(LogInformation, "icinga", "HelloWorld external command called.");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
46
lib/icinga/externalcommand.h
Normal file
46
lib/icinga/externalcommand.h
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Icinga 2 *
|
||||||
|
* Copyright (C) 2012 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 EXTERNALCOMMAND_H
|
||||||
|
#define EXTERNALCOMMAND_H
|
||||||
|
|
||||||
|
namespace icinga
|
||||||
|
{
|
||||||
|
|
||||||
|
class I2_ICINGA_API ExternalCommand {
|
||||||
|
public:
|
||||||
|
|
||||||
|
static int Execute(const String& command, const vector<String>& arguments);
|
||||||
|
|
||||||
|
static int HelloWorld(const vector<String>& arguments);
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef function<int (const vector<String>& arguments)> Callback;
|
||||||
|
|
||||||
|
static bool m_Initialized;
|
||||||
|
static map<String, Callback> m_Commands;
|
||||||
|
|
||||||
|
ExternalCommand(void);
|
||||||
|
|
||||||
|
static void RegisterCommand(const String& command, const Callback& callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* EXTERNALCOMMAND_H */
|
@ -40,6 +40,8 @@ using boost::algorithm::is_any_of;
|
|||||||
# define I2_ICINGA_API I2_IMPORT
|
# define I2_ICINGA_API I2_IMPORT
|
||||||
#endif /* I2_ICINGA_BUILD */
|
#endif /* I2_ICINGA_BUILD */
|
||||||
|
|
||||||
|
#include "externalcommand.h"
|
||||||
|
|
||||||
#include "endpoint.h"
|
#include "endpoint.h"
|
||||||
#include "endpointmanager.h"
|
#include "endpointmanager.h"
|
||||||
#include "icingaapplication.h"
|
#include "icingaapplication.h"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user