Commit Graph

1846 Commits

Author SHA1 Message Date
Julian Brost a927ba39b7 Windows: only include critical messages in early log messages
The point of logging to the Windows Event Log was to catch errors that happen
before the full logging configuration has been loaded and enabled. Messages
like the number of loaded objects per type just cause noise in the log and
provide little benefit. Therefore raise the required log level at this stage.

Note that this commit removes the (never documented) ability to use the -x flag
to change the level. But doing so would require patching the command line of
the service in the registry anyways.
2022-07-14 14:07:56 +02:00
Julian Brost abe2dfa763 Replace EventuallyAtomic with AtomicOrLocked which falls back to a mutex
Apparently there was a reason for making the members of generated classes
atomic. However, this was only done for some types, others were still accessed
using non-atomic operations. For members of type T::Ptr (i.e.  intrusive_ptr<T>),
this can result in a double free when multiple threads access the same variable
and at least one of them writes to the variable.

This commit makes use of std::atomic<T> for more T (it removes the additional
constraint sizeof(T) <= sizeof(void*)) and uses a type including a mutex for
load and store operations as a fallback.
2022-05-03 12:02:46 +02:00
Julian Brost b24a2fa2a5
Merge pull request #9179 from Icinga/Al2Klimov-patch-3
Let new cluster certificates expire after 397 days, not 15 years
2022-04-11 15:29:05 +02:00
Alexander A. Klimov e490883577 Renew certificates also periodically 2022-04-11 11:02:39 +02:00
Yonas Habteab 575af4c980 Defer: Allow to cancel the callback before going out of scope 2022-03-30 09:42:22 +02:00
Alexander A. Klimov 9be2eb8e5e Introduce IsCertUptodate() 2022-03-29 16:47:23 +02:00
Alexander A. Klimov e06b631f3a Let new cluster certificates expire after 397 days, not 15 years
https://cabforum.org/wp-content/uploads/CA-Browser-Forum-BR-1.7.3.pdf, section 6.3.2:

"Subscriber Certificates issued on or after 1 September 2020 SHOULD NOT have a Validity Period greater than 397 days and MUST NOT have a Validity Period greater than 398 days."
2022-03-29 16:47:23 +02:00
Julian Brost bf5b905707
Merge pull request #9250 from Icinga/feature/fix-compiler-warning-do-not-move-local-variables
Fix compiler warnings don't move local variables
2022-03-08 11:37:09 +01:00
Alexander A. Klimov 9585a63fa0 Introduce IoEngine::YieldCurrentCoroutine() 2022-03-02 16:39:44 +01:00
Alexander A. Klimov ad0fe764f7 Icinga DB: log amount of history kept in memory every 10s 2022-03-02 16:39:37 +01:00
Alexander A. Klimov 8ea62f7fc7 Icinga DB: keep history in memory until written to Redis
by putting the messages into a Bulker and retrying each chunk.
2022-03-02 16:39:37 +01:00
Alexander A. Klimov 9a8d388734 Introduce Bulker 2022-03-02 16:39:37 +01:00
Yonas Habteab f00a3c9693 ConfigObject: Initialize local static var at declaration to ensure thread safety 2022-02-25 15:23:49 +01:00
Yonas Habteab a0607aceff Fix compiler warnings don't move local variables 2022-02-22 17:51:43 +01:00
Noah Hilverling 10bde2075a Dictionary: Make sure underlaying map is ordered 2021-11-12 13:34:57 +01:00
Julian Brost 6cd3a483a0 tlsutility: move hex encoding into a separate function BinaryToHex 2021-11-05 14:14:37 +01:00
Tobias Deiminger eb8f67335e Define SD_JOURNAL_SUPPRESS_LOCATION more locally
add_definitions would set SD_JOURNAL_SUPPRESS_LOCATION for all targets
in directory and sub-directories. However, another future target might
want the opposite, so define it as local as possible to journaldlogger.cpp.

