mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-29 08:34:20 +02:00
Compat IDO: remove more hardcoded values, prepare setting the socket
This commit is contained in:
parent
ad1207166c
commit
f9c4543112
@ -98,6 +98,7 @@ bool CompatIdoComponent::GetConfigDumpInProgress(void)
|
|||||||
return m_ConfigDumpInProgress;
|
return m_ConfigDumpInProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the component.
|
* Starts the component.
|
||||||
*/
|
*/
|
||||||
@ -108,6 +109,10 @@ void CompatIdoComponent::Start(void)
|
|||||||
const int ProgramStatusTimerInterval = 15;
|
const int ProgramStatusTimerInterval = 15;
|
||||||
const int ReconnectTimerInterval = GetReconnectInterval();
|
const int ReconnectTimerInterval = GetReconnectInterval();
|
||||||
|
|
||||||
|
/* FIXME - make this a config option when unix sockets are realdy */
|
||||||
|
|
||||||
|
bool IdoSocketType = true;
|
||||||
|
|
||||||
/* HINTS - XXX
|
/* HINTS - XXX
|
||||||
* - only tcp sockets
|
* - only tcp sockets
|
||||||
* - only icinga idoutils 1.8
|
* - only icinga idoutils 1.8
|
||||||
@ -116,7 +121,7 @@ void CompatIdoComponent::Start(void)
|
|||||||
/*
|
/*
|
||||||
* open ido socket once
|
* open ido socket once
|
||||||
*/
|
*/
|
||||||
OpenIdoSocket();
|
OpenIdoSocket(IdoSocketType);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* tell ido2db that we just started
|
* tell ido2db that we just started
|
||||||
@ -175,11 +180,12 @@ void CompatIdoComponent::Stop(void)
|
|||||||
/**
|
/**
|
||||||
* Opens the ido socket, and sends hello to ido2db
|
* Opens the ido socket, and sends hello to ido2db
|
||||||
*/
|
*/
|
||||||
void CompatIdoComponent::OpenIdoSocket(void)
|
void CompatIdoComponent::OpenIdoSocket(bool sockettype)
|
||||||
{
|
{
|
||||||
OpenSink(GetSocketAddress(), GetSocketPort());
|
OpenSink(GetSocketAddress(), GetSocketPort());
|
||||||
SendHello(GetInstanceName());
|
SendHello(GetInstanceName(), sockettype);
|
||||||
|
|
||||||
|
m_IdoSocket->SetSocketType(sockettype);
|
||||||
/*
|
/*
|
||||||
* if we're connected, do not reconnecte
|
* if we're connected, do not reconnecte
|
||||||
*/
|
*/
|
||||||
@ -261,7 +267,7 @@ void CompatIdoComponent::ReconnectTimerHandler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* socket was disconnected, recconnect */
|
/* socket was disconnected, recconnect */
|
||||||
OpenIdoSocket();
|
OpenIdoSocket(m_IdoSocket->GetSocketType());
|
||||||
|
|
||||||
if(m_IdoSocket->IsConnected()) {
|
if(m_IdoSocket->IsConnected()) {
|
||||||
Logger::Write(LogInformation, "compatido", "Successfully reconnected to ido socket");
|
Logger::Write(LogInformation, "compatido", "Successfully reconnected to ido socket");
|
||||||
@ -287,19 +293,30 @@ void CompatIdoComponent::OpenSink(String node, String service)
|
|||||||
/**
|
/**
|
||||||
* sends hello msg to ido2b
|
* sends hello msg to ido2b
|
||||||
*/
|
*/
|
||||||
void CompatIdoComponent::SendHello(String instancename)
|
void CompatIdoComponent::SendHello(String instancename, bool sockettype)
|
||||||
{
|
{
|
||||||
|
/* FIXME */
|
||||||
|
#define COMPATIDO_PROTOCOL 2
|
||||||
|
#define COMPATIDO_NAME "ICINGA2 COMPATIDO"
|
||||||
|
#define COMPATIDO_RELEASE_VERSION "2.0"
|
||||||
|
|
||||||
|
String connection;
|
||||||
|
if(sockettype)
|
||||||
|
connection = "TCPSOCKET";
|
||||||
|
else
|
||||||
|
connection = "UNIXSOCKET";
|
||||||
|
|
||||||
/* connection is always TCP */
|
/* connection is always TCP */
|
||||||
/* connecttype is always initial */
|
/* connecttype is always initial */
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "\n\n"
|
message << "\n\n"
|
||||||
<< "HELLO" << "\n"
|
<< "HELLO" << "\n"
|
||||||
<< "PROTOCOL" << ": " << 2 << "\n"
|
<< "PROTOCOL" << ": " << COMPATIDO_PROTOCOL<< "\n"
|
||||||
<< "AGENT" << ": " << "I2 COMPATIDO" << "\n"
|
<< "AGENT" << ": " << COMPATIDO_NAME << "\n"
|
||||||
<< "AGENTVERSION" << ": " << "2.0" << "\n"
|
<< "AGENTVERSION" << ": " << COMPATIDO_RELEASE_VERSION << "\n"
|
||||||
<< "STARTTIME" << ": " << static_cast<int>(Utility::GetTime()) << "\n"
|
<< "STARTTIME" << ": " << static_cast<int>(Utility::GetTime()) << "\n"
|
||||||
<< "DISPOSITION" << ": " << "REALTIME" << "\n"
|
<< "DISPOSITION" << ": " << "REALTIME" << "\n"
|
||||||
<< "CONNECTION" << ": " << "TCPSOCKET" << "\n"
|
<< "CONNECTION" << ": " << connection << "\n"
|
||||||
<< "INSTANCENAME" << ": " << instancename << "\n"
|
<< "INSTANCENAME" << ": " << instancename << "\n"
|
||||||
<< "STARTDATADUMP"
|
<< "STARTDATADUMP"
|
||||||
<< "\n\n";
|
<< "\n\n";
|
||||||
@ -337,7 +354,7 @@ void CompatIdoComponent::SendStartProcess(void)
|
|||||||
{
|
{
|
||||||
/* TODO */
|
/* TODO */
|
||||||
#define PROGRAM_MODIFICATION_DATE "10-17-2012"
|
#define PROGRAM_MODIFICATION_DATE "10-17-2012"
|
||||||
#define VERSION "2.0"
|
#define PROGRAM_RELEASE_VERSION "2.0"
|
||||||
|
|
||||||
stringstream message;
|
stringstream message;
|
||||||
message << "\n"
|
message << "\n"
|
||||||
@ -347,7 +364,7 @@ void CompatIdoComponent::SendStartProcess(void)
|
|||||||
<< 3 << "=" << "" << "\n" /* attributes */
|
<< 3 << "=" << "" << "\n" /* attributes */
|
||||||
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
|
<< 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n" /* timestamp */
|
||||||
<< 105 << "=" << "Icinga2" << "\n" /* progranname */
|
<< 105 << "=" << "Icinga2" << "\n" /* progranname */
|
||||||
<< 107 << "=" << VERSION << "\n" /* programversion */
|
<< 107 << "=" << PROGRAM_RELEASE_VERSION << "\n" /* programversion */
|
||||||
<< 104 << "=" << PROGRAM_MODIFICATION_DATE << "\n" /* programdata */
|
<< 104 << "=" << PROGRAM_MODIFICATION_DATE << "\n" /* programdata */
|
||||||
<< 102 << "=" << Utility::GetPid() << "\n" /* process id */
|
<< 102 << "=" << Utility::GetPid() << "\n" /* process id */
|
||||||
<< 999 << "\n\n"; /* enddata */
|
<< 999 << "\n\n"; /* enddata */
|
||||||
|
@ -55,11 +55,11 @@ private:
|
|||||||
void ProgramStatusTimerHandler(void);
|
void ProgramStatusTimerHandler(void);
|
||||||
void ReconnectTimerHandler(void);
|
void ReconnectTimerHandler(void);
|
||||||
|
|
||||||
void OpenIdoSocket(void);
|
void OpenIdoSocket(bool sockettype);
|
||||||
void CloseIdoSocket(void);
|
void CloseIdoSocket(void);
|
||||||
|
|
||||||
void OpenSink(String node, String service);
|
void OpenSink(String node, String service);
|
||||||
void SendHello(String instancename);
|
void SendHello(String instancename, bool sockettype);
|
||||||
void GoodByeSink(void);
|
void GoodByeSink(void);
|
||||||
void CloseSink(void);
|
void CloseSink(void);
|
||||||
void SendStartProcess(void);
|
void SendStartProcess(void);
|
||||||
|
@ -44,6 +44,27 @@ IdoSocket::IdoSocket(TcpClientRole role)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * Set the ido socket type
|
||||||
|
* *
|
||||||
|
* * @param type true=tcp, false=unix
|
||||||
|
* */
|
||||||
|
void IdoSocket::SetSocketType(bool type)
|
||||||
|
{
|
||||||
|
m_SocketType = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* * Get the ido socket type
|
||||||
|
* *
|
||||||
|
* * @returns type true=tcp, false=unix
|
||||||
|
* */
|
||||||
|
bool IdoSocket::GetSocketType(void)
|
||||||
|
{
|
||||||
|
return m_SocketType;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a message to the ido socket
|
* Sends a message to the ido socket
|
||||||
*
|
*
|
||||||
|
@ -38,7 +38,11 @@ public:
|
|||||||
|
|
||||||
IdoSocket(TcpClientRole role);
|
IdoSocket(TcpClientRole role);
|
||||||
|
|
||||||
|
void SetSocketType(bool);
|
||||||
|
bool GetSocketType(void);
|
||||||
|
|
||||||
void SendMessage(const String& message);
|
void SendMessage(const String& message);
|
||||||
|
|
||||||
void SetReconnect(bool reconnect);
|
void SetReconnect(bool reconnect);
|
||||||
bool GetReconnect(void);
|
bool GetReconnect(void);
|
||||||
|
|
||||||
@ -52,6 +56,7 @@ private:
|
|||||||
void ClientClosedHandler(void);
|
void ClientClosedHandler(void);
|
||||||
|
|
||||||
bool m_Reconnect;
|
bool m_Reconnect;
|
||||||
|
bool m_SocketType;
|
||||||
|
|
||||||
friend IdoSocket::Ptr IdoSocketFactory(SOCKET fd, TcpClientRole role);
|
friend IdoSocket::Ptr IdoSocketFactory(SOCKET fd, TcpClientRole role);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user