mirror of
https://github.com/Icinga/icinga2.git
synced 2026-02-19 02:29:16 -05:00
I've used the following command to replace the original copyright header
lines in a C-style comment block:
```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{/\*[^*]*\(\s*c\s*\)\s*(\d{4})\s*Icinga\s+GmbH[^*]*\*/}{// SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n// SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```
For files that use shell-style comments (#) like CMakeLists.txt, I've
used this command:
```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{#.*\(\s*c\s*\)\s(\d{4})\sIcinga\s+GmbH.*}{# SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n# SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```
And for SQL files:
```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{--.*\(c\)\s(\d{4})\sIcinga\sGmbH.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{-- Copyright \(c\)\s(\d{4})\sIcinga\s+Development\sTeam.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```
84 lines
2.2 KiB
C++
84 lines
2.2 KiB
C++
// SPDX-FileCopyrightText: 2021 Icinga GmbH <https://icinga.com>
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#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.
|
|
*
|
|
* This function implements the interface expected by the Logger base class and passes
|
|
* the log entry to WindowsEventLogLogger::WriteToWindowsEventLog().
|
|
*
|
|
* @param entry The log entry.
|
|
*/
|
|
void WindowsEventLogLogger::ProcessLogEntry(const LogEntry& entry) {
|
|
WindowsEventLogLogger::WriteToWindowsEventLog(entry);
|
|
}
|
|
|
|
/**
|
|
* Writes a LogEntry object to the Windows Event Log.
|
|
*
|
|
* @param entry The log entry.
|
|
*/
|
|
void WindowsEventLogLogger::WriteToWindowsEventLog(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 */
|