mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 14:44:32 +02:00
parent
074f7cd389
commit
662130f47e
@ -191,28 +191,46 @@ void HostDbObject::OnConfigUpdate(void)
|
|||||||
{
|
{
|
||||||
Host::Ptr host = static_pointer_cast<Host>(GetObject());
|
Host::Ptr host = static_pointer_cast<Host>(GetObject());
|
||||||
|
|
||||||
/* parents: host_id, parent_host_object_id */
|
/* safety delete */
|
||||||
|
DbQuery query_del1;
|
||||||
|
query_del1.Table = GetType()->GetTable() + "_parenthosts";
|
||||||
|
query_del1.Type = DbQueryDelete;
|
||||||
|
query_del1.WhereCriteria = boost::make_shared<Dictionary>();
|
||||||
|
query_del1.WhereCriteria->Set(GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject()));
|
||||||
|
OnQuery(query_del1);
|
||||||
|
|
||||||
/* delete possible definitions - TODO do that on startup */
|
DbQuery query_del2;
|
||||||
DbQuery query1;
|
query_del2.Table = GetType()->GetTable() + "dependencies";
|
||||||
query1.Table = GetType()->GetTable() + "_parenthosts";
|
query_del2.Type = DbQueryDelete;
|
||||||
query1.Type = DbQueryDelete;
|
query_del2.WhereCriteria = boost::make_shared<Dictionary>();
|
||||||
query1.WhereCriteria = boost::make_shared<Dictionary>();
|
query_del2.WhereCriteria->Set("dependent_host_object_id", host);
|
||||||
query1.WhereCriteria->Set(GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject()));
|
OnQuery(query_del2);
|
||||||
OnQuery(query1);
|
|
||||||
|
|
||||||
BOOST_FOREACH(const Host::Ptr& parent, host->GetParentHosts()) {
|
BOOST_FOREACH(const Host::Ptr& parent, host->GetParentHosts()) {
|
||||||
Log(LogDebug, "ido", "host parents: " + parent->GetName());
|
Log(LogDebug, "ido", "host parents: " + parent->GetName());
|
||||||
|
|
||||||
Dictionary::Ptr fields = boost::make_shared<Dictionary>();
|
/* parents: host_id, parent_host_object_id */
|
||||||
fields->Set(GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject()));
|
Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
|
||||||
fields->Set("parent_host_object_id", parent);
|
fields1->Set(GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject()));
|
||||||
fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
fields1->Set("parent_host_object_id", parent);
|
||||||
|
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
|
||||||
|
DbQuery query1;
|
||||||
|
query1.Table = GetType()->GetTable() + "_parenthosts";
|
||||||
|
query1.Type = DbQueryInsert;
|
||||||
|
query1.Fields = fields1;
|
||||||
|
OnQuery(query1);
|
||||||
|
|
||||||
|
/* host dependencies */
|
||||||
|
Dictionary::Ptr fields2 = boost::make_shared<Dictionary>();
|
||||||
|
fields2->Set("host_object_id", parent);
|
||||||
|
fields2->Set("dependent_host_object_id", host);
|
||||||
|
fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
|
||||||
DbQuery query2;
|
DbQuery query2;
|
||||||
query2.Table = GetType()->GetTable() + "_parenthosts";
|
query2.Table = GetType()->GetTable() + "dependencies";
|
||||||
query2.Type = DbQueryInsert;
|
query2.Type = DbQueryInsert;
|
||||||
query2.Fields = fields;
|
query2.Fields = fields2;
|
||||||
OnQuery(query2);
|
OnQuery(query2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "icinga/checkcommand.h"
|
#include "icinga/checkcommand.h"
|
||||||
#include "icinga/eventcommand.h"
|
#include "icinga/eventcommand.h"
|
||||||
#include "icinga/compatutility.h"
|
#include "icinga/compatutility.h"
|
||||||
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
@ -167,6 +168,34 @@ bool ServiceDbObject::IsStatusAttribute(const String& attribute) const
|
|||||||
void ServiceDbObject::OnConfigUpdate(void)
|
void ServiceDbObject::OnConfigUpdate(void)
|
||||||
{
|
{
|
||||||
Service::Ptr service = static_pointer_cast<Service>(GetObject());
|
Service::Ptr service = static_pointer_cast<Service>(GetObject());
|
||||||
|
|
||||||
|
/* service dependencies */
|
||||||
|
Log(LogDebug, "ido", "service dependencies for '" + service->GetName() + "'");
|
||||||
|
|
||||||
|
DbQuery query_del1;
|
||||||
|
query_del1.Table = GetType()->GetTable() + "dependencies";
|
||||||
|
query_del1.Type = DbQueryDelete;
|
||||||
|
query_del1.WhereCriteria = boost::make_shared<Dictionary>();
|
||||||
|
query_del1.WhereCriteria->Set("dependent_service_object_id", service);
|
||||||
|
OnQuery(query_del1);
|
||||||
|
|
||||||
|
BOOST_FOREACH(const Service::Ptr& parent, service->GetParentServices()) {
|
||||||
|
Log(LogDebug, "ido", "service parents: " + parent->GetName());
|
||||||
|
|
||||||
|
/* service dependencies */
|
||||||
|
Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
|
||||||
|
fields1->Set("service_object_id", parent);
|
||||||
|
fields1->Set("dependent_service_object_id", service);
|
||||||
|
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
|
||||||
|
DbQuery query1;
|
||||||
|
query1.Table = GetType()->GetTable() + "dependencies";
|
||||||
|
query1.Type = DbQueryInsert;
|
||||||
|
query1.Fields = fields1;
|
||||||
|
OnQuery(query1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* service host config update */
|
||||||
Host::Ptr host = service->GetHost();
|
Host::Ptr host = service->GetHost();
|
||||||
|
|
||||||
if (!host)
|
if (!host)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user