]> granicus.if.org Git - icinga2/commitdiff
Compat IDO: remove more hardcoded values, prepare setting the socket
authorMichael Friedrich <michael.friedrich@gmail.com>
Mon, 8 Oct 2012 08:26:07 +0000 (10:26 +0200)
committerMichael Friedrich <michael.friedrich@gmail.com>
Mon, 8 Oct 2012 08:26:07 +0000 (10:26 +0200)
components/compatido/compatidocomponent.cpp
components/compatido/compatidocomponent.h
components/compatido/idosocket.cpp
components/compatido/idosocket.h

index 848acc7e3421031ed75b4240018366a9a0bb9c73..0a06f4715734fae43b99898f5b5b3b94fc930422 100644 (file)
@@ -98,6 +98,7 @@ bool CompatIdoComponent::GetConfigDumpInProgress(void)
        return m_ConfigDumpInProgress;
 }
 
+
 /**
  * Starts the component.
  */
@@ -108,6 +109,10 @@ void CompatIdoComponent::Start(void)
        const int ProgramStatusTimerInterval = 15;
        const int ReconnectTimerInterval = GetReconnectInterval();
 
+       /* FIXME - make this a config option when unix sockets are realdy */
+
+       bool IdoSocketType = true;
+
        /* HINTS - XXX
         * - only tcp sockets
         * - only icinga idoutils 1.8
@@ -116,7 +121,7 @@ void CompatIdoComponent::Start(void)
        /*
         * open ido socket once
         */
-       OpenIdoSocket();
+       OpenIdoSocket(IdoSocketType);
 
        /* 
         * tell ido2db that we just started
@@ -175,11 +180,12 @@ void CompatIdoComponent::Stop(void)
 /**
  * Opens the ido socket, and sends hello to ido2db
  */
-void CompatIdoComponent::OpenIdoSocket(void)
+void CompatIdoComponent::OpenIdoSocket(bool sockettype)
 {
        OpenSink(GetSocketAddress(), GetSocketPort());
-       SendHello(GetInstanceName());
+       SendHello(GetInstanceName(), sockettype);
 
+       m_IdoSocket->SetSocketType(sockettype);
        /* 
         * if we're connected, do not reconnecte
         */
@@ -261,7 +267,7 @@ void CompatIdoComponent::ReconnectTimerHandler(void)
                }
 
                /* socket was disconnected, recconnect */
-               OpenIdoSocket();
+               OpenIdoSocket(m_IdoSocket->GetSocketType());
 
                if(m_IdoSocket->IsConnected()) {
                        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
  */
-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 */
        /* connecttype is always initial */
        stringstream message;
        message << "\n\n"
                << "HELLO" << "\n"
-               << "PROTOCOL" << ": " << << "\n"
-               << "AGENT" << ": " << "I2 COMPATIDO" << "\n"
-               << "AGENTVERSION" << ": " << "2.0" << "\n"
+               << "PROTOCOL" << ": " << COMPATIDO_PROTOCOL<< "\n"
+               << "AGENT" << ": " << COMPATIDO_NAME << "\n"
+               << "AGENTVERSION" << ": " << COMPATIDO_RELEASE_VERSION << "\n"
                << "STARTTIME" << ": " << static_cast<int>(Utility::GetTime()) << "\n"
                << "DISPOSITION" << ": " << "REALTIME" << "\n"
-               << "CONNECTION" << ": " << "TCPSOCKET" << "\n"
+               << "CONNECTION" << ": " << connection << "\n"
                << "INSTANCENAME" << ": " << instancename << "\n"
                << "STARTDATADUMP"
                << "\n\n";
@@ -337,7 +354,7 @@ void CompatIdoComponent::SendStartProcess(void)
 {
 /* TODO */
 #define PROGRAM_MODIFICATION_DATE "10-17-2012"
-#define VERSION "2.0"
+#define PROGRAM_RELEASE_VERSION "2.0"
 
         stringstream message;
         message << "\n"
@@ -347,7 +364,7 @@ void CompatIdoComponent::SendStartProcess(void)
                << 3 << "=" << "" << "\n"                               /* attributes */
                << 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n"              /* timestamp */
                << 105 << "=" << "Icinga2" << "\n"                      /* progranname */
-               << 107 << "=" << VERSION << "\n"                        /*  programversion */
+               << 107 << "=" << PROGRAM_RELEASE_VERSION << "\n"                        /*  programversion */
                << 104 << "=" << PROGRAM_MODIFICATION_DATE << "\n"                      /* programdata */
                << 102 << "=" << Utility::GetPid() << "\n"                      /* process id */
                << 999 << "\n\n";                                       /* enddata */
index 6c59ae6ea1fdc849f949035ae5d0d7623c74348e..682c6f2c767a99c2a4eec725a82fe822f4a01421 100644 (file)
@@ -55,11 +55,11 @@ private:
        void ProgramStatusTimerHandler(void);
        void ReconnectTimerHandler(void);
 
-       void OpenIdoSocket(void);
+       void OpenIdoSocket(bool sockettype);
        void CloseIdoSocket(void);
 
        void OpenSink(String node, String service);
-       void SendHello(String instancename);
+       void SendHello(String instancename, bool sockettype);
        void GoodByeSink(void);
        void CloseSink(void);
        void SendStartProcess(void);
index b028f2da07ccd48ea90032d4ea10353ee9501593..fa07791b751624c90bde4202052182e1e4b2ebd2 100644 (file)
@@ -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
  *
index 498677bf566bd347e62ad8c72d31756deda17395..6ac3561853bf8643d0e4a6aa2bf4111c655e6a33 100644 (file)
@@ -38,7 +38,11 @@ public:
 
        IdoSocket(TcpClientRole role);
 
+       void SetSocketType(bool);
+       bool GetSocketType(void);
+
        void SendMessage(const String& message);
+
        void SetReconnect(bool reconnect);
        bool GetReconnect(void);
 
@@ -52,6 +56,7 @@ private:
        void ClientClosedHandler(void);
 
        bool m_Reconnect;
+       bool m_SocketType;
 
        friend IdoSocket::Ptr IdoSocketFactory(SOCKET fd, TcpClientRole role);
 };