]> granicus.if.org Git - icinga2/commitdiff
Compat IDO: serialize dumps (refs #3257)
authorMichael Friedrich <michael.friedrich@gmail.com>
Sun, 7 Oct 2012 21:45:55 +0000 (23:45 +0200)
committerMichael Friedrich <michael.friedrich@gmail.com>
Sun, 7 Oct 2012 21:45:55 +0000 (23:45 +0200)
- dump config once, protect it from status dumps
- send process start to ido2db to allow deletion of inactive objects

components/compatido/compatidocomponent.cpp
components/compatido/compatidocomponent.h

index 814559a903121ead402c1ec0f1bcd31f7f061f66..e12e3bfc604d0be1e8c83e6d758f90836d805508 100644 (file)
@@ -80,6 +80,24 @@ int CompatIdoComponent::GetReconnectInterval(void) const
                 return interval;
 }
 
+/**
+ * Sets config dump in progress state
+ */
+void CompatIdoComponent::SetConfigDumpInProgress(bool state)
+{
+       m_ConfigDumpInProgress = state;
+}
+
+/**
+ * Get state of config in progress
+ *
+ * @returns state bis config dump in progress.
+ */
+bool CompatIdoComponent::GetConfigDumpInProgress(void)
+{
+       return m_ConfigDumpInProgress;
+}
+
 /**
  * Starts the component.
  */
@@ -100,12 +118,20 @@ void CompatIdoComponent::Start(void)
         */
        OpenIdoSocket();
 
+       /* 
+        * tell ido2db that we just started
+        */
+       SendStartProcess();
+
        /*
-        * full config dump at startup, wait for it
+        * ddump the config later (can't do that within start of the component)
         */
-       Logger::Write(LogInformation, "compatido", "Writing compat ido config information");
+       m_ConfigTimer = boost::make_shared<Timer>();
+       m_ConfigTimer->SetInterval(ConfigTimerInterval);
+       m_ConfigTimer->OnTimerExpired.connect(boost::bind(&CompatIdoComponent::ConfigTimerHandler, this));
+       m_ConfigTimer->Start();
+       m_ConfigTimer->Reschedule(0);
 
-       DumpConfigObjects();
 
        /*
         * initialize timers
@@ -114,18 +140,6 @@ void CompatIdoComponent::Start(void)
        m_StatusTimer->SetInterval(StatusTimerInterval);
        m_StatusTimer->OnTimerExpired.connect(boost::bind(&CompatIdoComponent::StatusTimerHandler, this));
        m_StatusTimer->Start();
-       m_StatusTimer->Reschedule(0);
-
-       /*
-        * do not dump configs in intervals, only on startup
-        * TODO trigger dynaamic config updates later
-        */
-       /*
-       m_ConfigTimer = boost::make_shared<Timer>();
-       m_ConfigTimer->SetInterval(ConfigTimerInterval);
-       m_ConfigTimer->OnTimerExpired.connect(boost::bind(&CompatIdoComponent::ConfigTimerHandler, this));
-       m_ConfigTimer->Start();
-       */
 
        /*
         * do not dummp that asynchronous
@@ -211,7 +225,10 @@ void CompatIdoComponent::ConfigTimerHandler(void)
 {
        Logger::Write(LogInformation, "compatido", "Writing compat ido config information");
 
+       /* protect the dump of status update messages */
+       SetConfigDumpInProgress(true);
        DumpConfigObjects();
+       SetConfigDumpInProgress(false);
 }
 
 /**
@@ -219,6 +236,10 @@ void CompatIdoComponent::ConfigTimerHandler(void)
  */
 void CompatIdoComponent::ProgramStatusTimerHandler(void)
 {
+       /* do not dump any data if config dump is still in progress */
+       if(GetConfigDumpInProgress())
+               return;
+
         Logger::Write(LogInformation, "compatido", "Writing compat ido program status information");
 
         DumpProgramStatusData();
@@ -309,6 +330,31 @@ void CompatIdoComponent::CloseSink(void)
        m_IdoSocket->Close();
 }
 
+/**
+ * tell ido2db that we are starting up (must be called before config dump)
+ */
+void CompatIdoComponent::SendStartProcess(void)
+{
+/* TODO */
+#define PROGRAM_MODIFICATION_DATE "10-17-2012"
+
+        stringstream message;
+        message << "\n"
+                << 200 << "\n"                                                 /* processdata */
+               << 1 << "=" << 104 << "\n"                              /* type = pprocess prelaunch */
+               << 2 << "=" << "" << "\n"                               /* flags */
+               << 3 << "=" << "" << "\n"                               /* attributes */
+               << 4 << "=" << std::setprecision(17) << Utility::GetTime() << "\n"              /* timestamp */
+               << 105 << "=" << "Icinga2" << "\n"                      /* progranname */
+               << 107 << "=" << VERSION << "\n"                        /*  programversion */
+               << 104 << "=" << PROGRAM_MODIFICATION_DATE << "\n"                      /* programdata */
+               << 102 << "=" << Utility::GetPid() << "\n"                      /* process id */
+               << 999 << "\n\n";                                       /* enddata */
+
+        m_IdoSocket->SendMessage(message.str());
+
+}
+
 /**
  * sends config dump start signal to ido
  */
@@ -413,6 +459,11 @@ void CompatIdoComponent::DisableServiceObject(const Service::Ptr& service)
  */
 void CompatIdoComponent::DumpHostObject(const Host::Ptr& host)
 {
+       //FIXME DEBUG only
+       stringstream log;
+       log << "Dumping Host Config: " << host->GetName();
+        Logger::Write(LogInformation, "compatido", log.str());
+
        stringstream message;
        message << "\n"
                << 400 << ":" << "\n"                                   /* hostdefinition */
@@ -565,6 +616,11 @@ void CompatIdoComponent::DumpHostStatus(const Host::Ptr& host)
  */
 void CompatIdoComponent::DumpServiceObject(const Service::Ptr& service)
 {
+       //FIXME DEBUG only
+       stringstream log;
+       log << "Dumping Service Config: " << service->GetHost()->GetName() << "->" << service->GetAlias();
+        Logger::Write(LogInformation, "compatido", log.str());
+
        stringstream message;
        message << "\n"
                << 402 << ":" << "\n"                                   /* servicedefinition */
index 148d014750649b0701691c4b2d96061c8bc5299f..6c59ae6ea1fdc849f949035ae5d0d7623c74348e 100644 (file)
@@ -40,11 +40,16 @@ private:
 
        IdoSocket::Ptr m_IdoSocket;
 
+       bool m_ConfigDumpInProgress;
+
        String GetSocketAddress(void) const;
        String GetSocketPort(void) const;
        String GetInstanceName(void) const;
        int GetReconnectInterval(void) const;
 
+       void SetConfigDumpInProgress(bool state);
+       bool GetConfigDumpInProgress(void);
+
        void ConfigTimerHandler(void);
        void StatusTimerHandler(void);
        void ProgramStatusTimerHandler(void);
@@ -57,6 +62,7 @@ private:
        void SendHello(String instancename);
        void GoodByeSink(void);
        void CloseSink(void);
+       void SendStartProcess(void);
        void StartConfigDump(void);
        void EndConfigDump(void);