本文整理汇总了C++中checkresult::Ptr::GetVarsBefore方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::GetVarsBefore方法的具体用法?C++ Ptr::GetVarsBefore怎么用?C++ Ptr::GetVarsBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类checkresult::Ptr
的用法示例。
在下文中一共展示了Ptr::GetVarsBefore方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: AddCheckResult
void ElasticsearchWriter::AddCheckResult(const Dictionary::Ptr& fields, const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
{
String prefix = "check_result.";
fields->Set(prefix + "output", cr->GetOutput());
fields->Set(prefix + "check_source", cr->GetCheckSource());
fields->Set(prefix + "exit_status", cr->GetExitStatus());
fields->Set(prefix + "command", cr->GetCommand());
fields->Set(prefix + "state", cr->GetState());
fields->Set(prefix + "vars_before", cr->GetVarsBefore());
fields->Set(prefix + "vars_after", cr->GetVarsAfter());
fields->Set(prefix + "execution_start", FormatTimestamp(cr->GetExecutionStart()));
fields->Set(prefix + "execution_end", FormatTimestamp(cr->GetExecutionEnd()));
fields->Set(prefix + "schedule_start", FormatTimestamp(cr->GetScheduleStart()));
fields->Set(prefix + "schedule_end", FormatTimestamp(cr->GetScheduleEnd()));
/* Add extra calculated field. */
fields->Set(prefix + "latency", cr->CalculateLatency());
fields->Set(prefix + "execution_time", cr->CalculateExecutionTime());
if (!GetEnableSendPerfdata())
return;
Array::Ptr perfdata = cr->GetPerformanceData();
CheckCommand::Ptr checkCommand = checkable->GetCheckCommand();
if (perfdata) {
ObjectLock olock(perfdata);
for (const Value& val : perfdata) {
PerfdataValue::Ptr pdv;
if (val.IsObjectType<PerfdataValue>())
pdv = val;
else {
try {
pdv = PerfdataValue::Parse(val);
} catch (const std::exception&) {
Log(LogWarning, "ElasticsearchWriter")
<< "Ignoring invalid perfdata for checkable '"
<< checkable->GetName() << "' and command '"
<< checkCommand->GetName() << "' with value: " << val;
continue;
}
}
String escapedKey = pdv->GetLabel();
boost::replace_all(escapedKey, " ", "_");
boost::replace_all(escapedKey, ".", "_");
boost::replace_all(escapedKey, "\\", "_");
boost::algorithm::replace_all(escapedKey, "::", ".");
String perfdataPrefix = prefix + "perfdata." + escapedKey;
fields->Set(perfdataPrefix + ".value", pdv->GetValue());
if (pdv->GetMin())
fields->Set(perfdataPrefix + ".min", pdv->GetMin());
if (pdv->GetMax())
fields->Set(perfdataPrefix + ".max", pdv->GetMax());
if (pdv->GetWarn())
fields->Set(perfdataPrefix + ".warn", pdv->GetWarn());
if (pdv->GetCrit())
fields->Set(perfdataPrefix + ".crit", pdv->GetCrit());
if (!pdv->GetUnit().IsEmpty())
fields->Set(perfdataPrefix + ".unit", pdv->GetUnit());
}
}
}