From: Michael Friedrich Date: Wed, 23 Apr 2014 08:33:30 +0000 (+0200) Subject: DB IDO: Add missing dependency attributes. X-Git-Tag: v0.0.10~24 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cdd5c0a716127f00a66c7a2718bed4763f98658b;p=icinga2 DB IDO: Add missing dependency attributes. Fixes #5745 --- diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index f3a167a02..5e4ddc2cf 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -24,6 +24,7 @@ #include "icinga/host.h" #include "icinga/service.h" #include "icinga/notification.h" +#include "icinga/dependency.h" #include "icinga/checkcommand.h" #include "icinga/eventcommand.h" #include "icinga/compatutility.h" @@ -174,7 +175,7 @@ void HostDbObject::OnConfigUpdate(void) { Host::Ptr host = static_pointer_cast(GetObject()); - /* parents, host dependencies */ + /* parents */ BOOST_FOREACH(const Checkable::Ptr& checkable, host->GetParents()) { Host::Ptr parent = dynamic_pointer_cast(checkable); @@ -195,11 +196,28 @@ void HostDbObject::OnConfigUpdate(void) query1.Category = DbCatConfig; query1.Fields = fields1; OnQuery(query1); + } + + /* host dependencies */ + Log(LogDebug, "db_ido", "host dependencies for '" + host->GetName() + "'"); + + BOOST_FOREACH(const Dependency::Ptr& dep, host->GetDependencies()) { + Checkable::Ptr parent = dep->GetParent(); + + if (!parent) + continue; + + int state_filter = dep->GetStateFilter(); + + Log(LogDebug, "db_ido", "parent host: " + parent->GetName()); - /* host dependencies */ Dictionary::Ptr fields2 = make_shared(); fields2->Set("host_object_id", parent); fields2->Set("dependent_host_object_id", host); + fields2->Set("inherits_parent", 1); + fields2->Set("timeperiod_object_id", dep->GetPeriod()); + fields2->Set("fail_on_up", (state_filter & StateFilterUp) ? 1 : 0); + fields2->Set("fail_on_down", (state_filter & StateFilterDown) ? 1 : 0); fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */ DbQuery query2; diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 5c9e57466..2bc808743 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -28,6 +28,7 @@ #include "base/utility.h" #include "remote/endpoint.h" #include "icinga/notification.h" +#include "icinga/dependency.h" #include "icinga/checkcommand.h" #include "icinga/eventcommand.h" #include "icinga/externalcommandprocessor.h" @@ -176,26 +177,34 @@ void ServiceDbObject::OnConfigUpdate(void) /* service dependencies */ Log(LogDebug, "db_ido", "service dependencies for '" + service->GetName() + "'"); - BOOST_FOREACH(const Checkable::Ptr& checkable, service->GetParents()) { - Service::Ptr parent = dynamic_pointer_cast(checkable); + BOOST_FOREACH(const Dependency::Ptr& dep, service->GetDependencies()) { + Checkable::Ptr parent = dep->GetParent(); if (!parent) continue; Log(LogDebug, "db_ido", "service parents: " + parent->GetName()); - /* service dependencies */ - Dictionary::Ptr fields1 = make_shared(); - 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; + int state_filter = dep->GetStateFilter(); + + /* service dependencies */ + Dictionary::Ptr fields1 = make_shared(); + fields1->Set("service_object_id", parent); + fields1->Set("dependent_service_object_id", service); + fields1->Set("inherits_parent", 1); + fields1->Set("timeperiod_object_id", dep->GetPeriod()); + fields1->Set("fail_on_ok", (state_filter & StateFilterOK) ? 1 : 0); + fields1->Set("fail_on_warning", (state_filter & StateFilterWarning) ? 1 : 0); + fields1->Set("fail_on_critical", (state_filter & StateFilterCritical) ? 1 : 0); + fields1->Set("fail_on_unknown", (state_filter & StateFilterUnknown) ? 1 : 0); + fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */ + + DbQuery query1; + query1.Table = GetType()->GetTable() + "dependencies"; + query1.Type = DbQueryInsert; query1.Category = DbCatConfig; - query1.Fields = fields1; - OnQuery(query1); + query1.Fields = fields1; + OnQuery(query1); } /* service contacts, contactgroups */