本文整理汇总了C++中service::Ptr类的典型用法代码示例。如果您正苦于以下问题:C++ Ptr类的具体用法?C++ Ptr怎么用?C++ Ptr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ptr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DisplayNameAccessor
Value ServicesTable::DisplayNameAccessor(const Value& row)
{
Service::Ptr service = static_cast<Service::Ptr>(row);
if (!service)
return Empty;
return service->GetDisplayName();
}
示例2: IconImageAltAccessor
Value ServicesTable::IconImageAltAccessor(const Value& row)
{
Service::Ptr service = static_cast<Service::Ptr>(row);
if (!service)
return Empty;
return service->GetIconImageAlt();
}
示例3: CheckResultHandler
void OpenTsdbWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
{
CONTEXT("Processing check result for '" + checkable->GetName() + "'");
if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !checkable->GetEnablePerfdata())
return;
Service::Ptr service = dynamic_pointer_cast<Service>(checkable);
Host::Ptr host;
if (service)
host = service->GetHost();
else
host = static_pointer_cast<Host>(checkable);
String metric;
std::map<String, String> tags;
String escaped_hostName = EscapeTag(host->GetName());
tags["host"] = escaped_hostName;
double ts = cr->GetExecutionEnd();
if (service) {
String serviceName = service->GetShortName();
String escaped_serviceName = EscapeMetric(serviceName);
metric = "icinga.service." + escaped_serviceName;
SendMetric(metric + ".state", tags, service->GetState(), ts);
} else {
metric = "icinga.host";
SendMetric(metric + ".state", tags, host->GetState(), ts);
}
SendMetric(metric + ".state_type", tags, checkable->GetStateType(), ts);
SendMetric(metric + ".reachable", tags, checkable->IsReachable(), ts);
SendMetric(metric + ".downtime_depth", tags, checkable->GetDowntimeDepth(), ts);
SendMetric(metric + ".acknowledgement", tags, checkable->GetAcknowledgement(), ts);
SendPerfdata(metric, tags, cr, ts);
metric = "icinga.check";
if (service) {
tags["type"] = "service";
String serviceName = service->GetShortName();
String escaped_serviceName = EscapeTag(serviceName);
tags["service"] = escaped_serviceName;
} else {
tags["type"] = "host";
}
SendMetric(metric + ".current_attempt", tags, checkable->GetCheckAttempt(), ts);
SendMetric(metric + ".max_check_attempts", tags, checkable->GetMaxCheckAttempts(), ts);
SendMetric(metric + ".latency", tags, cr->CalculateLatency(), ts);
SendMetric(metric + ".execution_time", tags, cr->CalculateExecutionTime(), ts);
}
示例4: NotificationTimerHandler
/**
* Periodically sends notifications.
*
* @param - Event arguments for the timer.
*/
void NotificationComponent::NotificationTimerHandler(void)
{
double now = Utility::GetTime();
for (const Notification::Ptr& notification : ConfigType::GetObjectsByType<Notification>()) {
if (!notification->IsActive())
continue;
if (notification->IsPaused() && GetEnableHA())
continue;
Checkable::Ptr checkable = notification->GetCheckable();
if (!IcingaApplication::GetInstance()->GetEnableNotifications() || !checkable->GetEnableNotifications())
continue;
if (notification->GetInterval() <= 0 && notification->GetNoMoreNotifications())
continue;
if (notification->GetNextNotification() > now)
continue;
bool reachable = checkable->IsReachable(DependencyNotification);
{
ObjectLock olock(notification);
notification->SetNextNotification(Utility::GetTime() + notification->GetInterval());
}
{
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
ObjectLock olock(checkable);
if (checkable->GetStateType() == StateTypeSoft)
continue;
if ((service && service->GetState() == ServiceOK) || (!service && host->GetState() == HostUp))
continue;
if (!reachable || checkable->IsInDowntime() || checkable->IsAcknowledged())
continue;
}
try {
Log(LogNotice, "NotificationComponent")
<< "Attempting to send reminder notification '" << notification->GetName() << "'";
notification->BeginExecuteNotification(NotificationProblem, checkable->GetLastCheckResult(), false, true);
} catch (const std::exception& ex) {
Log(LogWarning, "NotificationComponent")
<< "Exception occured during notification for object '"
<< GetName() << "': " << DiagnosticInformation(ex);
}
}
}
示例5: NotificationSentToAllUsersHandlerInternal
void ElasticsearchWriter::NotificationSentToAllUsersHandlerInternal(const Notification::Ptr& notification,
const Checkable::Ptr& checkable, const std::set<User::Ptr>& users, NotificationType type,
const CheckResult::Ptr& cr, const String& author, const String& text)
{
AssertOnWorkQueue();
CONTEXT("Elasticwriter processing notification to all users '" + checkable->GetName() + "'");
Log(LogDebug, "ElasticsearchWriter")
<< "Processing notification for '" << checkable->GetName() << "'";
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
String notificationTypeString = Notification::NotificationTypeToString(type);
Dictionary::Ptr fields = new Dictionary();
if (service) {
fields->Set("service", service->GetShortName());
fields->Set("state", service->GetState());
fields->Set("last_state", service->GetLastState());
fields->Set("last_hard_state", service->GetLastHardState());
} else {
fields->Set("state", host->GetState());
fields->Set("last_state", host->GetLastState());
fields->Set("last_hard_state", host->GetLastHardState());
}
fields->Set("host", host->GetName());
ArrayData userNames;
for (const User::Ptr& user : users) {
userNames.push_back(user->GetName());
}
fields->Set("users", new Array(std::move(userNames)));
fields->Set("notification_type", notificationTypeString);
fields->Set("author", author);
fields->Set("text", text);
CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
if (commandObj)
fields->Set("check_command", commandObj->GetName());
double ts = Utility::GetTime();
if (cr) {
AddCheckResult(fields, checkable, cr);
ts = cr->GetExecutionEnd();
}
Enqueue(checkable, "notification", fields, ts);
}
示例6: NotesAccessor
Value ServicesTable::NotesAccessor(const Value& row)
{
Service::Ptr service = static_cast<Service::Ptr>(row);
if (!service)
return Empty;
return service->GetNotes();
}
示例7: ActionUrlAccessor
Value ServicesTable::ActionUrlAccessor(const Value& row)
{
Service::Ptr service = static_cast<Service::Ptr>(row);
if (!service)
return Empty;
return service->GetActionUrl();
}
示例8: IsReachableAccessor
Value ServicesTable::IsReachableAccessor(const Value& row)
{
Service::Ptr service = static_cast<Service::Ptr>(row);
if (!service)
return Empty;
return service->IsReachable();
}
示例9: OriginalAttributesAccessor
Value ServicesTable::OriginalAttributesAccessor(const Value& row)
{
Service::Ptr service = static_cast<Service::Ptr>(row);
if (!service)
return Empty;
return JsonEncode(service->GetOriginalAttributes());
}
示例10: AcknowledgementTypeAccessor
Value ServicesTable::AcknowledgementTypeAccessor(const Value& row)
{
Service::Ptr service = static_cast<Service::Ptr>(row);
if (!service)
return Empty;
ObjectLock olock(service);
return service->GetAcknowledgement();
}
示例11: OnConfigUpdate
void ServiceDbObject::OnConfigUpdate(void)
{
Service::Ptr service = static_pointer_cast<Service>(GetObject());
/* service dependencies */
Log(LogDebug, "db_ido", "service dependencies for '" + service->GetName() + "'");
BOOST_FOREACH(const Dependency::Ptr& dep, service->GetDependencies()) {
Checkable::Ptr parent = dep->GetParent();
if (!parent)
continue;
Log(LogDebug, "db_ido", "service parents: " + parent->GetName());
int state_filter = dep->GetStateFilter();
/* service dependencies */
Dictionary::Ptr fields1 = make_shared<Dictionary>();
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());
fields1->Set("fail_on_ok", (state_filter & StateFilterOK) ? 1 : 0);
fields1->Set("fail_on_warning", (state_filter & StateFilterWarning) ? 1 : 0);
fields1->Set("fail_on_critical", (state_filter & StateFilterCritical) ? 1 : 0);
fields1->Set("fail_on_unknown", (state_filter & StateFilterUnknown) ? 1 : 0);
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
DbQuery query1;
query1.Table = GetType()->GetTable() + "dependencies";
query1.Type = DbQueryInsert;
query1.Category = DbCatConfig;
query1.Fields = fields1;
OnQuery(query1);
}
/* service contacts, contactgroups */
Log(LogDebug, "db_ido", "service contacts: " + service->GetName());
BOOST_FOREACH(const User::Ptr& user, CompatUtility::GetCheckableNotificationUsers(service)) {
Log(LogDebug, "db_ido", "service contacts: " + user->GetName());
Dictionary::Ptr fields_contact = make_shared<Dictionary>();
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;
query_contact.Category = DbCatConfig;
query_contact.Fields = fields_contact;
OnQuery(query_contact);
}
示例12: CalculateConfigHash
String ServiceDbObject::CalculateConfigHash(const Dictionary::Ptr& configFields) const
{
String hashData = DbObject::CalculateConfigHash(configFields);
Service::Ptr service = static_pointer_cast<Service>(GetObject());
Array::Ptr groups = service->GetGroups();
if (groups)
hashData += DbObject::HashValue(groups);
Array::Ptr dependencies = new Array();
/* dependencies */
for (const Dependency::Ptr& dep : service->GetDependencies()) {
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();
for (const User::Ptr& user : CompatUtility::GetCheckableNotificationUsers(service)) {
users->Add(user->GetName());
}
users->Sort();
hashData += DbObject::HashValue(users);
Array::Ptr userGroups = new Array();
for (const UserGroup::Ptr& usergroup : CompatUtility::GetCheckableNotificationUserGroups(service)) {
userGroups->Add(usergroup->GetName());
}
userGroups->Sort();
hashData += DbObject::HashValue(userGroups);
return SHA256(hashData);
}
示例13: AddComment
String Comment::AddComment(const Checkable::Ptr& checkable, CommentType entryType, const String& author,
const String& text, double expireTime, 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("text", text);
attrs->Set("expire_time", expireTime);
attrs->Set("entry_type", entryType);
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(Comment::TypeInstance, fullName, true, Array::Ptr(), attrs);
Array::Ptr errors = new Array();
if (!ConfigObjectUtility::CreateObject(Comment::TypeInstance, fullName, config, errors)) {
ObjectLock olock(errors);
for (const String& error : errors) {
Log(LogCritical, "Comment", error);
}
BOOST_THROW_EXCEPTION(std::runtime_error("Could not create comment."));
}
Comment::Ptr comment = Comment::GetByName(fullName);
if (!comment)
BOOST_THROW_EXCEPTION(std::runtime_error("Could not create comment."));
Log(LogNotice, "Comment")
<< "Added comment '" << comment->GetName() << "'.";
return fullName;
}
示例14: GetStatusFields
Dictionary::Ptr ServiceDbObject::GetStatusFields(void) const
{
Dictionary::Ptr fields = boost::make_shared<Dictionary>();
Service::Ptr service = static_pointer_cast<Service>(GetObject());
Dictionary::Ptr attrs;
{
ObjectLock olock(service);
attrs = CompatUtility::GetServiceStatusAttributes(service, CompatTypeService);
}
fields->Set("output", attrs->Get("plugin_output"));
fields->Set("long_output", attrs->Get("long_plugin_output"));
fields->Set("perfdata", attrs->Get("performance_data"));
fields->Set("current_state", attrs->Get("current_state"));
fields->Set("has_been_checked", attrs->Get("has_been_checked"));
fields->Set("should_be_scheduled", attrs->Get("should_be_scheduled"));
fields->Set("current_check_attempt", attrs->Get("current_attempt"));
fields->Set("max_check_attempts", attrs->Get("max_attempts"));
fields->Set("last_check", DbValue::FromTimestamp(attrs->Get("last_check")));
fields->Set("next_check", DbValue::FromTimestamp(attrs->Get("next_check")));
fields->Set("check_type", attrs->Get("check_type"));
fields->Set("last_state_change", DbValue::FromTimestamp(attrs->Get("last_state_change")));
fields->Set("last_hard_state_change", DbValue::FromTimestamp(attrs->Get("last_hard_state_change")));
fields->Set("last_time_ok", DbValue::FromTimestamp(attrs->Get("last_time_ok")));
fields->Set("last_time_warning", DbValue::FromTimestamp(attrs->Get("last_time_warn")));
fields->Set("last_time_critical", DbValue::FromTimestamp(attrs->Get("last_time_critical")));
fields->Set("last_time_unknown", DbValue::FromTimestamp(attrs->Get("last_time_unknown")));
fields->Set("state_type", attrs->Get("state_type"));
fields->Set("last_notification", DbValue::FromTimestamp(attrs->Get("last_notification")));
fields->Set("next_notification", DbValue::FromTimestamp(attrs->Get("next_notification")));
fields->Set("no_more_notifications", Empty);
fields->Set("notifications_enabled", attrs->Get("notifications_enabled"));
fields->Set("problem_has_been_acknowledged", attrs->Get("problem_has_been_acknowledged"));
fields->Set("acknowledgement_type", attrs->Get("acknowledgement_type"));
fields->Set("current_notification_number", attrs->Get("current_notification_number"));
fields->Set("passive_checks_enabled", attrs->Get("passive_checks_enabled"));
fields->Set("active_checks_enabled", attrs->Get("active_checks_enabled"));
fields->Set("event_handler_enabled", attrs->Get("event_handler_enabled"));
fields->Set("flap_detection_enabled", attrs->Get("flap_detection_enabled"));
fields->Set("is_flapping", attrs->Get("is_flapping"));
fields->Set("percent_state_change", attrs->Get("percent_state_change"));
fields->Set("latency", attrs->Get("check_latency"));
fields->Set("execution_time", attrs->Get("check_execution_time"));
fields->Set("scheduled_downtime_depth", attrs->Get("scheduled_downtime_depth"));
fields->Set("process_performance_data", attrs->Get("process_performance_data"));
fields->Set("event_handler", attrs->Get("event_handler"));
fields->Set("check_command", attrs->Get("check_command"));
fields->Set("normal_check_interval", attrs->Get("check_interval"));
fields->Set("retry_check_interval", attrs->Get("retry_interval"));
fields->Set("check_timeperiod_object_id", service->GetCheckPeriod());
return fields;
}
示例15: StalenessAccessor
Value ServicesTable::StalenessAccessor(const Value& row)
{
Service::Ptr service = static_cast<Service::Ptr>(row);
if (!service)
return Empty;
if (service->HasBeenChecked() && service->GetLastCheck() > 0)
return (Utility::GetTime() - service->GetLastCheck()) / (service->GetCheckInterval() * 3600);
return 0.0;
}