mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
ido: Properly implement program status updates.
This commit is contained in:
parent
b2b1040090
commit
70220e7375
@ -152,11 +152,6 @@ void MysqlDbConnection::ReconnectTimerHandler(void)
|
||||
SetReference(dbobj, DbReference(row->Get("object_id")));
|
||||
}
|
||||
|
||||
// TODO: Use a timer, move to libido
|
||||
std::ostringstream q2buf;
|
||||
q2buf << "REPLACE INTO icinga_programstatus (instance_id, status_update_time) VALUES (" << static_cast<long>(m_InstanceID) << ", NOW())";
|
||||
Query(q2buf.str());
|
||||
|
||||
Query("BEGIN");
|
||||
}
|
||||
|
||||
@ -396,13 +391,13 @@ void MysqlDbConnection::ExecuteQuery(const DbQuery& query)
|
||||
Value value;
|
||||
bool first = true;
|
||||
BOOST_FOREACH(boost::tie(key, value), query.WhereCriteria) {
|
||||
if (!FieldToEscapedString(Empty, value, &value))
|
||||
if (!FieldToEscapedString(key, value, &value))
|
||||
return;
|
||||
|
||||
if (!first)
|
||||
qbuf << " AND ";
|
||||
|
||||
qbuf << key << " = '" << Escape(value) << "'";
|
||||
qbuf << key << " = '" << value << "'";
|
||||
|
||||
if (first)
|
||||
first = false;
|
||||
|
@ -251,6 +251,12 @@ void ExternalCommandProcessor::ScheduleHostCheck(double, const std::vector<Strin
|
||||
|
||||
Service::Ptr hc = host->GetHostCheckService();
|
||||
|
||||
if (!hc) {
|
||||
Log(LogInformation, "icinga", "Ignoring request request for host '" +
|
||||
arguments[0] + "' (does not have a host check)");
|
||||
return;
|
||||
}
|
||||
|
||||
double planned_check = Convert::ToDouble(arguments[1]);
|
||||
|
||||
if (planned_check > hc->GetNextCheck()) {
|
||||
@ -277,6 +283,12 @@ void ExternalCommandProcessor::ScheduleForcedHostCheck(double, const std::vector
|
||||
|
||||
Service::Ptr hc = host->GetHostCheckService();
|
||||
|
||||
if (!hc) {
|
||||
Log(LogInformation, "icinga", "Ignoring request request for host '" +
|
||||
arguments[0] + "' (does not have a host check)");
|
||||
return;
|
||||
}
|
||||
|
||||
Log(LogInformation, "icinga", "Rescheduling next check for host '" + arguments[0] + "'");
|
||||
|
||||
{
|
||||
|
@ -18,11 +18,15 @@
|
||||
******************************************************************************/
|
||||
|
||||
#include "ido/dbconnection.h"
|
||||
#include "ido/dbvalue.h"
|
||||
#include "icinga/icingaapplication.h"
|
||||
#include "base/dynamictype.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
Timer::Ptr DbConnection::m_ProgramStatusTimer;
|
||||
|
||||
DbConnection::DbConnection(const Dictionary::Ptr& serializedUpdate)
|
||||
: DynamicObject(serializedUpdate)
|
||||
{ }
|
||||
@ -34,6 +38,45 @@ void DbConnection::Start(void)
|
||||
DbObject::OnQuery.connect(boost::bind(&DbConnection::ExecuteQuery, this, _1));
|
||||
}
|
||||
|
||||
void DbConnection::StaticInitialize(void)
|
||||
{
|
||||
m_ProgramStatusTimer = boost::make_shared<Timer>();
|
||||
m_ProgramStatusTimer->SetInterval(10);
|
||||
m_ProgramStatusTimer->OnTimerExpired.connect(boost::bind(&DbConnection::ProgramStatusHandler));
|
||||
m_ProgramStatusTimer->Start();
|
||||
}
|
||||
|
||||
void DbConnection::ProgramStatusHandler(void)
|
||||
{
|
||||
DbQuery query1;
|
||||
query1.Table = "icinga_programstatus";
|
||||
query1.Type = DbQueryDelete;
|
||||
query1.WhereCriteria = boost::make_shared<Dictionary>();
|
||||
query1.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
DbObject::OnQuery(query1);
|
||||
|
||||
DbQuery query2;
|
||||
query2.Table = "icinga_programstatus";
|
||||
query2.Type = DbQueryInsert;
|
||||
|
||||
query2.Fields = boost::make_shared<Dictionary>();
|
||||
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query2.Fields->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
|
||||
query2.Fields->Set("program_start_time", DbValue::FromTimestamp(IcingaApplication::GetInstance()->GetStartTime()));
|
||||
query2.Fields->Set("is_currently_running", 1);
|
||||
query2.Fields->Set("process_id", Utility::GetPid());
|
||||
query2.Fields->Set("daemon_mode", 1);
|
||||
query2.Fields->Set("last_command_check", DbValue::FromTimestamp(Utility::GetTime()));
|
||||
query2.Fields->Set("notifications_enabled", 1);
|
||||
query2.Fields->Set("active_service_checks_enabled", 1);
|
||||
query2.Fields->Set("passive_service_checks_enabled", 1);
|
||||
query2.Fields->Set("event_handlers_enabled", 1);
|
||||
query2.Fields->Set("flap_detection_enabled", 1);
|
||||
query2.Fields->Set("failure_prediction_enabled", 1);
|
||||
query2.Fields->Set("process_performance_data", 1);
|
||||
DbObject::OnQuery(query2);
|
||||
}
|
||||
|
||||
void DbConnection::SetReference(const DbObject::Ptr& dbobj, const DbReference& dbref)
|
||||
{
|
||||
if (dbref.IsValid())
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define DBCONNECTION_H
|
||||
|
||||
#include "base/dynamicobject.h"
|
||||
#include "base/timer.h"
|
||||
#include "ido/dbobject.h"
|
||||
#include "ido/dbquery.h"
|
||||
|
||||
@ -53,6 +54,12 @@ protected:
|
||||
|
||||
private:
|
||||
std::map<DbObject::Ptr, DbReference> m_References;
|
||||
static Timer::Ptr m_ProgramStatusTimer;
|
||||
|
||||
static void StaticInitialize(void);
|
||||
static void ProgramStatusHandler(void);
|
||||
|
||||
friend class DbType;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "ido/dbobject.h"
|
||||
#include "ido/dbtype.h"
|
||||
#include "ido/dbvalue.h"
|
||||
#include "icinga/service.h"
|
||||
#include "base/dynamictype.h"
|
||||
#include "base/objectlock.h"
|
||||
@ -116,7 +117,7 @@ void DbObject::SendStatusUpdate(void)
|
||||
|
||||
query2.Fields->Set(GetType()->GetTable() + "_object_id", GetObject());
|
||||
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||
query2.Fields->Set("status_update_time", Utility::FormatDateTime("%Y-%m-%d %H:%M:%S", Utility::GetTime()));
|
||||
query2.Fields->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
|
||||
OnQuery(query2);
|
||||
|
||||
m_LastStatusUpdate = Utility::GetTime();
|
||||
|
@ -18,6 +18,7 @@
|
||||
******************************************************************************/
|
||||
|
||||
#include "ido/dbtype.h"
|
||||
#include "ido/dbconnection.h"
|
||||
#include "base/objectlock.h"
|
||||
#include "base/utility.h"
|
||||
#include <boost/thread/once.hpp>
|
||||
@ -32,7 +33,13 @@ DbType::DbType(const String& name, const String& table, long tid, const DbType::
|
||||
: m_Name(name), m_Table(table), m_TypeID(tid), m_ObjectFactory(factory)
|
||||
{
|
||||
static boost::once_flag initializeOnce = BOOST_ONCE_INIT;
|
||||
boost::call_once(initializeOnce, &DbObject::StaticInitialize);
|
||||
boost::call_once(initializeOnce, &DbType::StaticInitialize);
|
||||
}
|
||||
|
||||
void DbType::StaticInitialize(void)
|
||||
{
|
||||
DbConnection::StaticInitialize();
|
||||
DbObject::StaticInitialize();
|
||||
}
|
||||
|
||||
String DbType::GetName(void) const
|
||||
|
@ -64,6 +64,8 @@ private:
|
||||
static TypeMap& GetTypes(void);
|
||||
|
||||
ObjectMap& GetObjects(void);
|
||||
|
||||
static void StaticInitialize(void);
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user