]> granicus.if.org Git - icinga2/commitdiff
ido: Implement support for runtimevariables.
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 8 Aug 2013 06:47:29 +0000 (08:47 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 8 Aug 2013 06:47:29 +0000 (08:47 +0200)
lib/ido/dbconnection.cpp
lib/ido/dbconnection.h

index 62e3d7894a8f223ea4322ac9f9740ec1f4c8fc1c..0986017014a78ec68ef8b53a127adc35a611fc4d 100644 (file)
@@ -60,6 +60,17 @@ String DbConnection::GetTablePrefix(void) const
                return m_TablePrefix;
 }
 
+void DbConnection::InsertRuntimeVariable(const String& key, const Value& value)
+{
+       DbQuery query;
+
+       query.Fields = boost::make_shared<Dictionary>();
+       query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
+       query.Fields->Set("varname", key);
+       query.Fields->Set("varvalue", value);
+       DbObject::OnQuery(query);
+}
+
 void DbConnection::ProgramStatusHandler(void)
 {
        DbQuery query1;
@@ -89,6 +100,18 @@ void DbConnection::ProgramStatusHandler(void)
        query2.Fields->Set("failure_prediction_enabled", 1);
        query2.Fields->Set("process_performance_data", 1);
        DbObject::OnQuery(query2);
+
+       DbQuery query3;
+       query3.Table = "runtimevariables";
+       query1.Type = DbQueryDelete;
+       query1.WhereCriteria = boost::make_shared<Dictionary>();
+       query1.WhereCriteria->Set("instance_id", 0);  /* DbConnection class fills in real ID */
+       DbObject::OnQuery(query1);
+
+       InsertRuntimeVariable("total_services", DynamicType::GetObjects("Service").size());
+       InsertRuntimeVariable("total_scheduled_services", DynamicType::GetObjects("Service").size());
+       InsertRuntimeVariable("total_hosts", DynamicType::GetObjects("Host").size());
+       InsertRuntimeVariable("total_scheduled_hosts", DynamicType::GetObjects("Host").size());
 }
 
 void DbConnection::SetObjectID(const DbObject::Ptr& dbobj, const DbReference& dbref)
index 35b3aca4c00b36c64fcc4b2913aa1c6d1aceec87..36ab73ba28a2a0f3cd70488821bfcb472f54c1d9 100644 (file)
@@ -74,6 +74,7 @@ private:
        std::set<DbObject::Ptr> m_StatusUpdates;
        static Timer::Ptr m_ProgramStatusTimer;
 
+       static void InsertRuntimeVariable(const String& key, const Value& value);
        static void ProgramStatusHandler(void);
 
        friend class DbType;