mirror of https://github.com/Icinga/icinga2.git
compatido: dump config data periodically, fix api syntax, rework code further
This commit is contained in:
parent
340a0583bf
commit
ceb25ab1cc
|
@ -50,16 +50,17 @@ void CompatIdoComponent::Start(void)
|
||||||
m_StatusTimer->Start();
|
m_StatusTimer->Start();
|
||||||
m_StatusTimer->Reschedule(0);
|
m_StatusTimer->Reschedule(0);
|
||||||
|
|
||||||
|
m_ConfigTimer = boost::make_shared<Timer>();
|
||||||
|
m_ConfigTimer->SetInterval(15);
|
||||||
|
m_ConfigTimer->OnTimerExpired.connect(boost::bind(&CompatIdoComponent::ConfigTimerHandler, this));
|
||||||
|
m_ConfigTimer->Start();
|
||||||
|
m_ConfigTimer->Reschedule(0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* open ido socket
|
* open ido socket once, send the updates via timer then
|
||||||
*/
|
*/
|
||||||
OpenSink("127.0.0.1", "5668");
|
OpenSink("127.0.0.1", "5668");
|
||||||
SendHello("i2-default");
|
SendHello("i2-default");
|
||||||
|
|
||||||
/*
|
|
||||||
* send the config on startup - FIXME dynamic config update handler
|
|
||||||
*/
|
|
||||||
DumpConfigObjects();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,13 +83,13 @@ void CompatIdoComponent::Stop(void)
|
||||||
*/
|
*/
|
||||||
void CompatIdoComponent::StatusTimerHandler(void)
|
void CompatIdoComponent::StatusTimerHandler(void)
|
||||||
{
|
{
|
||||||
|
Logger::Write(LogInformation, "compatido", "TODO: Writing compat ido status information");
|
||||||
/*
|
/*
|
||||||
* TODO
|
* TODO
|
||||||
* - fetch config, dump it
|
|
||||||
* - fetch status data, dump it periodically
|
* - fetch status data, dump it periodically
|
||||||
* - subscribe to check events and status updates, dump it
|
* - subscribe to check events and status updates, dump it
|
||||||
*/
|
*/
|
||||||
|
DumpStatusData();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* HINTS
|
* HINTS
|
||||||
|
@ -104,13 +105,15 @@ void CompatIdoComponent::StatusTimerHandler(void)
|
||||||
void CompatIdoComponent::ConfigTimerHandler(void)
|
void CompatIdoComponent::ConfigTimerHandler(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Logger::Write(LogInformation, "compatido", "TODO: Writing compat ido config updates information");
|
||||||
/*
|
/*
|
||||||
* TODO
|
* TODO
|
||||||
* - fetch config, dump it
|
* - fetch config, dump it
|
||||||
* - fetch status data, dump it periodically
|
* - subscribe to config update events, and send insert/update/delete for configs to ido2db
|
||||||
* - subscribe to check events and status updates, dump it
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
DumpConfigObjects();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* HINTS
|
* HINTS
|
||||||
* - we don't have any implizit host commands, fake it
|
* - we don't have any implizit host commands, fake it
|
||||||
|
@ -156,6 +159,9 @@ void CompatIdoComponent::SendHello(String instancename)
|
||||||
m_IdoSocket->SendMessage(message.str());
|
m_IdoSocket->SendMessage(message.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sends config dump start signal to ido
|
||||||
|
*/
|
||||||
void CompatIdoComponent::StartConfigDump()
|
void CompatIdoComponent::StartConfigDump()
|
||||||
{
|
{
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
|
@ -163,32 +169,37 @@ void CompatIdoComponent::StartConfigDump()
|
||||||
|
|
||||||
/* IDOMOD_CONFIG_DUMP_ORIGINAL=1 is the default config type */
|
/* IDOMOD_CONFIG_DUMP_ORIGINAL=1 is the default config type */
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "\n"
|
message << "\n\n"
|
||||||
<< IDO_API_STARTCONFIGDUMP << ":" << "\n"
|
<< IDO_API_STARTCONFIGDUMP << ":" << "\n"
|
||||||
<< IDO_DATA_CONFIGDUMPTYPE << "=" << 1 << "\n"
|
<< IDO_DATA_CONFIGDUMPTYPE << "=" << 1 << "\n"
|
||||||
<< IDO_DATA_TIMESTAMP << "=" << now.tv_sec << "." << now.tv_usec << "\n"
|
<< IDO_DATA_TIMESTAMP << "=" << now.tv_sec << "." << now.tv_usec << "\n"
|
||||||
<< IDO_API_ENDDATA
|
<< IDO_API_ENDDATA
|
||||||
<< "\n";
|
<< "\n\n";
|
||||||
|
|
||||||
m_IdoSocket->SendMessage(message.str());
|
m_IdoSocket->SendMessage(message.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sends config dump end signal to ido
|
||||||
|
*/
|
||||||
void CompatIdoComponent::EndConfigDump()
|
void CompatIdoComponent::EndConfigDump()
|
||||||
{
|
{
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, NULL);
|
||||||
|
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "\n"
|
message << "\n\n"
|
||||||
<< IDO_API_ENDCONFIGDUMP << ":" << "\n"
|
<< IDO_API_ENDCONFIGDUMP << ":" << "\n"
|
||||||
<< IDO_DATA_TIMESTAMP << "=" << now.tv_sec << "." << now.tv_usec << "\n"
|
<< IDO_DATA_TIMESTAMP << "=" << now.tv_sec << "." << now.tv_usec << "\n"
|
||||||
<< IDO_API_ENDDATA
|
<< IDO_API_ENDDATA
|
||||||
<< "\n";
|
<< "\n\n";
|
||||||
|
|
||||||
m_IdoSocket->SendMessage(message.str());
|
m_IdoSocket->SendMessage(message.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dump host config to ido
|
||||||
|
*/
|
||||||
void CompatIdoComponent::DumpHostObject(const Host::Ptr& host)
|
void CompatIdoComponent::DumpHostObject(const Host::Ptr& host)
|
||||||
{
|
{
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
|
@ -251,22 +262,28 @@ void CompatIdoComponent::DumpHostObject(const Host::Ptr& host)
|
||||||
<< IDO_DATA_HAVE3DCOORDS << "=" << 0 << "\n"
|
<< IDO_DATA_HAVE3DCOORDS << "=" << 0 << "\n"
|
||||||
<< IDO_DATA_X3D << "=" << 0.0 << "\n"
|
<< IDO_DATA_X3D << "=" << 0.0 << "\n"
|
||||||
<< IDO_DATA_Y3D << "=" << 0.0 << "\n"
|
<< IDO_DATA_Y3D << "=" << 0.0 << "\n"
|
||||||
<< IDO_DATA_Z3D<< "=" << 0.0 << "\n"
|
<< IDO_DATA_Z3D<< "=" << 0.0 << "\n";
|
||||||
/* FIXME add more related config items
|
/* FIXME add more related config items
|
||||||
* parents, contactgroups, contacts, custom vars
|
* parents, contactgroups, contacts, custom vars
|
||||||
* before sending the message
|
* before sending the message
|
||||||
*/
|
*/
|
||||||
<< IDO_API_ENDDATA << "\n\n";
|
|
||||||
|
|
||||||
|
|
||||||
m_IdoSocket->SendMessage(message.str());
|
m_IdoSocket->SendMessage(message.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dump host status to ido
|
||||||
|
*/
|
||||||
void CompatIdoComponent::DumpHostStatus(const Host::Ptr& host)
|
void CompatIdoComponent::DumpHostStatus(const Host::Ptr& host)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dump service config to ido
|
||||||
|
*/
|
||||||
void CompatIdoComponent::DumpServiceObject(const Service::Ptr& service)
|
void CompatIdoComponent::DumpServiceObject(const Service::Ptr& service)
|
||||||
{
|
{
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
|
@ -322,19 +339,23 @@ void CompatIdoComponent::DumpServiceObject(const Service::Ptr& service)
|
||||||
<< IDO_DATA_NOTESURL << "=" << "" << "\n"
|
<< IDO_DATA_NOTESURL << "=" << "" << "\n"
|
||||||
<< IDO_DATA_ACTIONURL << "=" << "" << "\n"
|
<< IDO_DATA_ACTIONURL << "=" << "" << "\n"
|
||||||
<< IDO_DATA_ICONIMAGE << "=" << "" << "\n"
|
<< IDO_DATA_ICONIMAGE << "=" << "" << "\n"
|
||||||
<< IDO_DATA_ICONIMAGEALT << "=" << "" << "\n"
|
<< IDO_DATA_ICONIMAGEALT << "=" << "" << "\n";
|
||||||
/* FIXME add more related config items
|
/* FIXME add more related config items
|
||||||
* contactgroups, contacts, custom vars
|
* contactgroups, contacts, custom vars
|
||||||
* before sending the message
|
* before sending the message
|
||||||
*/
|
*/
|
||||||
<< IDO_API_ENDDATA << "\n\n";
|
|
||||||
|
|
||||||
|
Logger::Write(LogInformation, "compatido", "Writing compat ido service");
|
||||||
m_IdoSocket->SendMessage(message.str());
|
m_IdoSocket->SendMessage(message.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dump service status to ido
|
||||||
|
*/
|
||||||
void CompatIdoComponent::DumpServiceStatus(const Service::Ptr& service)
|
void CompatIdoComponent::DumpServiceStatus(const Service::Ptr& service)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -35,6 +35,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Timer::Ptr m_StatusTimer;
|
Timer::Ptr m_StatusTimer;
|
||||||
|
Timer::Ptr m_ConfigTimer;
|
||||||
IdoSocket::Ptr m_IdoSocket;
|
IdoSocket::Ptr m_IdoSocket;
|
||||||
|
|
||||||
void OpenSink(String node, String service );
|
void OpenSink(String node, String service );
|
||||||
|
|
|
@ -35,7 +35,7 @@ IdoSocket::IdoSocket(TcpClientRole role)
|
||||||
* a local instance of our datahandler in case of a new
|
* a local instance of our datahandler in case of a new
|
||||||
* signal telling about new data
|
* signal telling about new data
|
||||||
*/
|
*/
|
||||||
//OnDataAvailable.connect(boost::bind(&IdoSocket::DataAvailableHandler, this));
|
OnDataAvailable.connect(boost::bind(&IdoSocket::DataAvailableHandler, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,23 +59,25 @@ void IdoSocket::SendMessage(const String& message)
|
||||||
*/
|
*/
|
||||||
void IdoSocket::DataAvailableHandler(void)
|
void IdoSocket::DataAvailableHandler(void)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
/*
|
||||||
String sString;
|
String sString;
|
||||||
|
|
||||||
while (NetString::ReadStringFromIOQueue(this, &sString)) {
|
while (NetString::ReadStringFromIOQueue(this, &sString)) {
|
||||||
//std::cerr << "<< " << jsonString << std::endl;
|
//std::cerr << "<< " << jsonString << std::endl;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Value value = Value::Deserialize(jsonString);
|
Value value = Value::Deserialize(jsonString);
|
||||||
|
|
||||||
// if (!value.IsObjectType<Dictionary>())
|
if (!value.IsObjectType<Dictionary>())
|
||||||
// throw_exception(invalid_argument("JSON-RPC message must be a dictionary."));
|
throw_exception(invalid_argument("JSON-RPC message must be a dictionary."));
|
||||||
|
|
||||||
// OnNewMessage(GetSelf(), MessagePart(value));
|
OnNewMessage(GetSelf(), MessagePart(value));
|
||||||
} catch (const exception& ex) {
|
} catch (const exception& ex) {
|
||||||
Logger::Write(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + String(ex.what()));
|
Logger::Write(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + String(ex.what()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue