本文整理汇总了C++中downtime::Ptr::GetName方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::GetName方法的具体用法?C++ Ptr::GetName怎么用?C++ Ptr::GetName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类downtime::Ptr
的用法示例。
在下文中一共展示了Ptr::GetName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RemoveDowntime
void Downtime::RemoveDowntime(const String& id, bool cancelled, bool expired, const MessageOrigin::Ptr& origin)
{
Downtime::Ptr downtime = Downtime::GetByName(id);
if (!downtime)
return;
String config_owner = downtime->GetConfigOwner();
if (!config_owner.IsEmpty() && !expired) {
Log(LogWarning, "Downtime")
<< "Cannot remove downtime '" << downtime->GetName() << "'. It is owned by scheduled downtime object '" << config_owner << "'";
return;
}
downtime->SetWasCancelled(cancelled);
Log(LogNotice, "Downtime")
<< "Removed downtime '" << downtime->GetName() << "' from object '" << downtime->GetCheckable()->GetName() << "'.";
if (downtime->GetPackage() != "_api")
return;
Array::Ptr errors = new Array();
if (!ConfigObjectUtility::DeleteObject(downtime, false, errors)) {
ObjectLock olock(errors);
for (const String& error : errors) {
Log(LogCritical, "Downtime", error);
}
BOOST_THROW_EXCEPTION(std::runtime_error("Could not remove downtime."));
}
}
示例2: AddDowntime
String Downtime::AddDowntime(const Checkable::Ptr& checkable, const String& author,
const String& comment, double startTime, double endTime, bool fixed,
const String& triggeredBy, double duration,
const String& scheduledDowntime, const String& scheduledBy,
const String& id, const MessageOrigin::Ptr& origin)
{
String fullName;
if (id.IsEmpty())
fullName = checkable->GetName() + "!" + Utility::NewUniqueID();
else
fullName = id;
Dictionary::Ptr attrs = new Dictionary();
attrs->Set("author", author);
attrs->Set("comment", comment);
attrs->Set("start_time", startTime);
attrs->Set("end_time", endTime);
attrs->Set("fixed", fixed);
attrs->Set("duration", duration);
attrs->Set("triggered_by", triggeredBy);
attrs->Set("scheduled_by", scheduledBy);
attrs->Set("config_owner", scheduledDowntime);
attrs->Set("entry_time", Utility::GetTime());
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
attrs->Set("host_name", host->GetName());
if (service)
attrs->Set("service_name", service->GetShortName());
String zone = checkable->GetZoneName();
if (!zone.IsEmpty())
attrs->Set("zone", zone);
String config = ConfigObjectUtility::CreateObjectConfig(Downtime::TypeInstance, fullName, true, Array::Ptr(), attrs);
Array::Ptr errors = new Array();
if (!ConfigObjectUtility::CreateObject(Downtime::TypeInstance, fullName, config, errors)) {
ObjectLock olock(errors);
for (const String& error : errors) {
Log(LogCritical, "Downtime", error);
}
BOOST_THROW_EXCEPTION(std::runtime_error("Could not create downtime."));
}
if (!triggeredBy.IsEmpty()) {
Downtime::Ptr parentDowntime = Downtime::GetByName(triggeredBy);
Array::Ptr triggers = parentDowntime->GetTriggers();
ObjectLock olock(triggers);
if (!triggers->Contains(fullName))
triggers->Add(fullName);
}
Downtime::Ptr downtime = Downtime::GetByName(fullName);
if (!downtime)
BOOST_THROW_EXCEPTION(std::runtime_error("Could not create downtime object."));
Log(LogNotice, "Downtime")
<< "Added downtime '" << downtime->GetName()
<< "' between '" << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S", startTime)
<< "' and '" << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S", endTime) << "'.";
return fullName;
}