Add downtimes sync

This commit is contained in:
Jean Flach 2018-10-26 16:33:39 +02:00 committed by Michael Friedrich
parent 36588ce31a
commit 77ce8f67bd
1 changed files with 28 additions and 0 deletions

View File

@ -463,6 +463,24 @@ void RedisWriter::CreateConfigUpdate(const ConfigObject::Ptr& object, std::vecto
}
}
icinga::Downtime::Ptr downtime = dynamic_pointer_cast<Downtime>(object);
if (downtime) {
propertiesBlacklist.emplace("name");
propertiesBlacklist.emplace("host_name");
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(downtime->GetCheckable());
if (service) {
propertiesBlacklist.emplace("service_name");
checkSums->Set("service_checksum", GetObjectIdentifier(service));
typeName = "servicedowntime";
} else {
checkSums->Set("host_checksum", GetObjectIdentifier(host));
typeName = "hostdowntime";
}
}
/* Send all object attributes to Redis, no extra checksums involved here. */
auto tempAttrs = (UpdateObjectAttrs(m_PrefixConfigObject, object, FAConfig, typeName));
attributes.insert(attributes.end(), std::begin(tempAttrs), std::end(tempAttrs));
@ -486,6 +504,8 @@ void RedisWriter::CreateConfigUpdate(const ConfigObject::Ptr& object, std::vecto
}
checkSums->Set("metadata_checksum", CalculateCheckSumMetadata(object));
/* TODO: Problem: This does not account for `is_in_effect`, `trigger_time` of downtimes. */
checkSums->Set("properties_checksum", CalculateCheckSumProperties(object, propertiesBlacklist));
String checkSumsBody = JsonEncode(checkSums);
@ -622,6 +642,14 @@ RedisWriter::UpdateObjectAttrs(const String& keyPrefix, const ConfigObject::Ptr&
attrs->Set(field.Name, Serialize(val));
}
/* Downtimes require in_effect, which is not an attribute */
Downtime::Ptr downtime = dynamic_pointer_cast<Downtime>(object);
if (downtime) {
attrs->Set("in_effect", Serialize(downtime->IsInEffect()));
attrs->Set("trigger_time", Serialize(downtime->GetTriggerTime()));
}
/* Use the name checksum as unique key. */
String typeName = type->GetName().ToLower();
if (!typeNameOverride.IsEmpty())