To make this work, we must take journaldlogger.cpp out of the unity
build, because all files from a unity of share compiler definitions.
2021-09-23 16:08:39 +02:00
Tobias Deiminger 173caa42aa Add a JournaldLogger
As proposed in #8857, this adds a Logger subclass that writes structured
log messages via journald's native protocol by calling sd_journal_sendv.
The feature therefore depends on the systemd library. sd_journal_sendv is
available since the early days (systemd v38), so a version check is
probably superflous.

We add the following fields to each record:
- MESSAGE: The log message
- PRIORITY (aka severity): Numeric severity as in RFC5424 section 6.2.1
- SYSLOG_FACILITY: Numeric facility as in RFC5424 section 6.2.1
- SYSLOG_IDENTIFIER: If provided, use value from configuration.
  Else use systemd's default behaior, which is to determine the field
  by using libc's program_invocation_short_name, resulting in "icinga2".
- ICINGA2_FACILITY: Facility as in Log::Log(..., String facility, ...),
  e.g. "ApiListener"
- some more fields are added automatically by systemd

Fields are stored indexed, so we can do fast queries for certain field
values. Example:

$ journalctl -t icinga2 ICINGA2_FACILITY=ApiListener -n 5

Syslog compatiblity is ratained because good old tag, severity and facility
is stored along, and systemd can forward to syslog daemons.

See also https://systemd.io/JOURNAL_NATIVE_PROTOCOL/.
2021-09-23 16:08:11 +02:00
Tobias Deiminger de7808e32c Make syslog facility handling reusable
The upcoming JournaldLogger will need the same syslog validation and
conversion logic, so factor it out from SyslogLogger to make it
reusable.

Also explicitely include syslog.h, which defines the syslog()
function.
2021-09-15 10:15:22 +02:00
Julian Brost 396f003c69 Enable hostname verification in UnbufferedAsioTlsStream 2021-08-13 10:58:10 +02:00
Julian Brost ec73b417f2 ApiListener: Choose bind host default based on OS IPv6 support 2021-08-06 12:19:08 +02:00
Julian Brost 9d5ae0f6fa
Merge pull request #8899 from Icinga/feature/icingadb-connect_timeout
Introduce IcingaDB#connect_timeout
2021-07-28 13:52:00 +02:00
Julian Brost cc8d3fbedd
Merge pull request #8937 from Icinga/bugfix/timeout-always-unknown
Override exit code on process timeout
2021-07-28 11:56:42 +02:00
Alexander A. Klimov 504fdda76c Introduce DEFAULT_CONNECT_TIMEOUT 2021-07-27 21:57:02 +02:00
Noah Hilverling 07cb6cd1cb
Merge pull request #8930 from Icinga/bugfix/wq-balance
WorkQueue#ParallelFor(): optionally don't pre-glue items together to chunks of different size
2021-07-27 19:05:26 +02:00
Julian Brost a55939e462 Override exit code on process timeout
As Icinga first sends a SIGTERM to a check plugin on timeout to allow it to
terminate gracefully, this is not really part of the plugin API specification
and we cannot assume that plugins will handle this correctly and still exit
with an exit code that maps to UNKNOWN. Therefore, once Icinga decides to kill
a process, force its exit code to 128 to be sure the state will be UNKNOWN
after a timeout.
2021-07-27 17:57:19 +02:00
Alexander A. Klimov 8731d84299 WorkQueue#ParallelFor(): optionally don't pre-glue items together to chunks of different size
... to equally distribute the load across the workers.
2021-07-26 11:40:43 +02:00
Alexander A. Klimov 37e53eaa68 Icinga DB: support TLS 2021-07-22 14:34:07 +02:00
Alexander A. Klimov 7f7637c9b8 Introduce DEFAULT_TLS_CIPHERS and DEFAULT_TLS_PROTOCOLMIN 2021-07-22 11:12:33 +02:00
Alexander A. Klimov 80a1128ec7 Introduce SetupSslContext() 2021-07-22 11:12:33 +02:00
Alexander A. Klimov fbcaf82e3e InitSslContext(): fall back to default root CAs 2021-07-22 11:12:33 +02:00
Alexander A. Klimov 2728603c29 Rename SetupSslContext() to InitSslContext() 2021-07-22 11:12:33 +02:00
Alexander Aleksandrovič Klimov 692f5aa615
Merge pull request #8718 from Icinga/feature/tls-1.3
Support TLS 1.3
2021-06-29 17:52:55 +02:00
Alexander Aleksandrovič Klimov 6048d0e800
Merge pull request #8373 from Icinga/feature/improve-crashlog
Improve crashlog
2021-06-29 17:52:25 +02:00
Julian Brost 0e7a05ad7a Support TLS 1.3 2021-06-29 11:08:47 +02:00
Alexander Aleksandrovič Klimov 58e329bc03
Merge pull request #7874 from Icinga/feature/sd_notify-7329
sd_notify() systemd about what we're doing right now
2021-06-28 18:20:15 +02:00
Julian Brost d1839471f4
Merge pull request #8846 from Icinga/bugfix/logger-default-severity
Set a default severity for loggers
2021-06-28 17:15:26 +02:00
Noah Hilverling 8af66ce44c
Merge pull request #8710 from Icinga/feature/windows-event-log
Add support for Windows Event Log and write early log messages to it
2021-06-24 09:19:50 +02:00
Alexander Aleksandrovič Klimov 9f24107a08
Merge pull request #8748 from Icinga/bugfix/icingadb-cv-function
JsonEncode(): encode non-[]/{} objects as strings, not null
2021-06-23 18:01:21 +02:00
Alexander A. Klimov 0fd474ee8d Hide $NOTIFY_SOCKET from plugins
refs #7329
2021-06-23 17:42:25 +02:00
Julian Brost 963ad9dd1c Set a default severity for loggers
So far, the documentation has claimed that loggers have a default severity
(information for FileLogger and warning for SyslogLogger). However, this was
not the case and not setting the severity resulted in a configuration error.

