]> granicus.if.org Git - icinga2/commitdiff
DB IDO: Add missing dependency attributes.
authorMichael Friedrich <michael.friedrich@netways.de>
Wed, 23 Apr 2014 08:33:30 +0000 (10:33 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Wed, 23 Apr 2014 08:33:30 +0000 (10:33 +0200)
Fixes #5745

lib/db_ido/hostdbobject.cpp
lib/db_ido/servicedbobject.cpp

index f3a167a0272136e9385f3c1a8a4cb614c2ac9349..5e4ddc2cfcefda3ee667d34f77d044686e62f5c4 100644 (file)
@@ -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<Host>(GetObject());
 
-       /* parents, host dependencies */
+       /* parents */
        BOOST_FOREACH(const Checkable::Ptr& checkable, host->GetParents()) {
                Host::Ptr parent = dynamic_pointer_cast<Host>(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<Dictionary>();
                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;
index 5c9e5746686d601412fa3725fd67069255dfcb4e..2bc8087438f438c0d929406ba6a30920242a44c9 100644 (file)
@@ -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<Service>(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<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;
+               int state_filter = dep->GetStateFilter();
+
+               /* service dependencies */
+               Dictionary::Ptr fields1 = make_shared<Dictionary>();
+               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 */