From c2f8d6df4486843c2c4b54b6e7125cb61c0842d5 Mon Sep 17 00:00:00 2001 From: Mattia Codato Date: Mon, 3 Aug 2020 08:07:32 +0200 Subject: [PATCH] Use ternary operator to get ExecuteOverride or checkable command --- lib/methods/clusterchecktask.cpp | 6 +----- lib/methods/clusterzonechecktask.cpp | 6 +----- lib/methods/dummychecktask.cpp | 6 +----- lib/methods/icingachecktask.cpp | 6 +----- lib/methods/pluginchecktask.cpp | 6 +----- lib/methods/plugineventtask.cpp | 6 +----- lib/methods/pluginnotificationtask.cpp | 6 +----- lib/methods/randomchecktask.cpp | 6 +----- lib/methods/sleepchecktask.cpp | 6 +----- 9 files changed, 9 insertions(+), 45 deletions(-) diff --git a/lib/methods/clusterchecktask.cpp b/lib/methods/clusterchecktask.cpp index 1fb02633d..eef3900ea 100644 --- a/lib/methods/clusterchecktask.cpp +++ b/lib/methods/clusterchecktask.cpp @@ -28,11 +28,7 @@ void ClusterCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRe if (resolvedMacros && !useResolvedMacros) return; - CheckCommand::Ptr command; - if (CheckCommand::ExecuteOverride) - command = CheckCommand::ExecuteOverride; - else - command = checkable->GetCheckCommand(); + CheckCommand::Ptr command = CheckCommand::ExecuteOverride ? CheckCommand::ExecuteOverride : checkable->GetCheckCommand(); String commandName = command->GetName(); ApiListener::Ptr listener = ApiListener::GetInstance(); diff --git a/lib/methods/clusterzonechecktask.cpp b/lib/methods/clusterzonechecktask.cpp index 024288ed7..0d5889a40 100644 --- a/lib/methods/clusterzonechecktask.cpp +++ b/lib/methods/clusterzonechecktask.cpp @@ -21,11 +21,7 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che REQUIRE_NOT_NULL(cr); ApiListener::Ptr listener = ApiListener::GetInstance(); - CheckCommand::Ptr command; - if (CheckCommand::ExecuteOverride) - command = CheckCommand::ExecuteOverride; - else - command = checkable->GetCheckCommand(); + CheckCommand::Ptr command = CheckCommand::ExecuteOverride ? CheckCommand::ExecuteOverride : checkable->GetCheckCommand(); String commandName = command->GetName(); if (!listener) { diff --git a/lib/methods/dummychecktask.cpp b/lib/methods/dummychecktask.cpp index ae44a1d63..45c773fcb 100644 --- a/lib/methods/dummychecktask.cpp +++ b/lib/methods/dummychecktask.cpp @@ -22,11 +22,7 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu REQUIRE_NOT_NULL(checkable); REQUIRE_NOT_NULL(cr); - CheckCommand::Ptr command; - if (CheckCommand::ExecuteOverride) - command = CheckCommand::ExecuteOverride; - else - command = checkable->GetCheckCommand(); + CheckCommand::Ptr command = CheckCommand::ExecuteOverride ? CheckCommand::ExecuteOverride : checkable->GetCheckCommand(); Host::Ptr host; Service::Ptr service; diff --git a/lib/methods/icingachecktask.cpp b/lib/methods/icingachecktask.cpp index efbdcc3c9..d697b6925 100644 --- a/lib/methods/icingachecktask.cpp +++ b/lib/methods/icingachecktask.cpp @@ -26,11 +26,7 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes REQUIRE_NOT_NULL(checkable); REQUIRE_NOT_NULL(cr); - CheckCommand::Ptr command; - if (CheckCommand::ExecuteOverride) - command = CheckCommand::ExecuteOverride; - else - command = checkable->GetCheckCommand(); + CheckCommand::Ptr command = CheckCommand::ExecuteOverride ? CheckCommand::ExecuteOverride : checkable->GetCheckCommand(); Host::Ptr host; Service::Ptr service; diff --git a/lib/methods/pluginchecktask.cpp b/lib/methods/pluginchecktask.cpp index 0825bf1b4..83d36c96d 100644 --- a/lib/methods/pluginchecktask.cpp +++ b/lib/methods/pluginchecktask.cpp @@ -22,11 +22,7 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes REQUIRE_NOT_NULL(checkable); REQUIRE_NOT_NULL(cr); - CheckCommand::Ptr commandObj; - if (CheckCommand::ExecuteOverride) - commandObj = CheckCommand::ExecuteOverride; - else - commandObj = checkable->GetCheckCommand(); + CheckCommand::Ptr commandObj = CheckCommand::ExecuteOverride ? CheckCommand::ExecuteOverride : checkable->GetCheckCommand(); Host::Ptr host; Service::Ptr service; diff --git a/lib/methods/plugineventtask.cpp b/lib/methods/plugineventtask.cpp index 7a7932a9d..9c4401303 100644 --- a/lib/methods/plugineventtask.cpp +++ b/lib/methods/plugineventtask.cpp @@ -21,11 +21,7 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable, { REQUIRE_NOT_NULL(checkable); - EventCommand::Ptr commandObj; - if (EventCommand::ExecuteOverride) - commandObj = EventCommand::ExecuteOverride; - else - commandObj = checkable->GetEventCommand(); + EventCommand::Ptr commandObj = EventCommand::ExecuteOverride ? EventCommand::ExecuteOverride : checkable->GetEventCommand(); Host::Ptr host; Service::Ptr service; diff --git a/lib/methods/pluginnotificationtask.cpp b/lib/methods/pluginnotificationtask.cpp index 79485bab2..ae89cc245 100644 --- a/lib/methods/pluginnotificationtask.cpp +++ b/lib/methods/pluginnotificationtask.cpp @@ -25,11 +25,7 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification, REQUIRE_NOT_NULL(notification); REQUIRE_NOT_NULL(user); - NotificationCommand::Ptr commandObj; - if (NotificationCommand::ExecuteOverride) - commandObj = NotificationCommand::ExecuteOverride; - else - commandObj = notification->GetCommand(); + NotificationCommand::Ptr commandObj = NotificationCommand::ExecuteOverride ? NotificationCommand::ExecuteOverride : notification->GetCommand(); auto type = static_cast(itype); diff --git a/lib/methods/randomchecktask.cpp b/lib/methods/randomchecktask.cpp index 083d07516..9b133ef0e 100644 --- a/lib/methods/randomchecktask.cpp +++ b/lib/methods/randomchecktask.cpp @@ -31,11 +31,7 @@ void RandomCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes + ". Icinga 2 has been running for " + Utility::FormatDuration(uptime) + ". Version: " + Application::GetAppVersion(); - CheckCommand::Ptr command; - if (CheckCommand::ExecuteOverride) - command = CheckCommand::ExecuteOverride; - else - command = checkable->GetCheckCommand(); + CheckCommand::Ptr command = CheckCommand::ExecuteOverride ? CheckCommand::ExecuteOverride : checkable->GetCheckCommand(); String commandName = command->GetName(); ServiceState state = static_cast(Utility::Random() % 4); diff --git a/lib/methods/sleepchecktask.cpp b/lib/methods/sleepchecktask.cpp index a3e62d133..ed3a5b6ee 100644 --- a/lib/methods/sleepchecktask.cpp +++ b/lib/methods/sleepchecktask.cpp @@ -18,11 +18,7 @@ void SleepCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu REQUIRE_NOT_NULL(checkable); REQUIRE_NOT_NULL(cr); - CheckCommand::Ptr commandObj; - if (CheckCommand::ExecuteOverride) - commandObj = CheckCommand::ExecuteOverride; - else - commandObj = checkable->GetCheckCommand(); + CheckCommand::Ptr commandObj = CheckCommand::ExecuteOverride ? CheckCommand::ExecuteOverride : checkable->GetCheckCommand(); Host::Ptr host; Service::Ptr service;