]> granicus.if.org Git - icinga2/commitdiff
compatido: cleanup, add programstatus cyclic updates
authorMichael Friedrich <michael.friedrich@gmail.com>
Sat, 15 Sep 2012 18:17:37 +0000 (20:17 +0200)
committerMichael Friedrich <michael.friedrich@gmail.com>
Sat, 15 Sep 2012 18:17:37 +0000 (20:17 +0200)
components/compatido/compatidocomponent.cpp
components/compatido/compatidocomponent.h
components/compatido/idoprotoapi.h

index 899db1ce9a71856526bcb95fafec12f6fe313afb..a7e868360577134202ee5d21cf6166d6c9aeeab1 100644 (file)
@@ -36,13 +36,18 @@ String CompatIdoComponent::GetName(void) const
  */
 void CompatIdoComponent::Start(void)
 {
-       /*
+       /* HINTS - XXX
+        * - only tcp sockets
+        * - only icinga idoutils 1.8
+        * - only "retained" config
+        * - instance_name is i2-default
         * TODO
         * we should have configs for 
-        * - socket (unix or tcp)
         * - data_processing_options
-        * - config_output_options - 0..orig, 1..retained (fake one)
+        * - config_output_options - 0..orig, 1..retained (chose retained for icinga-web preferred)
         * - INSTANCE_NAME ?
+        * - update interval ?
+        * - tcp socket+port
         */
        m_StatusTimer = boost::make_shared<Timer>();
        m_StatusTimer->SetInterval(15);
@@ -56,6 +61,12 @@ void CompatIdoComponent::Start(void)
        m_ConfigTimer->Start();
        m_ConfigTimer->Reschedule(0);
 
+       m_ProgramStatusTimer = boost::make_shared<Timer>();
+       m_ProgramStatusTimer->SetInterval(15);
+       m_ProgramStatusTimer->OnTimerExpired.connect(boost::bind(&CompatIdoComponent::ProgramStatusTimerHandler, this));
+       m_ProgramStatusTimer->Start();
+       m_ProgramStatusTimer->Reschedule(0);
+
        /*
         * open ido socket once, send the updates via timer then
         */
@@ -86,18 +97,13 @@ void CompatIdoComponent::Stop(void)
  */
 void CompatIdoComponent::StatusTimerHandler(void)
 {
-       Logger::Write(LogInformation, "compatido", "TODO: Writing compat ido status information");
+       Logger::Write(LogInformation, "compatido", "Writing compat ido status information");
        /*
         * TODO 
         * - fetch status data, dump it periodically
         * - subscribe to check events and status updates, dump it      
         */
        DumpStatusData();
-
-       /* 
-        * HINTS
-        * - we don't have any implizit host commands, fake it
-        */
 }
 
 /**
@@ -107,8 +113,7 @@ void CompatIdoComponent::StatusTimerHandler(void)
  */
 void CompatIdoComponent::ConfigTimerHandler(void)
 {
-
-       Logger::Write(LogInformation, "compatido", "TODO: Writing compat ido config updates information");
+       Logger::Write(LogInformation, "compatido", "Writing compat ido config information");
        /*
         * TODO 
         * - fetch config, dump it
@@ -116,15 +121,21 @@ void CompatIdoComponent::ConfigTimerHandler(void)
         */
 
        DumpConfigObjects();
+}
 
-       /* 
-        * HINTS
-        * - we don't have any implizit host commands, fake it
-        */
+/**
+ * Periodically dumps program status information
+ *
+ * @param - Event arguments for the timer.
+ */
+void CompatIdoComponent::ProgramStatusTimerHandler(void)
+{
+        Logger::Write(LogInformation, "compatido", "Writing compat ido program status information");
 
+        DumpProgramStatusData();
+}
 
 
-}
 
 /**
  * opens a tcp connection to the socket
@@ -450,7 +461,6 @@ void CompatIdoComponent::DumpServiceObject(const Service::Ptr& service)
                << IDO_DATA_CUSTOMVARIABLE << "=" << "i2_customvar" << ":" << 1 << ":" << "i2_custom_var_mod" << "\n"
                << IDO_API_ENDDATA << "\n\n";
 
-       Logger::Write(LogInformation, "compatido", "Writing compat ido service");
         m_IdoSocket->SendMessage(message.str());
 }
 
@@ -539,12 +549,56 @@ void CompatIdoComponent::DumpServiceStatus(const Service::Ptr& service)
                << IDO_DATA_RETRYCHECKINTERVAL << "=" << service->GetRetryInterval() / 60.0 << "\n"
                << IDO_DATA_SERVICECHECKPERIOD << "=" << "" << "\n"
                /* FIXME dump customvars in a loop */
-               << IDO_DATA_CUSTOMVARIABLE << "=" << "" << ":" << "1" << ":" << "\n"
+               << IDO_DATA_CUSTOMVARIABLE << "=" << "i2_customvar" << ":" << "1" << ":" << "i2_customvarmod" << "\n"
                << IDO_API_ENDDATA << "\n\n";
 
         m_IdoSocket->SendMessage(message.str());
 }
 
