]> granicus.if.org Git - icinga2/commitdiff
db_ido: Add {host,service}_{contacts,contactgroups}.
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 1 Oct 2013 14:43:25 +0000 (16:43 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Tue, 1 Oct 2013 14:44:33 +0000 (16:44 +0200)
refs #4378

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

index 8cb2e408fb3e29db672d4535a4acc01d14b9809d..70fcb6ecd1389e063bebfaa5bd3caacdfb9b0418 100644 (file)
@@ -209,7 +209,7 @@ void HostDbObject::OnConfigUpdate(void)
        OnQuery(query_del2);
 
        BOOST_FOREACH(const Host::Ptr& parent, host->GetParentHosts()) {
-               Log(LogDebug, "ido", "host parents: " + parent->GetName());
+               Log(LogDebug, "db_ido", "host parents: " + parent->GetName());
 
                /* parents: host_id, parent_host_object_id */
                Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
@@ -236,6 +236,50 @@ void HostDbObject::OnConfigUpdate(void)
                OnQuery(query2);
        }
 
+       /* host contacts, contactgroups */
+       Service::Ptr service = host->GetCheckService();
+
+       if (service) {
+               Array::Ptr contacts = CompatUtility::GetServiceNotificationUsers(service);
+               Log(LogDebug, "db_ido", "host contacts: " + host->GetName() + " length: " + Convert::ToString(contacts->GetLength()));
+
+               {
+                       ObjectLock olock(contacts);
+                       BOOST_FOREACH(const User::Ptr& user, contacts) {
+                               Log(LogDebug, "db_ido", "host contacts: " + user->GetName());
+
+                               Dictionary::Ptr fields_contact = boost::make_shared<Dictionary>();
+                               fields_contact->Set("host_id", DbValue::FromObjectInsertID(host));
+                               fields_contact->Set("contact_object_id", user);
+
+                               DbQuery query_contact;
+                               query_contact.Table = GetType()->GetTable() + "_contacts";
+                               query_contact.Type = DbQueryInsert;
+                               query_contact.Fields = fields_contact;
+                               OnQuery(query_contact);
+                       }
+               }
+
+               Array::Ptr contactgroups = CompatUtility::GetServiceNotificationUserGroups(service);
+               Log(LogDebug, "db_ido", "host contactgroups: " + host->GetName() + " length: " + Convert::ToString(contactgroups->GetLength()));
+               {
+                       ObjectLock olock(contactgroups);
+                       BOOST_FOREACH(const UserGroup::Ptr& usergroup, contactgroups) {
+                               Log(LogDebug, "db_ido", "host contactgroups: " + usergroup->GetName());
+
+                               Dictionary::Ptr fields_contact = boost::make_shared<Dictionary>();
+                               fields_contact->Set("host_id", DbValue::FromObjectInsertID(host));
+                               fields_contact->Set("contactgroup_object_id", usergroup);
+
+                               DbQuery query_contact;
+                               query_contact.Table = GetType()->GetTable() + "_contactgroups";
+                               query_contact.Type = DbQueryInsert;
+                               query_contact.Fields = fields_contact;
+                               OnQuery(query_contact);
+                       }
+               }
+       }
+
        /* custom variables */
        Log(LogDebug, "ido", "host customvars for '" + host->GetName() + "'");
 
@@ -258,7 +302,7 @@ void HostDbObject::OnConfigUpdate(void)
                String key;
                Value value;
                BOOST_FOREACH(boost::tie(key, value), customvars) {
-                       Log(LogDebug, "ido", "host customvar key: '" + key + "' value: '" + Convert::ToString(value) + "'");
+                       Log(LogDebug, "db_ido", "host customvar key: '" + key + "' value: '" + Convert::ToString(value) + "'");
 
                        Dictionary::Ptr fields3 = boost::make_shared<Dictionary>();
                        fields3->Set("varname", Convert::ToString(key));
index c22d72ebe7307bdb1cee6b1325494a8b6f22cf60..acbe80649bc095930ecb879ee1be4231f07aabe6 100644 (file)
@@ -236,6 +236,46 @@ void ServiceDbObject::OnConfigUpdate(void)
                 OnQuery(query1);
        }
 
+       /* service contacts, contactgroups */
+       Array::Ptr contacts = CompatUtility::GetServiceNotificationUsers(service);
+       Log(LogDebug, "db_ido", "service contacts: " + service->GetName() + " length: " + Convert::ToString(contacts->GetLength()));
+
+       {
+               ObjectLock olock(contacts);
+               BOOST_FOREACH(const User::Ptr& user, contacts) {
+                       Log(LogDebug, "db_ido", "service contacts: " + user->GetName());
+
+                       Dictionary::Ptr fields_contact = boost::make_shared<Dictionary>();
+                       fields_contact->Set("service_id", DbValue::FromObjectInsertID(service));
+                       fields_contact->Set("contact_object_id", user);
+
+                       DbQuery query_contact;
+                       query_contact.Table = GetType()->GetTable() + "_contacts";
+                       query_contact.Type = DbQueryInsert;
+                       query_contact.Fields = fields_contact;
+                       OnQuery(query_contact);
+               }
+       }
+
+       Array::Ptr contactgroups = CompatUtility::GetServiceNotificationUserGroups(service);
+       Log(LogDebug, "db_ido", "service contactgroups: " + service->GetName() + " length: " + Convert::ToString(contactgroups->GetLength()));
+       {
+               ObjectLock olock(contactgroups);
+               BOOST_FOREACH(const UserGroup::Ptr& usergroup, contactgroups) {
+                       Log(LogDebug, "db_ido", "service contactgroups: " + usergroup->GetName());
+
+                       Dictionary::Ptr fields_contact = boost::make_shared<Dictionary>();
+                       fields_contact->Set("service_id", DbValue::FromObjectInsertID(service));
+                       fields_contact->Set("contactgroup_object_id", usergroup);
+
+                       DbQuery query_contact;
+                       query_contact.Table = GetType()->GetTable() + "_contactgroups";
+                       query_contact.Type = DbQueryInsert;
+                       query_contact.Fields = fields_contact;
+                       OnQuery(query_contact);
+               }
+       }
+
        /* custom variables */
        Log(LogDebug, "db_ido", "service customvars for '" + service->GetName() + "'");