]> granicus.if.org Git - icinga2/commitdiff
compatido: dump config data periodically, fix api syntax, rework code further
authorMichael Friedrich <michael.friedrich@gmail.com>
Sat, 15 Sep 2012 15:05:42 +0000 (17:05 +0200)
committerMichael Friedrich <michael.friedrich@gmail.com>
Sat, 15 Sep 2012 15:05:42 +0000 (17:05 +0200)
components/compatido/compatidocomponent.cpp
components/compatido/compatidocomponent.h
components/compatido/idosocket.cpp

index 8b898652807874b2b43dfc476657427e556efa10..1ebb43666e662329d72854d1e74641a732da0a2e 100644 (file)
@@ -50,16 +50,17 @@ void CompatIdoComponent::Start(void)
        m_StatusTimer->Start();
        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");
        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)
 {
-
+       Logger::Write(LogInformation, "compatido", "TODO: Writing compat ido status information");
        /*
         * TODO 
-        * - fetch config, dump it
         * - fetch status data, dump it periodically
         * - subscribe to check events and status updates, dump it      
         */
+       DumpStatusData();
 
        /* 
         * HINTS
@@ -104,13 +105,15 @@ void CompatIdoComponent::StatusTimerHandler(void)
 void CompatIdoComponent::ConfigTimerHandler(void)
 {
 
+       Logger::Write(LogInformation, "compatido", "TODO: Writing compat ido config updates information");
        /*
         * TODO 
         * - fetch config, dump it
-        * - fetch status data, dump it periodically
-        * - subscribe to check events and status updates, dump it      
+        * - subscribe to config update events, and send insert/update/delete for configs to ido2db
         */
 
+       DumpConfigObjects();
+
        /* 
         * HINTS
         * - we don't have any implizit host commands, fake it
@@ -156,6 +159,9 @@ void CompatIdoComponent::SendHello(String instancename)
        m_IdoSocket->SendMessage(message.str());
 }
 
+/**
+ * sends config dump start signal to ido
+ */
 void CompatIdoComponent::StartConfigDump()
 {
        struct timeval now;
@@ -163,32 +169,37 @@ void CompatIdoComponent::StartConfigDump()
 
        /* IDOMOD_CONFIG_DUMP_ORIGINAL=1 is the default config type */
        stringstream message;
-       message << "\n"
+       message << "\n\n"
                << IDO_API_STARTCONFIGDUMP << ":" << "\n"
                << IDO_DATA_CONFIGDUMPTYPE << "=" << 1 << "\n"
                << IDO_DATA_TIMESTAMP << "=" << now.tv_sec << "." << now.tv_usec << "\n"
                << IDO_API_ENDDATA
-               << "\n";
+               << "\n\n";
 
        m_IdoSocket->SendMessage(message.str());
 }
 
+/**
+ * sends config dump end signal to ido
+ */
 void CompatIdoComponent::EndConfigDump()
 {
         struct timeval now;
         gettimeofday(&now, NULL);
 
         stringstream message;
-        message << "\n"
+        message << "\n\n"
                 << IDO_API_ENDCONFIGDUMP << ":" << "\n"
                 << IDO_DATA_TIMESTAMP << "=" << now.tv_sec << "." << now.tv_usec << "\n"
                 << IDO_API_ENDDATA
-                << "\n";
+                << "\n\n";
 
         m_IdoSocket->SendMessage(message.str());
-
 }
 
+/**
+ * dump host config to ido
+ */
 void CompatIdoComponent::DumpHostObject(const Host::Ptr& host)
 {
         struct timeval now;
@@ -251,22 +262,28 @@ void CompatIdoComponent::DumpHostObject(const Host::Ptr& host)
                << IDO_DATA_HAVE3DCOORDS << "=" << 0 << "\n"    
                << IDO_DATA_X3D << "=" << 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
                * parents, contactgroups, contacts, custom vars
                * before sending the message
                */
-               << IDO_API_ENDDATA << "\n\n";
 
 
         m_IdoSocket->SendMessage(message.str());
 }
 
+/**
+ * dump host status to ido
+ */
 void CompatIdoComponent::DumpHostStatus(const Host::Ptr& host)
 {
 
+       //FIXME
 }
 
+/**
+ * dump service config to ido
+ */
 void CompatIdoComponent::DumpServiceObject(const Service::Ptr& service)
 {
         struct timeval now;
@@ -322,19 +339,23 @@ void CompatIdoComponent::DumpServiceObject(const Service::Ptr& service)
                << IDO_DATA_NOTESURL << "=" << "" << "\n"
                << IDO_DATA_ACTIONURL << "=" << "" << "\n"
                << IDO_DATA_ICONIMAGE << "=" << "" << "\n"
-               << IDO_DATA_ICONIMAGEALT << "=" << "" << "\n"
+               << IDO_DATA_ICONIMAGEALT << "=" << "" << "\n";
                /* FIXME add more related config items
                * contactgroups, contacts, custom vars
                * before sending the message
                */
-               << IDO_API_ENDDATA << "\n\n";
 
+       Logger::Write(LogInformation, "compatido", "Writing compat ido service");
         m_IdoSocket->SendMessage(message.str());
 }
 
+/**
+ * dump service status to ido
+ */ 
 void CompatIdoComponent::DumpServiceStatus(const Service::Ptr& service)
 {
 
+       //FIXME
 }
 
 /**
index c6e374567c35010620d2f8fdd2dd8f8af0f05f1f..19727976f7dc5a5eb256c5a6457d779978beca16 100644 (file)
@@ -35,6 +35,7 @@ public:
 
 private:
        Timer::Ptr m_StatusTimer;
+       Timer::Ptr m_ConfigTimer;
        IdoSocket::Ptr m_IdoSocket;
 
        void OpenSink(String node, String service );
index 3a962322446e439c8fa09e0dcc34973ee2e9f11a..b09e73cdaccf5a920a559f750f8f137ef55a83f3 100644 (file)
@@ -35,7 +35,7 @@ IdoSocket::IdoSocket(TcpClientRole role)
         * a local instance of our datahandler in case of a new 
         * 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)
 {
+       return;
+/*
        String sString;
 
         while (NetString::ReadStringFromIOQueue(this, &sString)) {
                 //std::cerr << "<< " << jsonString << std::endl;
 
                 try {  
-//                        Value value = Value::Deserialize(jsonString);
+                       Value value = Value::Deserialize(jsonString);
 
-//                        if (!value.IsObjectType<Dictionary>())
-//                                throw_exception(invalid_argument("JSON-RPC message must be a dictionary."));
+                        if (!value.IsObjectType<Dictionary>())
+                                throw_exception(invalid_argument("JSON-RPC message must be a dictionary."));
 
-//                        OnNewMessage(GetSelf(), MessagePart(value));
+                        OnNewMessage(GetSelf(), MessagePart(value));
                 } catch (const exception& ex) {
                         Logger::Write(LogCritical, "jsonrpc", "Exception while processing message from JSON-RPC client: " + String(ex.what()));
                 }
         }
-
+*/
 }
 
 /**