-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a114a6
commit 6de9f58
Showing
11 changed files
with
201 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* The WindowsEventLogLogger type writes log information to the Windows Event Log. | ||
*/ | ||
|
||
object WindowsEventLogLogger "windowseventlog" { | ||
severity = "warning" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
MessageId=0x1 | ||
SymbolicName=MSG_PLAIN_LOG_ENTRY | ||
Language=English | ||
%1 | ||
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* Icinga 2 | (c) 2021 Icinga GmbH | GPLv2+ */ | ||
|
||
#ifdef _WIN32 | ||
#include "base/windowseventloglogger.hpp" | ||
#include "base/windowseventloglogger-ti.cpp" | ||
#include "base/windowseventloglogger-provider.h" | ||
#include "base/configtype.hpp" | ||
#include "base/statsfunction.hpp" | ||
#include <windows.h> | ||
|
||
using namespace icinga; | ||
|
||
REGISTER_TYPE(WindowsEventLogLogger); | ||
|
||
REGISTER_STATSFUNCTION(WindowsEventLogLogger, &WindowsEventLogLogger::StatsFunc); | ||
|
||
INITIALIZE_ONCE(&WindowsEventLogLogger::StaticInitialize); | ||
|
||
static HANDLE l_EventLog = nullptr; | ||
|
||
void WindowsEventLogLogger::StaticInitialize() | ||
{ | ||
l_EventLog = RegisterEventSourceA(nullptr, "Icinga 2"); | ||
} | ||
|
||
void WindowsEventLogLogger::StatsFunc(const Dictionary::Ptr& status, const Array::Ptr&) | ||
{ | ||
DictionaryData nodes; | ||
|
||
for (const WindowsEventLogLogger::Ptr& logger : ConfigType::GetObjectsByType<WindowsEventLogLogger>()) { | ||
nodes.emplace_back(logger->GetName(), 1); | ||
} | ||
|
||
status->Set("windowseventloglogger", new Dictionary(std::move(nodes))); | ||
} | ||
|
||
/** | ||
* Processes a log entry and outputs it to the Windows Event Log. | ||
* | ||
* @param entry The log entry. | ||
*/ | ||
void WindowsEventLogLogger::ProcessLogEntry(const LogEntry& entry) | ||
{ | ||
if (l_EventLog != nullptr) { | ||
std::string message = Logger::SeverityToString(entry.Severity) + "/" + entry.Facility + ": " + entry.Message; | ||
std::array<const char *, 1> strings{ | ||
message.c_str() | ||
}; | ||
|
||
WORD eventType; | ||
switch (entry.Severity) { | ||
case LogCritical: | ||
eventType = EVENTLOG_ERROR_TYPE; | ||
break; | ||
case LogWarning: | ||
eventType = EVENTLOG_WARNING_TYPE; | ||
break; | ||
default: | ||
eventType = EVENTLOG_INFORMATION_TYPE; | ||
} | ||
|
||
ReportEventA(l_EventLog, eventType, 0, MSG_PLAIN_LOG_ENTRY, NULL, strings.size(), 0, strings.data(), NULL); | ||
} | ||
} | ||
|
||
void WindowsEventLogLogger::Flush() | ||
{ | ||
/* Nothing to do here. */ | ||
} | ||
|
||
#endif /* _WIN32 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* Icinga 2 | (c) 2021 Icinga GmbH | GPLv2+ */ | ||
|
||
#ifndef WINDOWSEVENTLOGLOGGER_H | ||
#define WINDOWSEVENTLOGLOGGER_H | ||
|
||
#ifdef _WIN32 | ||
#include "base/i2-base.hpp" | ||
#include "base/windowseventloglogger-ti.hpp" | ||
|
||
namespace icinga | ||
{ | ||
|
||
/** | ||
* A logger that logs to the Windows Event Log. | ||
* | ||
* @ingroup base | ||
*/ | ||
class WindowsEventLogLogger final : public ObjectImpl<WindowsEventLogLogger> | ||
{ | ||
public: | ||
DECLARE_OBJECT(WindowsEventLogLogger); | ||
DECLARE_OBJECTNAME(WindowsEventLogLogger); | ||
|
||
static void StaticInitialize(); | ||
static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata); | ||
|
||
protected: | ||
void ProcessLogEntry(const LogEntry& entry) override; | ||
void Flush() override; | ||
}; | ||
|
||
} | ||
#endif /* _WIN32 */ | ||
|
||
#endif /* WINDOWSEVENTLOGLOGGER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* Icinga 2 | (c) 2021 Icinga GmbH | GPLv2+ */ | ||
|
||
#include "base/logger.hpp" | ||
|
||
library base; | ||
|
||
namespace icinga | ||
{ | ||
|
||
class WindowsEventLogLogger : Logger | ||
{ | ||
activation_priority -100; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters