Revert "Implement last_notification_result handling for Notification objects"

This reverts commit 1706b297a5.
This commit is contained in:
Michael Friedrich 2020-01-07 14:21:06 +01:00
parent d242b41704
commit 152709071d
8 changed files with 18 additions and 60 deletions

View File

@ -509,14 +509,10 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User::
String commandName = command->GetName();
try {
NotificationResult::Ptr nr = new NotificationResult();
nr->SetExecutionStart(Utility::GetTime());
command->Execute(this, user, cr, nr, type, author, text);
command->Execute(this, user, cr, type, author, text);
/* required by compatlogger */
Checkable::OnNotificationSentToUser(this, GetCheckable(), user, type, cr, author, text, command->GetName(), nullptr);
Service::OnNotificationSentToUser(this, GetCheckable(), user, type, cr, author, text, commandName, nullptr);
Log(LogInformation, "Notification")
<< "Completed sending '" << NotificationTypeToString(type)
@ -537,27 +533,6 @@ void Notification::ProcessNotificationResult(const NotificationResult::Ptr& nr,
if (!nr)
return;
double now = Utility::GetTime();
if (nr->GetExecutionStart() == 0)
nr->SetExecutionStart(now);
if (nr->GetExecutionEnd() == 0)
nr->SetExecutionEnd(now);
/* Determine the execution endpoint from a locally executed check. */
if (!origin || origin->IsLocal())
nr->SetExecutionEndpoint(IcingaApplication::GetInstance()->GetNodeName());
if (!IsActive())
return;
{
ObjectLock olock(this);
SetLastNotificationResult(nr);
}
/* Notify cluster, API and feature events. */
OnNewNotificationResult(this, nr, origin);
}

View File

@ -83,7 +83,7 @@ public:
Endpoint::Ptr GetCommandEndpoint() const;
void ProcessNotificationResult(const NotificationResult::Ptr& nr, const MessageOrigin::Ptr& origin = nullptr);
void ProcessNotificationResult(const NotificationResult::Ptr& nr, const MessageOrigin::Ptr& origin);
// Logging, etc.
static String NotificationTypeToString(NotificationType type);

View File

@ -1,8 +1,6 @@
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
#include "icinga/customvarobject.hpp"
#include "icinga/notificationresult.hpp"
#include "base/array.hpp"
#impl_include "icinga/notificationcommand.hpp"
#impl_include "icinga/service.hpp"
@ -18,7 +16,6 @@ public:
virtual String MakeName(const String& shortName, const Object::Ptr& context) const;
virtual Dictionary::Ptr ParseName(const String& name) const;
};
}}}
class Notification : CustomVarObject < NotificationNameComposer
@ -88,7 +85,6 @@ class Notification : CustomVarObject < NotificationNameComposer
[state] Timestamp next_notification;
[state] int notification_number;
[state] Timestamp last_problem_notification;
[state] NotificationResult::Ptr last_notification_result;
[config, navigation] name(Endpoint) command_endpoint (CommandEndpointRaw) {
navigate {{{

View File

@ -8,15 +8,14 @@ using namespace icinga;
REGISTER_TYPE(NotificationCommand);
Dictionary::Ptr NotificationCommand::Execute(const Notification::Ptr& notification,
const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr,
const NotificationType& type, const String& author, const String& comment,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationType& type,
const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros,
bool useResolvedMacros)
{
return GetExecute()->Invoke({
notification,
user,
cr,
nr,
type,
author,
comment,

View File

@ -23,8 +23,8 @@ public:
DECLARE_OBJECTNAME(NotificationCommand);
virtual Dictionary::Ptr Execute(const intrusive_ptr<Notification>& notification,
const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr,
const NotificationType& type, const String& author, const String& comment,
const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationType& type,
const String& author, const String& comment,
const Dictionary::Ptr& resolvedMacros = nullptr,
bool useResolvedMacros = false);
};

View File

@ -19,6 +19,7 @@
#include "icinga/notificationresult.hpp"
#include "icinga/notificationresult-ti.cpp"
#include "base/scriptglobal.hpp"
using namespace icinga;

View File

@ -15,12 +15,12 @@
using namespace icinga;
REGISTER_FUNCTION_NONCONST(Internal, PluginNotification, &PluginNotificationTask::ScriptFunc, "notification:user:cr:nr:itype:author:comment:resolvedMacros:useResolvedMacros");
REGISTER_FUNCTION_NONCONST(Internal, PluginNotification, &PluginNotificationTask::ScriptFunc, "notification:user:cr:itype:author:comment:resolvedMacros:useResolvedMacros");
void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification,
const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr,
int itype, const String& author, const String& comment,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
const User::Ptr& user, const CheckResult::Ptr& cr, int itype,
const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros,
bool useResolvedMacros)
{
REQUIRE_NOT_NULL(notification);
REQUIRE_NOT_NULL(user);
@ -55,28 +55,16 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification,
PluginUtility::ExecuteCommand(commandObj, checkable, cr, resolvers,
resolvedMacros, useResolvedMacros, timeout,
std::bind(&PluginNotificationTask::ProcessFinishedHandler, checkable, notification, nr, _1, _2));
std::bind(&PluginNotificationTask::ProcessFinishedHandler, checkable, _1, _2));
}
void PluginNotificationTask::ProcessFinishedHandler(const Checkable::Ptr& checkable,
const Notification::Ptr& notification, const NotificationResult::Ptr& nr, const Value& commandLine, const ProcessResult& pr)
void PluginNotificationTask::ProcessFinishedHandler(const Checkable::Ptr& checkable, const Value& commandLine, const ProcessResult& pr)
{
if (pr.ExitStatus != 0) {
Process::Arguments parguments = Process::PrepareCommand(commandLine);
Log(LogWarning, "PluginNotificationTask")
<< "Notification command for checkable '" << checkable->GetName()
<< "' and notification '" << notification->GetName() << "' (PID: " << pr.PID
<< "Notification command for object '" << checkable->GetName() << "' (PID: " << pr.PID
<< ", arguments: " << Process::PrettyPrintArguments(parguments) << ") terminated with exit code "
<< pr.ExitStatus << ", output: " << pr.Output;
}
String output = pr.Output.Trim();
nr->SetCommand(commandLine);
nr->SetOutput(output);
nr->SetExitStatus(pr.ExitStatus);
nr->SetExecutionStart(pr.ExecutionStart);
nr->SetExecutionEnd(pr.ExecutionEnd);
notification->ProcessNotificationResult(nr);
}

View File

@ -20,15 +20,14 @@ class PluginNotificationTask
{
public:
static void ScriptFunc(const Notification::Ptr& notification,
const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationResult::Ptr& nr,
int itype, const String& author, const String& comment,
const User::Ptr& user, const CheckResult::Ptr& cr, int itype,
const String& author, const String& comment,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros);
private:
PluginNotificationTask();
static void ProcessFinishedHandler(const Checkable::Ptr& checkable,
const Notification::Ptr& notification, const NotificationResult::Ptr& nr,
const Value& commandLine, const ProcessResult& pr);
};