本文整理汇总了C++中host::Ptr::GetName方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::GetName方法的具体用法?C++ Ptr::GetName怎么用?C++ Ptr::GetName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类host::Ptr
的用法示例。
在下文中一共展示了Ptr::GetName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CheckResultHandler
/**
* @threadsafety Always.
*/
void CompatLogger::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr &cr)
{
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
Dictionary::Ptr vars_after = cr->GetVarsAfter();
long state_after = vars_after->Get("state");
long stateType_after = vars_after->Get("state_type");
long attempt_after = vars_after->Get("attempt");
bool reachable_after = vars_after->Get("reachable");
Dictionary::Ptr vars_before = cr->GetVarsBefore();
if (vars_before) {
long state_before = vars_before->Get("state");
long stateType_before = vars_before->Get("state_type");
long attempt_before = vars_before->Get("attempt");
bool reachable_before = vars_before->Get("reachable");
if (state_before == state_after && stateType_before == stateType_after &&
attempt_before == attempt_after && reachable_before == reachable_after)
return; /* Nothing changed, ignore this checkresult. */
}
String output;
if (cr)
output = CompatUtility::GetCheckResultOutput(cr);
std::ostringstream msgbuf;
if (service) {
msgbuf << "SERVICE ALERT: "
<< host->GetName() << ";"
<< service->GetShortName() << ";"
<< Service::StateToString(service->GetState()) << ";"
<< Service::StateTypeToString(service->GetStateType()) << ";"
<< attempt_after << ";"
<< output << ""
<< "";
} else {
String state = Host::StateToString(Host::CalculateState(static_cast<ServiceState>(state_after)));
msgbuf << "HOST ALERT: "
<< host->GetName() << ";"
<< GetHostStateString(host) << ";"
<< Host::StateTypeToString(host->GetStateType()) << ";"
<< attempt_after << ";"
<< output << ""
<< "";
}
{
ObjectLock olock(this);
WriteLine(msgbuf.str());
Flush();
}
}
示例2: NotificationSentHandler
/**
* @threadsafety Always.
*/
void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
const User::Ptr& user, NotificationType notification_type, CheckResult::Ptr const& cr,
const String& author, const String& comment_text, const String& command_name)
{
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
String notification_type_str = Notification::NotificationTypeToString(notification_type);
/* override problem notifications with their current state string */
if (notification_type == NotificationProblem) {
if (service)
notification_type_str = Service::StateToString(service->GetState());
else
notification_type_str = GetHostStateString(host);
}
String author_comment = "";
if (notification_type == NotificationCustom || notification_type == NotificationAcknowledgement) {
author_comment = author + ";" + comment_text;
}
if (!cr)
return;
String output;
if (cr)
output = CompatUtility::GetCheckResultOutput(cr);
std::ostringstream msgbuf;
if (service) {
msgbuf << "SERVICE NOTIFICATION: "
<< user->GetName() << ";"
<< host->GetName() << ";"
<< service->GetShortName() << ";"
<< notification_type_str << ";"
<< command_name << ";"
<< output << ";"
<< author_comment
<< "";
} else {
msgbuf << "HOST NOTIFICATION: "
<< user->GetName() << ";"
<< host->GetName() << ";"
<< notification_type_str << " "
<< "(" << GetHostStateString(host) << ");"
<< command_name << ";"
<< output << ";"
<< author_comment
<< "";
}
{
ObjectLock oLock(this);
WriteLine(msgbuf.str());
Flush();
}
}
示例3: TriggerDowntimeHandler
/**
* @threadsafety Always.
*/
void CompatLogger::TriggerDowntimeHandler(const Downtime::Ptr& downtime)
{
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(downtime->GetCheckable());
if (!downtime)
return;
std::ostringstream msgbuf;
if (service) {
msgbuf << "SERVICE DOWNTIME ALERT: "
<< host->GetName() << ";"
<< service->GetShortName() << ";"
<< "STARTED" << "; "
<< "Checkable has entered a period of scheduled downtime."
<< "";
} else {
msgbuf << "HOST DOWNTIME ALERT: "
<< host->GetName() << ";"
<< "STARTED" << "; "
<< "Checkable has entered a period of scheduled downtime."
<< "";
}
{
ObjectLock oLock(this);
WriteLine(msgbuf.str());
Flush();
}
}
示例4: EnableFlappingChangedHandler
void CompatLogger::EnableFlappingChangedHandler(const Checkable::Ptr& checkable)
{
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
if (checkable->GetEnableFlapping())
return;
String flapping_output = "Flap detection has been disabled";
String flapping_state_str = "DISABLED";
std::ostringstream msgbuf;
if (service) {
msgbuf << "SERVICE FLAPPING ALERT: "
<< host->GetName() << ";"
<< service->GetShortName() << ";"
<< flapping_state_str << "; "
<< flapping_output
<< "";
} else {
msgbuf << "HOST FLAPPING ALERT: "
<< host->GetName() << ";"
<< flapping_state_str << "; "
<< flapping_output
<< "";
}
{
ObjectLock oLock(this);
WriteLine(msgbuf.str());
Flush();
}
}
示例5: EventCommandHandler
void CompatLogger::EventCommandHandler(const Checkable::Ptr& checkable)
{
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
EventCommand::Ptr event_command = checkable->GetEventCommand();
String event_command_name = event_command->GetName();
long current_attempt = checkable->GetCheckAttempt();
std::ostringstream msgbuf;
if (service) {
msgbuf << "SERVICE EVENT HANDLER: "
<< host->GetName() << ";"
<< service->GetShortName() << ";"
<< Service::StateToString(service->GetState()) << ";"
<< Service::StateTypeToString(service->GetStateType()) << ";"
<< current_attempt << ";"
<< event_command_name;
} else {
msgbuf << "HOST EVENT HANDLER: "
<< host->GetName() << ";"
<< GetHostStateString(host) << ";"
<< Host::StateTypeToString(host->GetStateType()) << ";"
<< current_attempt << ";"
<< event_command_name;
}
{
ObjectLock oLock(this);
WriteLine(msgbuf.str());
Flush();
}
}
示例6: DumpComments
void StatusDataWriter::DumpComments(std::ostream& fp, const Checkable::Ptr& checkable)
{
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
for (const Comment::Ptr& comment : checkable->GetComments()) {
if (comment->IsExpired())
continue;
if (service)
fp << "servicecomment {" << "\n"
<< "\t" << "service_description=" << service->GetShortName() << "\n";
else
fp << "hostcomment {" << "\n";
fp << "\t" "host_name=" << host->GetName() << "\n"
"\t" "comment_id=" << comment->GetLegacyId() << "\n"
"\t" "entry_time=" << comment->GetEntryTime() << "\n"
"\t" "entry_type=" << comment->GetEntryType() << "\n"
"\t" "persistent=" "1" "\n"
"\t" "author=" << comment->GetAuthor() << "\n"
"\t" "comment_data=" << comment->GetText() << "\n"
"\t" "expires=" << (comment->GetExpireTime() != 0 ? 1 : 0) << "\n"
"\t" "expire_time=" << comment->GetExpireTime() << "\n"
"\t" "}" "\n"
"\n";
}
}
示例7: EvaluateApplyRuleInstance
bool Service::EvaluateApplyRuleInstance(const Host::Ptr& host, const String& name, ScriptFrame& frame, const ApplyRule& rule)
{
if (!rule.EvaluateFilter(frame))
return false;
DebugInfo di = rule.GetDebugInfo();
Log(LogDebug, "Service")
<< "Applying service '" << name << "' to host '" << host->GetName() << "' for rule " << di;
ConfigItemBuilder::Ptr builder = new ConfigItemBuilder(di);
builder->SetType("Service");
builder->SetName(name);
builder->SetScope(frame.Locals->ShallowClone());
builder->SetIgnoreOnError(rule.GetIgnoreOnError());
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "host_name"), OpSetLiteral, MakeLiteral(host->GetName()), di));
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "name"), OpSetLiteral, MakeLiteral(name), di));
String zone = host->GetZoneName();
if (!zone.IsEmpty())
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "zone"), OpSetLiteral, MakeLiteral(zone), di));
builder->AddExpression(new SetExpression(MakeIndexer(ScopeThis, "package"), OpSetLiteral, MakeLiteral(rule.GetPackage()), di));
builder->AddExpression(new OwnedExpression(rule.GetExpression()));
ConfigItem::Ptr serviceItem = builder->Compile();
serviceItem->Register();
return true;
}
示例8: NotificationSentUserHandler
void ClusterEvents::NotificationSentUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable, const User::Ptr& user,
NotificationType notificationType, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr, const String& author, const String& commentText, const String& command,
const MessageOrigin::Ptr& origin)
{
ApiListener::Ptr listener = ApiListener::GetInstance();
if (!listener)
return;
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
Dictionary::Ptr params = new Dictionary();
params->Set("host", host->GetName());
if (service)
params->Set("service", service->GetShortName());
params->Set("notification", notification->GetName());
params->Set("user", user->GetName());
params->Set("type", notificationType);
params->Set("cr", Serialize(cr));
params->Set("nr", Serialize(nr));
params->Set("author", author);
params->Set("text", commentText);
params->Set("command", command);
Dictionary::Ptr message = new Dictionary();
message->Set("jsonrpc", "2.0");
message->Set("method", "event::NotificationSentUser");
message->Set("params", params);
listener->RelayMessage(origin, nullptr, message, true);
}
示例9: AcknowledgementSetHandler
void ClusterEvents::AcknowledgementSetHandler(const Checkable::Ptr& checkable,
const String& author, const String& comment, AcknowledgementType type,
bool notify, bool persistent, double expiry, const MessageOrigin::Ptr& origin)
{
ApiListener::Ptr listener = ApiListener::GetInstance();
if (!listener)
return;
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
Dictionary::Ptr params = new Dictionary();
params->Set("host", host->GetName());
if (service)
params->Set("service", service->GetShortName());
params->Set("author", author);
params->Set("comment", comment);
params->Set("acktype", type);
params->Set("notify", notify);
params->Set("persistent", persistent);
params->Set("expiry", expiry);
Dictionary::Ptr message = new Dictionary();
message->Set("jsonrpc", "2.0");
message->Set("method", "event::SetAcknowledgement");
message->Set("params", params);
listener->RelayMessage(origin, checkable, message, true);
}
示例10: CheckResultHandler
void ApiEvents::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin::Ptr& origin)
{
std::vector<EventQueue::Ptr> queues = EventQueue::GetQueuesForType("CheckResult");
if (queues.empty())
return;
Log(LogDebug, "ApiEvents", "Processing event type 'CheckResult'.");
Dictionary::Ptr result = new Dictionary();
result->Set("type", "CheckResult");
result->Set("timestamp", Utility::GetTime());
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
result->Set("host", host->GetName());
if (service)
result->Set("service", service->GetShortName());
result->Set("check_result", Serialize(cr));
BOOST_FOREACH(const EventQueue::Ptr& queue, queues) {
queue->ProcessEvent(result);
}
示例11: MakeCheckResultMessage
Dictionary::Ptr ClusterEvents::MakeCheckResultMessage(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
{
Dictionary::Ptr message = new Dictionary();
message->Set("jsonrpc", "2.0");
message->Set("method", "event::CheckResult");
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
Dictionary::Ptr params = new Dictionary();
params->Set("host", host->GetName());
if (service)
params->Set("service", service->GetShortName());
else {
Value agent_service_name = checkable->GetExtension("agent_service_name");
if (!agent_service_name.IsEmpty())
params->Set("service", agent_service_name);
}
params->Set("cr", Serialize(cr));
message->Set("params", params);
return message;
}
示例12: EvaluateObjectRuleOne
bool HostGroup::EvaluateObjectRuleOne(const Host::Ptr& host, const ObjectRule& rule)
{
DebugInfo di = rule.GetDebugInfo();
std::ostringstream msgbuf;
msgbuf << "Evaluating 'object' rule (" << di << ")";
CONTEXT(msgbuf.str());
Dictionary::Ptr locals = make_shared<Dictionary>();
locals->Set("host", host);
if (!rule.EvaluateFilter(locals))
return false;
std::ostringstream msgbuf2;
msgbuf2 << "Assigning membership for group '" << rule.GetName() << "' to host '" << host->GetName() << "' for rule " << di;
Log(LogDebug, "HostGroup", msgbuf2.str());
String group_name = rule.GetName();
HostGroup::Ptr group = HostGroup::GetByName(group_name);
if (!group) {
Log(LogCritical, "HostGroup", "Invalid membership assignment. Group '" + group_name + "' does not exist.");
return false;
}
/* assign host group membership */
group->ResolveGroupMembership(host, true);
/* update groups attribute for apply */
host->AddGroup(group_name);
return true;
}
示例13: CheckResultHandler
void ApiEvents::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, const MessageOrigin& origin)
{
ApiListener::Ptr listener = ApiListener::GetInstance();
if (!listener)
return;
Dictionary::Ptr message = make_shared<Dictionary>();
message->Set("jsonrpc", "2.0");
message->Set("method", "event::CheckResult");
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
Dictionary::Ptr params = make_shared<Dictionary>();
params->Set("host", host->GetName());
if (service)
params->Set("service", service->GetShortName());
params->Set("cr", Serialize(cr));
message->Set("params", params);
listener->RelayMessage(origin, checkable, message, true);
}
示例14: ResolveGroupMembership
bool HostGroup::ResolveGroupMembership(const Host::Ptr& host, bool add, int rstack) {
if (add && rstack > 20) {
Log(LogWarning, "HostGroup")
<< "Too many nested groups for group '" << GetName() << "': Host '"
<< host->GetName() << "' membership assignment failed.";
return false;
}
Array::Ptr groups = GetGroups();
if (groups && groups->GetLength() > 0) {
ObjectLock olock(groups);
for (const String& name : groups) {
HostGroup::Ptr group = HostGroup::GetByName(name);
if (group && !group->ResolveGroupMembership(host, add, rstack + 1))
return false;
}
}
if (add)
AddMember(host);
else
RemoveMember(host);
return true;
}
示例15: GetHostAlias
String CompatUtility::GetHostAlias(const Host::Ptr& host)
{
if (!host->GetDisplayName().IsEmpty())
return host->GetName();
else
return host->GetDisplayName();
}