This commit changes the default value to be information for all loggers.
2021-06-23 16:57:44 +02:00
Julian Brost 05ca30a6a0 Write early log messages to the Windows Event Log
When Icinga 2 is started as a service, the early log messages generated
until the FileLogger object is activated are lost and make it really
hard to debug issues that (only) occur when Icinga 2 reloads.

With this commit, these early log messages are written to the Windows
Event Log.
2021-06-21 15:15:54 +02:00
Julian Brost 6de9f58810 Add WindowsEventLogLogger 2021-06-21 15:15:54 +02:00
Julian Brost 97d6876803 Utility: add a function to truncate strings while avoiding collisions 2021-06-17 16:21:01 +02:00
Julian Brost 005fac0a23
Merge pull request #8742 from Icinga/bugfix/double-to-string
Convert::ToString(double): handle integral values too large for long long correctly
2021-06-15 12:28:15 +02:00
Julian Brost 06999faf25 Allow using E in perfdata both as exponent and unit prefix 2021-06-08 12:37:13 +02:00
Julian Brost 62cbe72cdb
Merge pull request #8492 from Icinga/bugfix/perfdata-scientific-notation
Fix perfdata parser not recognize scientific notation
2021-06-07 15:29:52 +02:00
Alexander A. Klimov fa2666fecf JsonEncode(): encode non-[]/{} objects as strings, not null
... to represent function custom vars as such in Icinga DB.
2021-04-30 15:49:52 +02:00
Julian Brost 2d6d87d10f Convert::ToString(double): handle integral values too large for long long correctly
Even if a double represents an integer value, it might not be safe to cast it
to long long as it may overflow the type. Instead just use print the double
value with 0 decimals using std::setprecision.

Before:

    <1> => 18446744073709551616.to_string()
    "-9223372036854775808"

After:

    <1> => 18446744073709551616.to_string()
    "18446744073709551616"
2021-04-27 17:31:50 +02:00
Alexander Aleksandrovič Klimov 0ee93754ee
Merge pull request #8691 from Icinga/bugfix/retry-rename-on-windows
Retry file rename operations on Windows for some errors
2021-03-26 17:16:25 +01:00