本文整理汇总了C++中host::Ptr::GetState方法的典型用法代码示例。如果您正苦于以下问题:C++ Ptr::GetState方法的具体用法?C++ Ptr::GetState怎么用?C++ Ptr::GetState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类host::Ptr
的用法示例。
在下文中一共展示了Ptr::GetState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetHostCurrentState
/* host */
int CompatUtility::GetHostCurrentState(const Host::Ptr& host)
{
if (host->GetState() != HostUp && !host->IsReachable())
return 2; /* hardcoded compat state */
return host->GetState();
}
示例2: GetHostStateString
String CompatUtility::GetHostStateString(const Host::Ptr& host)
{
if (host->GetState() != HostUp && !host->IsReachable())
return "UNREACHABLE"; /* hardcoded compat state */
return Host::StateToString(host->GetState());
}
示例3: SendPerfdata
void InfluxdbWriter::SendPerfdata(const Dictionary::Ptr& tmpl, const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, double ts)
{
Array::Ptr perfdata = cr->GetPerformanceData();
if (!perfdata)
return;
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, "InfluxdbWriter")
<< "Ignoring invalid perfdata value: " << val;
continue;
}
}
Dictionary::Ptr fields = new Dictionary();
fields->Set(String("value"), pdv->GetValue());
if (GetEnableSendThresholds()) {
if (pdv->GetCrit())
fields->Set(String("crit"), pdv->GetCrit());
if (pdv->GetWarn())
fields->Set(String("warn"), pdv->GetWarn());
if (pdv->GetMin())
fields->Set(String("min"), pdv->GetMin());
if (pdv->GetMax())
fields->Set(String("max"), pdv->GetMax());
}
if (GetEnableSendMetadata()) {
Host::Ptr host;
Service::Ptr service;
boost::tie(host, service) = GetHostService(checkable);
if (service)
fields->Set(String("state"), FormatInteger(service->GetState()));
else
fields->Set(String("state"), FormatInteger(host->GetState()));
fields->Set(String("current_attempt"), FormatInteger(checkable->GetCheckAttempt()));
fields->Set(String("max_check_attempts"), FormatInteger(checkable->GetMaxCheckAttempts()));
fields->Set(String("state_type"), FormatInteger(checkable->GetStateType()));
fields->Set(String("reachable"), FormatBoolean(checkable->IsReachable()));
fields->Set(String("downtime_depth"), FormatInteger(checkable->GetDowntimeDepth()));
fields->Set(String("acknowledgement"), FormatInteger(checkable->GetAcknowledgement()));
fields->Set(String("latency"), cr->CalculateLatency());
fields->Set(String("execution_time"), cr->CalculateExecutionTime());
}
SendMetric(tmpl, pdv->GetLabel(), fields, ts);
}
}
示例4: 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);
}
示例5: 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);
}
}
}
示例6: 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);
}
示例7: InternalCheckResultHandler
void ElasticsearchWriter::InternalCheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
{
AssertOnWorkQueue();
CONTEXT("Elasticwriter processing check result for '" + checkable->GetName() + "'");
if (!IcingaApplication::GetInstance()->GetEnablePerfdata() || !checkable->GetEnablePerfdata())
return;
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
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());
fields->Set("state_type", checkable->GetStateType());
fields->Set("current_check_attempt", checkable->GetCheckAttempt());
fields->Set("max_check_attempts", checkable->GetMaxCheckAttempts());
fields->Set("reachable", checkable->IsReachable());
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, "checkresult", fields, ts);
}
示例8: AcknowledgeProblem
Dictionary::Ptr ApiActions::AcknowledgeProblem(const ConfigObject::Ptr& object,
const Dictionary::Ptr& params)
{
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
if (!checkable)
return ApiActions::CreateResult(404, "Cannot acknowledge problem for non-existent object.");
if (!params->Contains("author") || !params->Contains("comment"))
return ApiActions::CreateResult(403, "Acknowledgements require author and comment.");
AcknowledgementType sticky = AcknowledgementNormal;
bool notify = false;
double timestamp = 0.0;
if (params->Contains("sticky"))
sticky = AcknowledgementSticky;
if (params->Contains("notify"))
notify = true;
if (params->Contains("expiry"))
timestamp = HttpUtility::GetLastParameter(params, "expiry");
else
timestamp = 0;
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
if (!service) {
if (host->GetState() == HostUp)
return ApiActions::CreateResult(409, "Host " + checkable->GetName() + " is UP.");
} else {
if (service->GetState() == ServiceOK)
return ApiActions::CreateResult(409, "Service " + checkable->GetName() + " is OK.");
}
Comment::AddComment(checkable, CommentAcknowledgement, HttpUtility::GetLastParameter(params, "author"),
HttpUtility::GetLastParameter(params, "comment"), timestamp);
checkable->AcknowledgeProblem(HttpUtility::GetLastParameter(params, "author"),
HttpUtility::GetLastParameter(params, "comment"), sticky, notify, timestamp);
return ApiActions::CreateResult(200, "Successfully acknowledged problem for object '" + checkable->GetName() + "'.");
}
示例9: StateChangeHandlerInternal
void ElasticsearchWriter::StateChangeHandlerInternal(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type)
{
AssertOnWorkQueue();
CONTEXT("Elasticwriter processing state change '" + checkable->GetName() + "'");
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
Dictionary::Ptr fields = new Dictionary();
fields->Set("current_check_attempt", checkable->GetCheckAttempt());
fields->Set("max_check_attempts", checkable->GetMaxCheckAttempts());
fields->Set("host", host->GetName());
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());
}
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, "statechange", fields, ts);
}
示例10: IsAvailable
bool Dependency::IsAvailable(DependencyType dt) const
{
Checkable::Ptr parent = GetParent();
Host::Ptr parentHost;
Service::Ptr parentService;
tie(parentHost, parentService) = GetHostService(parent);
/* ignore if it's the same checkable object */
if (parent == GetChild()) {
Log(LogNotice, "Dependency")
<< "Dependency '" << GetName() << "' passed: Parent and child " << (parentService ? "service" : "host") << " are identical.";
return true;
}
/* ignore pending */
if (!parent->GetLastCheckResult()) {
Log(LogNotice, "Dependency")
<< "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' hasn't been checked yet.";
return true;
}
if (GetIgnoreSoftStates()) {
/* ignore soft states */
if (parent->GetStateType() == StateTypeSoft) {
Log(LogNotice, "Dependency")
<< "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' is in a soft state.";
return true;
}
} else {
Log(LogNotice, "Dependency")
<< "Dependency '" << GetName() << "' failed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' is in a soft state.";
}
int state;
if (parentService)
state = ServiceStateToFilter(parentService->GetState());
else
state = HostStateToFilter(parentHost->GetState());
/* check state */
if (state & GetStateFilter()) {
Log(LogNotice, "Dependency")
<< "Dependency '" << GetName() << "' passed: Parent " << (parentService ? "service" : "host") << " '" << parent->GetName() << "' matches state filter.";
return true;
}
/* ignore if not in time period */
TimePeriod::Ptr tp = GetPeriod();
if (tp && !tp->IsInside(Utility::GetTime())) {
Log(LogNotice, "Dependency")
<< "Dependency '" << GetName() << "' passed: Outside time period.";
return true;
}
if (dt == DependencyCheckExecution && !GetDisableChecks()) {
Log(LogNotice, "Dependency")
<< "Dependency '" << GetName() << "' passed: Checks are not disabled.";
return true;
} else if (dt == DependencyNotification && !GetDisableNotifications()) {
Log(LogNotice, "Dependency")
<< "Dependency '" << GetName() << "' passed: Notifications are not disabled";
return true;
}
Log(LogNotice, "Dependency")
<< "Dependency '" << GetName() << "' failed. Parent "
<< (parentService ? "service" : "host") << " '" << parent->GetName() << "' is "
<< (parentService ? Service::StateToString(parentService->GetState()) : Host::StateToString(parentHost->GetState()));
return false;
}
示例11: BeginExecuteNotification
void Notification::BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, bool reminder, const String& author, const String& text)
{
Log(LogNotice, "Notification")
<< "Attempting to send " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "'.";
Checkable::Ptr checkable = GetCheckable();
if (!force) {
TimePeriod::Ptr tp = GetPeriod();
if (tp && !tp->IsInside(Utility::GetTime())) {
Log(LogNotice, "Notification")
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName()
<< "': not in timeperiod '" << tp->GetName() << "'";
return;
}
double now = Utility::GetTime();
Dictionary::Ptr times = GetTimes();
if (times && type == NotificationProblem) {
Value timesBegin = times->Get("begin");
Value timesEnd = times->Get("end");
if (timesBegin != Empty && timesBegin >= 0 && now < checkable->GetLastHardStateChange() + timesBegin) {
Log(LogNotice, "Notification")
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName()
<< "': before specified begin time (" << Utility::FormatDuration(timesBegin) << ")";
/* we need to adjust the next notification time
* to now + begin delaying the first notification
*/
double nextProposedNotification = now + timesBegin + 1.0;
if (GetNextNotification() > nextProposedNotification)
SetNextNotification(nextProposedNotification);
return;
}
if (timesEnd != Empty && timesEnd >= 0 && now > checkable->GetLastHardStateChange() + timesEnd) {
Log(LogNotice, "Notification")
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName()
<< "': after specified end time (" << Utility::FormatDuration(timesEnd) << ")";
return;
}
}
unsigned long ftype = type;
Log(LogDebug, "Notification")
<< "Type '" << NotificationTypeToStringInternal(type)
<< "', TypeFilter: " << NotificationFilterToString(GetTypeFilter(), GetTypeFilterMap())
<< " (FType=" << ftype << ", TypeFilter=" << GetTypeFilter() << ")";
if (!(ftype & GetTypeFilter())) {
Log(LogNotice, "Notification")
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "': type '"
<< NotificationTypeToStringInternal(type) << "' does not match type filter: "
<< NotificationFilterToString(GetTypeFilter(), GetTypeFilterMap()) << ".";
return;
}
/* ensure that recovery notifications are always sent, no state filter checks necessary */
if (type != NotificationRecovery) {
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
unsigned long fstate;
String stateStr;
if (service) {
fstate = ServiceStateToFilter(service->GetState());
stateStr = NotificationServiceStateToString(service->GetState());
} else {
fstate = HostStateToFilter(host->GetState());
stateStr = NotificationHostStateToString(host->GetState());
}
Log(LogDebug, "Notification")
<< "State '" << stateStr << "', StateFilter: " << NotificationFilterToString(GetStateFilter(), GetStateFilterMap())
<< " (FState=" << fstate << ", StateFilter=" << GetStateFilter() << ")";
if (!(fstate & GetStateFilter())) {
Log(LogNotice, "Notification")
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '" << GetName() << "': state '" << stateStr
<< "' does not match state filter: " << NotificationFilterToString(GetStateFilter(), GetStateFilterMap()) << ".";
return;
}
}
} else {
Log(LogNotice, "Notification")
<< "Not checking " << (reminder ? "reminder " : " ") << "notification filters for notification object '" << GetName() << "': Notification was forced.";
}
{
ObjectLock olock(this);
UpdateNotificationNumber();
double now = Utility::GetTime();
//.........这里部分代码省略.........
示例12: CheckNotificationUserFilters
bool Notification::CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force, bool reminder)
{
if (!force) {
TimePeriod::Ptr tp = user->GetPeriod();
if (tp && !tp->IsInside(Utility::GetTime())) {
Log(LogNotice, "Notification")
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '"
<< GetName() << " and user '" << user->GetName()
<< "': user period not in timeperiod '" << tp->GetName() << "'";
return false;
}
unsigned long ftype = type;
Log(LogDebug, "Notification")
<< "User notification, Type '" << NotificationTypeToStringInternal(type)
<< "', TypeFilter: " << NotificationFilterToString(user->GetTypeFilter(), GetTypeFilterMap())
<< " (FType=" << ftype << ", TypeFilter=" << GetTypeFilter() << ")";
if (!(ftype & user->GetTypeFilter())) {
Log(LogNotice, "Notification")
<< "Not sending " << (reminder ? "reminder " : " ") << "notifications for notification object '"
<< GetName() << " and user '" << user->GetName() << "': type '"
<< NotificationTypeToStringInternal(type) << "' does not match type filter: "
<< NotificationFilterToString(user->GetTypeFilter(), GetTypeFilterMap()) << ".";
return false;
}
/* check state filters it this is not a recovery notification */
if (type != NotificationRecovery) {
Checkable::Ptr checkable = GetCheckable();
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
unsigned long fstate;
String stateStr;
if (service) {
fstate = ServiceStateToFilter(service->GetState());
stateStr = NotificationServiceStateToString(service->GetState());
} else {
fstate = HostStateToFilter(host->GetState());
stateStr = NotificationHostStateToString(host->GetState());
}
Log(LogDebug, "Notification")
<< "User notification, State '" << stateStr << "', StateFilter: "
<< NotificationFilterToString(user->GetStateFilter(), GetStateFilterMap())
<< " (FState=" << fstate << ", StateFilter=" << user->GetStateFilter() << ")";
if (!(fstate & user->GetStateFilter())) {
Log(LogNotice, "Notification")
<< "Not " << (reminder ? "reminder " : " ") << "sending notifications for notification object '"
<< GetName() << " and user '" << user->GetName() << "': state '" << stateStr
<< "' does not match state filter: " << NotificationFilterToString(user->GetStateFilter(), GetStateFilterMap()) << ".";
return false;
}
}
} else {
Log(LogNotice, "Notification")
<< "Not checking " << (reminder ? "reminder " : " ") << "notification filters for notification object '"
<< GetName() << "' and user '" << user->GetName() << "': Notification was forced.";
}
return true;
}
示例13: CheckResultHandler
void LogstashWriter::CheckResultHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr)
{
CONTEXT("LOGSTASH Processing check result for '" + checkable->GetName() + "'");
Log(LogDebug, "LogstashWriter")
<< "Processing check result for '" << checkable->GetName() << "'";
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
Dictionary::Ptr fields = new Dictionary();
if (service) {
fields->Set("service_name", service->GetShortName());
fields->Set("service_state", Service::StateToString(service->GetState()));
fields->Set("last_state", service->GetLastState());
fields->Set("last_hard_state", service->GetLastHardState());
} else {
fields->Set("last_state", host->GetLastState());
fields->Set("last_hard_state", host->GetLastHardState());
}
fields->Set("host_name", host->GetName());
fields->Set("type", "CheckResult");
fields->Set("state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState()));
fields->Set("current_check_attempt", checkable->GetCheckAttempt());
fields->Set("max_check_attempts", checkable->GetMaxCheckAttempts());
fields->Set("latency", cr->CalculateLatency());
fields->Set("execution_time", cr->CalculateExecutionTime());
fields->Set("reachable", checkable->IsReachable());
double ts = Utility::GetTime();
if (cr) {
fields->Set("plugin_output", cr->GetOutput());
fields->Set("check_source", cr->GetCheckSource());
ts = cr->GetExecutionEnd();
}
Array::Ptr perfdata = cr->GetPerformanceData();
if (perfdata) {
Dictionary::Ptr perfdataItems = new Dictionary();
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, "LogstashWriter")
<< "Ignoring invalid perfdata value: '" << val << "' for object '"
<< checkable->GetName() << "'.";
continue;
}
}
Dictionary::Ptr perfdataItem = new Dictionary();
perfdataItem->Set("value", pdv->GetValue());
if (pdv->GetMin())
perfdataItem->Set("min", pdv->GetMin());
if (pdv->GetMax())
perfdataItem->Set("max", pdv->GetMax());
if (pdv->GetWarn())
perfdataItem->Set("warn", pdv->GetWarn());
if (pdv->GetCrit())
perfdataItem->Set("crit", pdv->GetCrit());
String escaped_key = EscapeMetricLabel(pdv->GetLabel());
perfdataItems->Set(escaped_key, perfdataItem);
}
fields->Set("performance_data", perfdataItems);
}
SendLogMessage(ComposeLogstashMessage(fields, GetSource(), ts));
}
示例14: StateChangeHandler
void LogstashWriter::StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type)
{
CONTEXT("Logstash Processing state change '" + checkable->GetName() + "'");
Log(LogDebug, "LogstashWriter")
<< "Processing state change for '" << checkable->GetName() << "'";
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
Dictionary::Ptr fields = new Dictionary();
fields->Set("state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState()));
fields->Set("type", "StateChange");
fields->Set("current_check_attempt", checkable->GetCheckAttempt());
fields->Set("max_check_attempts", checkable->GetMaxCheckAttempts());
fields->Set("hostname", host->GetName());
if (service) {
fields->Set("service_name", service->GetShortName());
fields->Set("service_state", Service::StateToString(service->GetState()));
fields->Set("last_state", service->GetLastState());
fields->Set("last_hard_state", service->GetLastHardState());
} else {
fields->Set("last_state", host->GetLastState());
fields->Set("last_hard_state", host->GetLastHardState());
}
double ts = Utility::GetTime();
if (cr) {
fields->Set("plugin_output", cr->GetOutput());
fields->Set("check_source", cr->GetCheckSource());
ts = cr->GetExecutionEnd();
}
SendLogMessage(ComposeLogstashMessage(fields, GetSource(), ts));
}
示例15: NotificationToUserHandler
void LogstashWriter::NotificationToUserHandler(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)
{
CONTEXT("Logstash Processing notification to all users '" + checkable->GetName() + "'");
Log(LogDebug, "LogstashWriter")
<< "Processing notification for '" << checkable->GetName() << "'";
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
String notification_type_str = Notification::NotificationTypeToString(notification_type);
String author_comment = "";
if (notification_type == NotificationCustom || notification_type == NotificationAcknowledgement) {
author_comment = author + ";" + comment_text;
}
double ts = Utility::GetTime();
Dictionary::Ptr fields = new Dictionary();
if (service) {
fields->Set("type", "SERVICE NOTIFICATION");
fields->Set("service_name", service->GetShortName());
} else {
fields->Set("type", "HOST NOTIFICATION");
}
if (cr) {
fields->Set("plugin_output", cr->GetOutput());
ts = cr->GetExecutionEnd();
}
fields->Set("state", service ? Service::StateToString(service->GetState()) : Host::StateToString(host->GetState()));
fields->Set("host_name", host->GetName());
fields->Set("command", command_name);
fields->Set("notification_type", notification_type_str);
fields->Set("comment", author_comment);
SendLogMessage(ComposeLogstashMessage(fields, GetSource(), ts));
}