+
+/** 
+ * dumps programstatus to ido
+ */
+void CompatIdoComponent::DumpProgramStatusData(void)
+{
+        struct timeval now;
+        gettimeofday(&now, NULL);
+
+       double start_time = IcingaApplication::GetInstance()->GetStartTime();
+
+        stringstream message;
+        message << "\n"
+                << IDO_API_PROGRAMSTATUSDATA << ":" << "\n"
+               << IDO_DATA_TYPE << "=" << "" << "\n"
+               << IDO_DATA_FLAGS << "=" << "" << "\n"
+               << IDO_DATA_ATTRIBUTES << "=" << "" << "\n"
+               << IDO_DATA_TIMESTAMP << "=" << now.tv_sec << "." << now.tv_usec << "\n"
+               << IDO_DATA_PROGRAMSTARTTIME << "=" << static_cast<int>(start_time) << "\n"
+               << IDO_DATA_PROCESSID << "=" << getpid() << "\n"
+               << IDO_DATA_DAEMONMODE << "=" << "1" << "\n"
+               << IDO_DATA_LASTCOMMANDCHECK << "=" << "" << "\n"
+               << IDO_DATA_LASTLOGROTATION << "=" << "" << "\n"
+               << IDO_DATA_NOTIFICATIONSENABLED << "=" << "" << "\n"
+               << IDO_DATA_ACTIVESERVICECHECKSENABLED << "=" << "1" << "\n"
+               << IDO_DATA_PASSIVESERVICECHECKSENABLED << "=" << "1" << "\n"
+               << IDO_DATA_ACTIVEHOSTCHECKSENABLED << "=" << "0" << "\n"
+               << IDO_DATA_PASSIVEHOSTCHECKSENABLED << "=" << "0" << "\n"
+               << IDO_DATA_EVENTHANDLERSENABLED << "=" << "0" << "\n"
+               << IDO_DATA_FLAPDETECTIONENABLED << "=" << "1" << "\n"
+               << IDO_DATA_FAILUREPREDICTIONENABLED << "=" << "0" << "\n"
+               << IDO_DATA_PROCESSPERFORMANCEDATA << "=" << "1" << "\n"
+               << IDO_DATA_OBSESSOVERHOSTS << "=" << "0" << "\n"
+               << IDO_DATA_OBSESSOVERSERVICES << "=" << "0" << "\n"
+               << IDO_DATA_MODIFIEDHOSTATTRIBUTES << "=" << "0" << "\n"
+               << IDO_DATA_MODIFIEDSERVICEATTRIBUTES << "=" << "0" << "\n"
+               << IDO_DATA_GLOBALHOSTEVENTHANDLER << "=" << "" << "\n"
+               << IDO_DATA_GLOBALSERVICEEVENTHANDLER << "=" << "" << "\n"
+               << IDO_DATA_DISABLED_NOTIFICATIONS_EXPIRE_TIME << "=" << "" << "\n" //XXX supported in 1.8
+                << IDO_API_ENDDATA << "\n\n";
+
+        m_IdoSocket->SendMessage(message.str());
+}
+
 /**
  * process and dump all config objects
  */
@@ -555,7 +609,6 @@ void CompatIdoComponent::DumpConfigObjects(void)
         * escalations, dependencies
         * if needed/available.
         */
-       Logger::Write(LogInformation, "compatido", "Writing compat ido config information");
 
        /* tell ido2db that we start now */
        StartConfigDump();
@@ -678,9 +731,6 @@ void CompatIdoComponent::DumpConfigObjects(void)
  */
 void CompatIdoComponent::DumpStatusData(void)
 {
-       Logger::Write(LogInformation, "compatido", "Writing compat ido status information");
-//FIXME update programstatus data more frequently
-//
         /* hosts */
         DynamicObject::Ptr object;
         BOOST_FOREACH(tie(tuples::ignore, object), DynamicObject::GetObjects("Host")) {
@@ -699,5 +749,4 @@ void CompatIdoComponent::DumpStatusData(void)
 }
 
 
-
 EXPORT_COMPONENT(compatido, CompatIdoComponent);
index 20a8961d45a411e10103856f2bfd4df7799b9f4a..c2a246ad6c46e30849e2c7c9c16c5e7e7df4132a 100644 (file)
@@ -36,6 +36,7 @@ public:
 private:
        Timer::Ptr m_StatusTimer;
        Timer::Ptr m_ConfigTimer;
+       Timer::Ptr m_ProgramStatusTimer;
        IdoSocket::Ptr m_IdoSocket;
 
        void OpenSink(String node, String service );
@@ -51,6 +52,7 @@ private:
        void DumpStatusData(void);
        void DumpHostStatus(const Host::Ptr& host);
        void DumpServiceStatus(const Service::Ptr& service);
+       void DumpProgramStatusData(void);
 
        template<typename T>
        void CreateMessageList(stringstream& msg, const T& list, int type)
@@ -66,6 +68,7 @@ private:
 
        void ConfigTimerHandler(void);
        void StatusTimerHandler(void);
+       void ProgramStatusTimerHandler(void);
 };
 
 }
index c53d73bb826a746f2e9701f0602297fd322032dd..03a6a21d35282a363b5ba9e881ffc1e227278477 100644 (file)
  * COMMON DATA ATTRIBUTES
  */
 
-#define IDO_MAX_DATA_TYPES                           270
+#define IDO_MAX_DATA_TYPES                           271
 
 #define IDO_DATA_NONE                                0
 
 #define IDO_DATA_END_TIME                            267    /* ACKNOWLEDGEMENT DATA */
 #define IDO_DATA_DOWNTIMEISINEFFECT                  268
 #define IDO_DATA_DOWNTIMETRIGGERTIME                 269
-
+#define IDO_DATA_DISABLED_NOTIFICATIONS_EXPIRE_TIME  270
 
 #endif /* COMPATIDOPROTOAPI_H */