2013-07-17 14:10:28 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2018-01-02 12:06:00 +01:00
|
|
|
* Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
|
2013-07-17 14:10:28 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "db_ido/servicedbobject.hpp"
|
2015-11-11 11:55:20 +01:00
|
|
|
#include "db_ido/servicegroupdbobject.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "db_ido/dbtype.hpp"
|
|
|
|
#include "db_ido/dbvalue.hpp"
|
|
|
|
#include "db_ido/dbevents.hpp"
|
|
|
|
#include "icinga/notification.hpp"
|
|
|
|
#include "icinga/dependency.hpp"
|
|
|
|
#include "icinga/checkcommand.hpp"
|
|
|
|
#include "icinga/eventcommand.hpp"
|
|
|
|
#include "icinga/externalcommandprocessor.hpp"
|
|
|
|
#include "icinga/compatutility.hpp"
|
2017-12-06 17:03:56 +01:00
|
|
|
#include "icinga/pluginutility.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/icingaapplication.hpp"
|
|
|
|
#include "remote/endpoint.hpp"
|
|
|
|
#include "base/convert.hpp"
|
|
|
|
#include "base/objectlock.hpp"
|
|
|
|
#include "base/initialize.hpp"
|
2015-08-15 20:28:05 +02:00
|
|
|
#include "base/configtype.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/utility.hpp"
|
2014-10-19 14:21:12 +02:00
|
|
|
#include "base/logger.hpp"
|
2015-10-22 15:48:53 +02:00
|
|
|
#include "base/json.hpp"
|
2013-09-30 19:32:32 +02:00
|
|
|
#include <boost/algorithm/string/join.hpp>
|
2013-07-17 14:10:28 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2013-08-02 17:12:07 +02:00
|
|
|
REGISTER_DBTYPE(Service, "service", DbObjectTypeService, "service_object_id", ServiceDbObject);
|
2013-07-17 14:10:28 +02:00
|
|
|
|
2013-08-01 13:20:30 +02:00
|
|
|
ServiceDbObject::ServiceDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
|
|
|
|
: DbObject(type, name1, name2)
|
2013-07-17 14:10:28 +02:00
|
|
|
{ }
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
Dictionary::Ptr ServiceDbObject::GetConfigFields() const
|
2013-07-17 14:10:28 +02:00
|
|
|
{
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr fields = new Dictionary();
|
2013-07-17 14:10:28 +02:00
|
|
|
Service::Ptr service = static_pointer_cast<Service>(GetObject());
|
2013-07-23 11:02:47 +02:00
|
|
|
Host::Ptr host = service->GetHost();
|
|
|
|
|
|
|
|
fields->Set("host_object_id", host);
|
2013-07-17 14:10:28 +02:00
|
|
|
fields->Set("display_name", service->GetDisplayName());
|
2013-07-22 12:08:49 +02:00
|
|
|
fields->Set("check_command_object_id", service->GetCheckCommand());
|
2013-07-31 18:06:54 +02:00
|
|
|
fields->Set("eventhandler_command_object_id", service->GetEventCommand());
|
|
|
|
fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
|
2017-12-21 12:08:42 +01:00
|
|
|
fields->Set("check_interval", service->GetCheckInterval() / 60.0);
|
|
|
|
fields->Set("retry_interval", service->GetRetryInterval() / 60.0);
|
2013-12-05 14:54:16 +01:00
|
|
|
fields->Set("max_check_attempts", service->GetMaxCheckAttempts());
|
2017-12-05 19:51:34 +01:00
|
|
|
fields->Set("is_volatile", service->GetVolatile());
|
2017-12-05 15:28:08 +01:00
|
|
|
fields->Set("flap_detection_enabled", service->GetEnableFlapping());
|
2017-12-05 19:51:34 +01:00
|
|
|
fields->Set("low_flap_threshold", service->GetFlappingThresholdLow());
|
|
|
|
fields->Set("high_flap_threshold", service->GetFlappingThresholdLow());
|
2017-12-05 15:28:08 +01:00
|
|
|
fields->Set("process_performance_data", service->GetEnablePerfdata());
|
2017-12-06 15:35:27 +01:00
|
|
|
fields->Set("freshness_checks_enabled", 1);
|
|
|
|
fields->Set("freshness_threshold", Convert::ToLong(service->GetCheckInterval()));
|
2017-12-05 15:28:08 +01:00
|
|
|
fields->Set("event_handler_enabled", service->GetEnableEventHandler());
|
|
|
|
fields->Set("passive_checks_enabled", service->GetEnablePassiveChecks());
|
|
|
|
fields->Set("active_checks_enabled", service->GetEnableActiveChecks());
|
|
|
|
fields->Set("notifications_enabled", service->GetEnableNotifications());
|
2014-04-17 13:49:45 +02:00
|
|
|
fields->Set("notes", service->GetNotes());
|
|
|
|
fields->Set("notes_url", service->GetNotesUrl());
|
|
|
|
fields->Set("action_url", service->GetActionUrl());
|
|
|
|
fields->Set("icon_image", service->GetIconImage());
|
|
|
|
fields->Set("icon_image_alt", service->GetIconImageAlt());
|
2013-07-17 14:10:28 +02:00
|
|
|
|
2017-12-21 10:32:39 +01:00
|
|
|
fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(service));
|
|
|
|
|
|
|
|
unsigned long notificationStateFilter = CompatUtility::GetCheckableNotificationTypeFilter(service);
|
|
|
|
unsigned long notificationTypeFilter = CompatUtility::GetCheckableNotificationTypeFilter(service);
|
|
|
|
|
|
|
|
fields->Set("notify_on_warning", notificationStateFilter & ServiceWarning);
|
|
|
|
fields->Set("notify_on_unknown", notificationStateFilter & ServiceUnknown);
|
|
|
|
fields->Set("notify_on_critical", notificationStateFilter & ServiceCritical);
|
|
|
|
fields->Set("notify_on_recovery", notificationTypeFilter & NotificationRecovery);
|
|
|
|
fields->Set("notify_on_flapping", (notificationTypeFilter & NotificationFlappingStart) ||
|
|
|
|
(notificationTypeFilter & NotificationFlappingEnd));
|
|
|
|
fields->Set("notify_on_downtime", (notificationTypeFilter & NotificationDowntimeStart) ||
|
|
|
|
(notificationTypeFilter & NotificationDowntimeEnd) || (notificationTypeFilter & NotificationDowntimeRemoved));
|
|
|
|
|
2013-07-17 14:10:28 +02:00
|
|
|
return fields;
|
|
|
|
}
|
2013-07-22 12:08:49 +02:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
Dictionary::Ptr ServiceDbObject::GetStatusFields() const
|
2013-07-22 12:08:49 +02:00
|
|
|
{
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr fields = new Dictionary();
|
2013-07-22 12:08:49 +02:00
|
|
|
Service::Ptr service = static_pointer_cast<Service>(GetObject());
|
2013-12-05 14:54:16 +01:00
|
|
|
CheckResult::Ptr cr = service->GetLastCheckResult();
|
2013-07-23 09:50:42 +02:00
|
|
|
|
2013-12-05 14:54:16 +01:00
|
|
|
if (cr) {
|
|
|
|
fields->Set("output", CompatUtility::GetCheckResultOutput(cr));
|
|
|
|
fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
|
2017-12-06 17:03:56 +01:00
|
|
|
fields->Set("perfdata", PluginUtility::FormatPerfdata(cr->GetPerformanceData()));
|
2014-03-21 10:09:34 +01:00
|
|
|
fields->Set("check_source", cr->GetCheckSource());
|
2017-12-21 10:32:39 +01:00
|
|
|
fields->Set("latency", cr->CalculateLatency());
|
|
|
|
fields->Set("execution_time", cr->CalculateExecutionTime());
|
2013-07-23 09:50:42 +02:00
|
|
|
}
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
fields->Set("current_state", service->GetState());
|
2017-12-05 14:23:15 +01:00
|
|
|
fields->Set("has_been_checked", service->HasBeenChecked());
|
2014-04-08 13:34:48 +02:00
|
|
|
fields->Set("should_be_scheduled", service->GetEnableActiveChecks());
|
2013-12-05 14:54:16 +01:00
|
|
|
fields->Set("current_check_attempt", service->GetCheckAttempt());
|
|
|
|
fields->Set("max_check_attempts", service->GetMaxCheckAttempts());
|
2017-12-21 10:32:39 +01:00
|
|
|
fields->Set("last_check", DbValue::FromTimestamp(service->GetLastCheck()));
|
2013-12-05 14:54:16 +01:00
|
|
|
fields->Set("next_check", DbValue::FromTimestamp(service->GetNextCheck()));
|
2017-12-05 11:34:38 +01:00
|
|
|
fields->Set("check_type", !service->GetEnableActiveChecks()); /* 0 .. active, 1 .. passive */
|
2013-12-05 14:54:16 +01:00
|
|
|
fields->Set("last_state_change", DbValue::FromTimestamp(service->GetLastStateChange()));
|
|
|
|
fields->Set("last_hard_state_change", DbValue::FromTimestamp(service->GetLastHardStateChange()));
|
2014-12-12 13:25:10 +01:00
|
|
|
fields->Set("last_hard_state", service->GetLastHardState());
|
2017-12-21 10:32:39 +01:00
|
|
|
fields->Set("last_time_ok", DbValue::FromTimestamp(service->GetLastStateOK()));
|
|
|
|
fields->Set("last_time_warning", DbValue::FromTimestamp(service->GetLastStateWarning()));
|
|
|
|
fields->Set("last_time_critical", DbValue::FromTimestamp(service->GetLastStateCritical()));
|
|
|
|
fields->Set("last_time_unknown", DbValue::FromTimestamp(service->GetLastStateUnknown()));
|
2013-12-05 14:54:16 +01:00
|
|
|
fields->Set("state_type", service->GetStateType());
|
2017-12-05 15:28:08 +01:00
|
|
|
fields->Set("notifications_enabled", service->GetEnableNotifications());
|
2017-12-05 13:35:09 +01:00
|
|
|
fields->Set("problem_has_been_acknowledged", service->GetAcknowledgement() != AcknowledgementNone);
|
2017-12-05 14:17:57 +01:00
|
|
|
fields->Set("acknowledgement_type", service->GetAcknowledgement());
|
2017-12-05 15:28:08 +01:00
|
|
|
fields->Set("passive_checks_enabled", service->GetEnablePassiveChecks());
|
|
|
|
fields->Set("active_checks_enabled", service->GetEnableActiveChecks());
|
|
|
|
fields->Set("event_handler_enabled", service->GetEnableEventHandler());
|
|
|
|
fields->Set("flap_detection_enabled", service->GetEnableFlapping());
|
2017-12-05 18:53:22 +01:00
|
|
|
fields->Set("is_flapping", service->IsFlapping());
|
|
|
|
fields->Set("percent_state_change", service->GetFlappingCurrent());
|
2013-12-05 14:54:16 +01:00
|
|
|
fields->Set("scheduled_downtime_depth", service->GetDowntimeDepth());
|
2017-12-05 15:28:08 +01:00
|
|
|
fields->Set("process_performance_data", service->GetEnablePerfdata());
|
2017-12-21 12:08:42 +01:00
|
|
|
fields->Set("normal_check_interval", service->GetCheckInterval() / 60.0);
|
|
|
|
fields->Set("retry_check_interval", service->GetRetryInterval() / 60.0);
|
2013-07-31 18:06:54 +02:00
|
|
|
fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
|
2017-12-05 18:53:22 +01:00
|
|
|
fields->Set("is_reachable", service->IsReachable());
|
2015-10-22 15:48:53 +02:00
|
|
|
fields->Set("original_attributes", JsonEncode(service->GetOriginalAttributes()));
|
|
|
|
|
2017-12-21 10:32:39 +01:00
|
|
|
fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(service));
|
|
|
|
fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationLastNotification(service)));
|
|
|
|
fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationNextNotification(service)));
|
|
|
|
|
2017-12-05 19:30:45 +01:00
|
|
|
EventCommand::Ptr eventCommand = service->GetEventCommand();
|
|
|
|
|
|
|
|
if (eventCommand)
|
|
|
|
fields->Set("event_handler", eventCommand->GetName());
|
|
|
|
|
|
|
|
CheckCommand::Ptr checkCommand = service->GetCheckCommand();
|
|
|
|
|
|
|
|
if (checkCommand)
|
|
|
|
fields->Set("check_command", checkCommand->GetName());
|
|
|
|
|
2013-07-22 12:08:49 +02:00
|
|
|
return fields;
|
2013-07-24 10:55:04 +02:00
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void ServiceDbObject::OnConfigUpdateHeavy()
|
2013-07-25 08:30:02 +02:00
|
|
|
{
|
|
|
|
Service::Ptr service = static_pointer_cast<Service>(GetObject());
|
2013-08-05 17:25:40 +02:00
|
|
|
|
2015-11-11 11:55:20 +01:00
|
|
|
/* groups */
|
|
|
|
Array::Ptr groups = service->GetGroups();
|
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
std::vector<DbQuery> queries;
|
|
|
|
|
|
|
|
DbQuery query1;
|
|
|
|
query1.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
|
|
|
|
query1.Type = DbQueryDelete;
|
|
|
|
query1.Category = DbCatConfig;
|
|
|
|
query1.WhereCriteria = new Dictionary();
|
|
|
|
query1.WhereCriteria->Set("service_object_id", service);
|
2017-11-30 08:19:58 +01:00
|
|
|
queries.emplace_back(std::move(query1));
|
2016-08-14 22:24:51 +02:00
|
|
|
|
2015-11-11 11:55:20 +01:00
|
|
|
if (groups) {
|
|
|
|
ObjectLock olock(groups);
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const String& groupName : groups) {
|
2015-11-11 11:55:20 +01:00
|
|
|
ServiceGroup::Ptr group = ServiceGroup::GetByName(groupName);
|
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
DbQuery query2;
|
|
|
|
query2.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
|
|
|
|
query2.Type = DbQueryInsert;
|
|
|
|
query2.Category = DbCatConfig;
|
|
|
|
query2.Fields = new Dictionary();
|
|
|
|
query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
|
|
|
query2.Fields->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
|
|
|
|
query2.Fields->Set("service_object_id", service);
|
|
|
|
query2.WhereCriteria = new Dictionary();
|
|
|
|
query2.WhereCriteria->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
|
|
|
query2.WhereCriteria->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
|
|
|
|
query2.WhereCriteria->Set("service_object_id", service);
|
2017-11-30 08:19:58 +01:00
|
|
|
queries.emplace_back(std::move(query2));
|
2015-11-11 11:55:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
DbObject::OnMultipleQueries(queries);
|
|
|
|
|
2013-08-05 17:25:40 +02:00
|
|
|
/* service dependencies */
|
2014-10-19 17:52:17 +02:00
|
|
|
Log(LogDebug, "ServiceDbObject")
|
2017-12-19 15:50:05 +01:00
|
|
|
<< "service dependencies for '" << service->GetName() << "'";
|
2013-08-05 17:25:40 +02:00
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
queries.clear();
|
|
|
|
|
|
|
|
DbQuery query2;
|
|
|
|
query2.Table = GetType()->GetTable() + "dependencies";
|
|
|
|
query2.Type = DbQueryDelete;
|
|
|
|
query2.Category = DbCatConfig;
|
|
|
|
query2.WhereCriteria = new Dictionary();
|
|
|
|
query2.WhereCriteria->Set("dependent_service_object_id", service);
|
2017-11-30 08:19:58 +01:00
|
|
|
queries.emplace_back(std::move(query2));
|
2016-08-14 22:24:51 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Dependency::Ptr& dep : service->GetDependencies()) {
|
2014-04-23 10:33:30 +02:00
|
|
|
Checkable::Ptr parent = dep->GetParent();
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2014-05-03 21:02:19 +02:00
|
|
|
if (!parent) {
|
2014-10-19 17:52:17 +02:00
|
|
|
Log(LogDebug, "ServiceDbObject")
|
2017-12-19 15:50:05 +01:00
|
|
|
<< "Missing parent for dependency '" << dep->GetName() << "'.";
|
2014-04-03 15:36:13 +02:00
|
|
|
continue;
|
2014-05-03 21:02:19 +02:00
|
|
|
}
|
2014-04-03 15:36:13 +02:00
|
|
|
|
2014-10-19 17:52:17 +02:00
|
|
|
Log(LogDebug, "ServiceDbObject")
|
2017-12-19 15:50:05 +01:00
|
|
|
<< "service parents: " << parent->GetName();
|
2013-08-05 17:25:40 +02:00
|
|
|
|
2017-12-21 12:08:42 +01:00
|
|
|
int stateFilter = dep->GetStateFilter();
|
2014-04-23 10:33:30 +02:00
|
|
|
|
|
|
|
/* service dependencies */
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr fields1 = new Dictionary();
|
2014-04-23 10:33:30 +02:00
|
|
|
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());
|
2017-12-21 12:08:42 +01:00
|
|
|
fields1->Set("fail_on_ok", stateFilter & StateFilterOK);
|
|
|
|
fields1->Set("fail_on_warning", stateFilter & StateFilterWarning);
|
|
|
|
fields1->Set("fail_on_critical", stateFilter & StateFilterCritical);
|
|
|
|
fields1->Set("fail_on_unknown", stateFilter & StateFilterUnknown);
|
2014-04-23 10:33:30 +02:00
|
|
|
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
|
|
|
|
|
|
|
DbQuery query1;
|
|
|
|
query1.Table = GetType()->GetTable() + "dependencies";
|
|
|
|
query1.Type = DbQueryInsert;
|
2013-10-29 15:54:43 +01:00
|
|
|
query1.Category = DbCatConfig;
|
2014-04-23 10:33:30 +02:00
|
|
|
query1.Fields = fields1;
|
2017-11-30 08:19:58 +01:00
|
|
|
queries.emplace_back(std::move(query1));
|
2013-08-05 17:25:40 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
DbObject::OnMultipleQueries(queries);
|
|
|
|
|
2013-10-01 16:43:25 +02:00
|
|
|
/* service contacts, contactgroups */
|
2014-10-19 17:52:17 +02:00
|
|
|
Log(LogDebug, "ServiceDbObject")
|
2017-12-19 15:50:05 +01:00
|
|
|
<< "service contacts: " << service->GetName();
|
2013-10-01 16:43:25 +02:00
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
queries.clear();
|
|
|
|
|
|
|
|
DbQuery query3;
|
|
|
|
query3.Table = GetType()->GetTable() + "_contacts";
|
|
|
|
query3.Type = DbQueryDelete;
|
|
|
|
query3.Category = DbCatConfig;
|
|
|
|
query3.WhereCriteria = new Dictionary();
|
|
|
|
query3.WhereCriteria->Set("service_id", DbValue::FromObjectInsertID(service));
|
2017-11-30 08:19:58 +01:00
|
|
|
queries.emplace_back(std::move(query3));
|
2016-08-14 22:24:51 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(service)) {
|
2014-10-19 17:52:17 +02:00
|
|
|
Log(LogDebug, "ServiceDbObject")
|
2017-12-19 15:50:05 +01:00
|
|
|
<< "service contacts: " << user->GetName();
|
2013-10-02 21:09:13 +02:00
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr fields_contact = new Dictionary();
|
2013-10-02 21:09:13 +02:00
|
|
|
fields_contact->Set("service_id", DbValue::FromObjectInsertID(service));
|
|
|
|
fields_contact->Set("contact_object_id", user);
|
|
|
|
fields_contact->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
|
|
|
|
|
|
|
DbQuery query_contact;
|
|
|
|
query_contact.Table = GetType()->GetTable() + "_contacts";
|
|
|
|
query_contact.Type = DbQueryInsert;
|
2013-10-29 15:54:43 +01:00
|
|
|
query_contact.Category = DbCatConfig;
|
2013-10-02 21:09:13 +02:00
|
|
|
query_contact.Fields = fields_contact;
|
2017-11-30 08:19:58 +01:00
|
|
|
queries.emplace_back(std::move(query_contact));
|
2013-10-01 16:43:25 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
DbObject::OnMultipleQueries(queries);
|
|
|
|
|
2014-10-20 10:09:57 +02:00
|
|
|
Log(LogDebug, "ServiceDbObject")
|
2017-12-19 15:50:05 +01:00
|
|
|
<< "service contactgroups: " << service->GetName();
|
2013-10-02 21:09:13 +02:00
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
queries.clear();
|
|
|
|
|
|
|
|
DbQuery query4;
|
|
|
|
query4.Table = GetType()->GetTable() + "_contactgroups";
|
|
|
|
query4.Type = DbQueryDelete;
|
|
|
|
query4.Category = DbCatConfig;
|
|
|
|
query4.WhereCriteria = new Dictionary();
|
|
|
|
query4.WhereCriteria->Set("service_id", DbValue::FromObjectInsertID(service));
|
2017-11-30 08:19:58 +01:00
|
|
|
queries.emplace_back(std::move(query4));
|
2016-08-14 22:24:51 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(service)) {
|
2014-10-19 17:52:17 +02:00
|
|
|
Log(LogDebug, "ServiceDbObject")
|
2017-12-19 15:50:05 +01:00
|
|
|
<< "service contactgroups: " << usergroup->GetName();
|
2013-10-02 21:09:13 +02:00
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Dictionary::Ptr fields_contact = new Dictionary();
|
2013-10-02 21:09:13 +02:00
|
|
|
fields_contact->Set("service_id", DbValue::FromObjectInsertID(service));
|
|
|
|
fields_contact->Set("contactgroup_object_id", usergroup);
|
|
|
|
fields_contact->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
|
|
|
|
|
|
|
DbQuery query_contact;
|
|
|
|
query_contact.Table = GetType()->GetTable() + "_contactgroups";
|
|
|
|
query_contact.Type = DbQueryInsert;
|
2013-10-29 15:54:43 +01:00
|
|
|
query_contact.Category = DbCatConfig;
|
2013-10-02 21:09:13 +02:00
|
|
|
query_contact.Fields = fields_contact;
|
2017-11-30 08:19:58 +01:00
|
|
|
queries.emplace_back(std::move(query_contact));
|
2013-10-01 16:43:25 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
DbObject::OnMultipleQueries(queries);
|
|
|
|
|
|
|
|
DoCommonConfigUpdate();
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void ServiceDbObject::OnConfigUpdateLight()
|
2016-08-14 22:24:51 +02:00
|
|
|
{
|
|
|
|
DoCommonConfigUpdate();
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void ServiceDbObject::DoCommonConfigUpdate()
|
2016-08-14 22:24:51 +02:00
|
|
|
{
|
|
|
|
Service::Ptr service = static_pointer_cast<Service>(GetObject());
|
|
|
|
|
2013-08-12 11:08:29 +02:00
|
|
|
/* update comments and downtimes on config change */
|
2014-04-03 15:36:13 +02:00
|
|
|
DbEvents::AddComments(service);
|
|
|
|
DbEvents::AddDowntimes(service);
|
2013-07-25 08:30:02 +02:00
|
|
|
}
|
|
|
|
|
2016-08-14 22:24:51 +02:00
|
|
|
String ServiceDbObject::CalculateConfigHash(const Dictionary::Ptr& configFields) const
|
2013-07-25 08:30:02 +02:00
|
|
|
{
|
2016-08-14 22:24:51 +02:00
|
|
|
String hashData = DbObject::CalculateConfigHash(configFields);
|
|
|
|
|
|
|
|
Service::Ptr service = static_pointer_cast<Service>(GetObject());
|
2016-08-24 11:35:12 +02:00
|
|
|
|
|
|
|
Array::Ptr groups = service->GetGroups();
|
|
|
|
|
|
|
|
if (groups)
|
|
|
|
hashData += DbObject::HashValue(groups);
|
2016-08-14 22:24:51 +02:00
|
|
|
|
|
|
|
Array::Ptr dependencies = new Array();
|
|
|
|
|
|
|
|
/* dependencies */
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Dependency::Ptr& dep : service->GetDependencies()) {
|
2016-08-14 22:24:51 +02:00
|
|
|
Checkable::Ptr parent = dep->GetParent();
|
|
|
|
|
|
|
|
if (!parent)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Array::Ptr depInfo = new Array();
|
|
|
|
depInfo->Add(parent->GetName());
|
|
|
|
depInfo->Add(dep->GetStateFilter());
|
|
|
|
depInfo->Add(dep->GetPeriodRaw());
|
|
|
|
|
|
|
|
dependencies->Add(depInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
dependencies->Sort();
|
|
|
|
|
|
|
|
hashData += DbObject::HashValue(dependencies);
|
|
|
|
|
|
|
|
Array::Ptr users = new Array();
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(service)) {
|
2016-08-14 22:24:51 +02:00
|
|
|
users->Add(user->GetName());
|
|
|
|
}
|
|
|
|
|
|
|
|
users->Sort();
|
|
|
|
|
|
|
|
hashData += DbObject::HashValue(users);
|
|
|
|
|
|
|
|
Array::Ptr userGroups = new Array();
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(service)) {
|
2016-08-14 22:24:51 +02:00
|
|
|
userGroups->Add(usergroup->GetName());
|
|
|
|
}
|
|
|
|
|
|
|
|
userGroups->Sort();
|
|
|
|
|
|
|
|
hashData += DbObject::HashValue(userGroups);
|
|
|
|
|
|
|
|
return SHA256(hashData);
|
2013-10-03 03:41:47 +02:00
|
|
|
}
|