From: Michael Friedrich Date: Tue, 1 Oct 2013 14:43:25 +0000 (+0200) Subject: db_ido: Add {host,service}_{contacts,contactgroups}. X-Git-Tag: v0.0.3~301 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f2e413ba4af37df6ed4db0633941e8105736bbac;p=icinga2 db_ido: Add {host,service}_{contacts,contactgroups}. refs #4378 --- diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 8cb2e408f..70fcb6ecd 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -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(); @@ -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(); + 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(); + 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(); fields3->Set("varname", Convert::ToString(key)); diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index c22d72ebe..acbe80649 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -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(); + 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(); + 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() + "'");