mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-25 22:54:57 +02:00
Remove some superfluous if statements
They're just useless, since a `CheckResult` handler is never going to be called without a check result and a checkable can't exist without a checkcommand.
This commit is contained in:
parent
79e5462072
commit
2e19fce31d
@ -272,22 +272,12 @@ void ElasticsearchWriter::InternalCheckResultHandler(const Checkable::Ptr& check
|
||||
fields->Set("max_check_attempts", checkable->GetMaxCheckAttempts());
|
||||
|
||||
fields->Set("reachable", checkable->IsReachable());
|
||||
fields->Set("check_command", checkable->GetCheckCommand()->GetName());
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
AddCheckResult(fields, checkable, cr);
|
||||
AddTemplateTags(fields, checkable, cr);
|
||||
|
||||
Enqueue(checkable, "checkresult", fields, ts);
|
||||
Enqueue(checkable, "checkresult", fields, cr->GetExecutionEnd());
|
||||
}
|
||||
|
||||
void ElasticsearchWriter::StateChangeHandler(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type)
|
||||
@ -325,21 +315,12 @@ void ElasticsearchWriter::StateChangeHandlerInternal(const Checkable::Ptr& check
|
||||
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();
|
||||
}
|
||||
fields->Set("check_command", checkable->GetCheckCommand()->GetName());
|
||||
|
||||
AddCheckResult(fields, checkable, cr);
|
||||
AddTemplateTags(fields, checkable, cr);
|
||||
|
||||
Enqueue(checkable, "statechange", fields, ts);
|
||||
Enqueue(checkable, "statechange", fields, cr->GetExecutionEnd());
|
||||
}
|
||||
|
||||
void ElasticsearchWriter::NotificationSentToAllUsersHandler(const Notification::Ptr& notification,
|
||||
@ -396,11 +377,7 @@ void ElasticsearchWriter::NotificationSentToAllUsersHandlerInternal(const Notifi
|
||||
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());
|
||||
fields->Set("check_command", checkable->GetCheckCommand()->GetName());
|
||||
|
||||
double ts = Utility::GetTime();
|
||||
|
||||
|
@ -306,22 +306,15 @@ void GelfWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, con
|
||||
fields->Set("_reachable", checkable->IsReachable());
|
||||
|
||||
CheckCommand::Ptr checkCommand = checkable->GetCheckCommand();
|
||||
fields->Set("_check_command", checkCommand->GetName());
|
||||
|
||||
if (checkCommand)
|
||||
fields->Set("_check_command", checkCommand->GetName());
|
||||
fields->Set("_latency", cr->CalculateLatency());
|
||||
fields->Set("_execution_time", cr->CalculateExecutionTime());
|
||||
fields->Set("short_message", CompatUtility::GetCheckResultOutput(cr));
|
||||
fields->Set("full_message", cr->GetOutput());
|
||||
fields->Set("_check_source", cr->GetCheckSource());
|
||||
|
||||
double ts = Utility::GetTime();
|
||||
|
||||
if (cr) {
|
||||
fields->Set("_latency", cr->CalculateLatency());
|
||||
fields->Set("_execution_time", cr->CalculateExecutionTime());
|
||||
fields->Set("short_message", CompatUtility::GetCheckResultOutput(cr));
|
||||
fields->Set("full_message", cr->GetOutput());
|
||||
fields->Set("_check_source", cr->GetCheckSource());
|
||||
ts = cr->GetExecutionEnd();
|
||||
}
|
||||
|
||||
if (cr && GetEnableSendPerfdata()) {
|
||||
if (GetEnableSendPerfdata()) {
|
||||
Array::Ptr perfdata = cr->GetPerformanceData();
|
||||
|
||||
if (perfdata) {
|
||||
@ -366,7 +359,7 @@ void GelfWriter::CheckResultHandlerInternal(const Checkable::Ptr& checkable, con
|
||||
}
|
||||
}
|
||||
|
||||
SendLogMessage(checkable, ComposeGelfMessage(fields, GetSource(), ts));
|
||||
SendLogMessage(checkable, ComposeGelfMessage(fields, GetSource(), cr->GetExecutionEnd()));
|
||||
}
|
||||
|
||||
void GelfWriter::NotificationToUserHandler(const Notification::Ptr& notification, const Checkable::Ptr& checkable,
|
||||
@ -430,11 +423,7 @@ void GelfWriter::NotificationToUserHandlerInternal(const Notification::Ptr& noti
|
||||
fields->Set("_command", commandName);
|
||||
fields->Set("_notification_type", notificationTypeString);
|
||||
fields->Set("_comment", authorComment);
|
||||
|
||||
CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
|
||||
|
||||
if (commandObj)
|
||||
fields->Set("_check_command", commandObj->GetName());
|
||||
fields->Set("_check_command", checkable->GetCheckCommand()->GetName());
|
||||
|
||||
SendLogMessage(checkable, ComposeGelfMessage(fields, GetSource(), ts));
|
||||
}
|
||||
@ -478,21 +467,12 @@ void GelfWriter::StateChangeHandlerInternal(const Checkable::Ptr& checkable, con
|
||||
fields->Set("_last_hard_state", host->GetLastHardState());
|
||||
}
|
||||
|
||||
CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
|
||||
fields->Set("_check_command", checkable->GetCheckCommand()->GetName());
|
||||
fields->Set("short_message", CompatUtility::GetCheckResultOutput(cr));
|
||||
fields->Set("full_message", cr->GetOutput());
|
||||
fields->Set("_check_source", cr->GetCheckSource());
|
||||
|
||||
if (commandObj)
|
||||
fields->Set("_check_command", commandObj->GetName());
|
||||
|
||||
double ts = Utility::GetTime();
|
||||
|
||||
if (cr) {
|
||||
fields->Set("short_message", CompatUtility::GetCheckResultOutput(cr));
|
||||
fields->Set("full_message", cr->GetOutput());
|
||||
fields->Set("_check_source", cr->GetCheckSource());
|
||||
ts = cr->GetExecutionEnd();
|
||||
}
|
||||
|
||||
SendLogMessage(checkable, ComposeGelfMessage(fields, GetSource(), ts));
|
||||
SendLogMessage(checkable, ComposeGelfMessage(fields, GetSource(), cr->GetExecutionEnd()));
|
||||
}
|
||||
|
||||
String GelfWriter::ComposeGelfMessage(const Dictionary::Ptr& fields, const String& source, double ts)
|
||||
|
Loading…
x
Reference in New Issue
Block a user