Commit Graph

13861 Commits

Author SHA1 Message Date
Yonas Habteab 932a53449d JsonRpcConnection: Raise an exception when trying to send to disconnected clients 2024-08-27 14:23:41 +02:00
Julian Brost 9222a63ff7 Make sure log file is reopened when `ApiListener::ReplayLog()` returns 2024-08-27 14:23:41 +02:00
Yonas Habteab a5a83e311a Defer: Allow empty initialization & add `SetFunc()` method 2024-08-27 14:23:41 +02:00
Yonas Habteab 73db30c08b Use `Defer` class for cleanup in `ApiListener::ReplayLog()` 2024-08-27 14:23:41 +02:00
Alexander A. Klimov f074e24d2a ApiListener#ReplayLog(): stop reading files ASAP on send error 2024-08-27 14:23:41 +02:00
Alexander A. Klimov b538ad2528 JsonRpcConnection#Send*(): discard messages ASAP once shutting down
Especially ApiListener#ReplayLog() enqueued lots of messages into
JsonRpcConnection#{m_IoStrand,m_OutgoingMessagesQueue} (RAM) even if
the connection was shut(ting) down. Now #Disconnect() takes effect ASAP.
2024-08-27 14:23:41 +02:00
Alexander A. Klimov 33f8ea6dcc JsonRpcConnection#Disconnect(): spawn coroutine only if necessary
by checking the now atomic #m_ShuttingDown outside of it.
2024-08-27 14:23:41 +02:00
Tobias Bauriedel 600281bfa0
Fix ITL for http CheckCommand definition
There were some missing arguments.

ref/NC/806131
2024-08-27 14:07:43 +02:00
Yonas Habteab a51910a19b
Merge pull request #9975 from nicolasberens/bugfix/update-check_snmp-9907
add multiplier option to check_snmp which is available since monitori…
2024-08-26 17:12:09 +02:00
Nicolas Berens c76cade9ae add new variables to documentation 2024-08-26 15:36:21 +02:00
Nicolas Berens 91b1638a01 add multiplier option to check_snmp which is available since monitoring-plugins v2.3.3, refs #9907 2024-08-26 15:36:21 +02:00
Julian Brost 145bb6109b
Merge pull request #10112 from Icinga/formatdatetime
Overhaul Utility::FormatDateTime()
2024-08-26 14:31:00 +02:00
Julian Brost 585b357c3f
Merge pull request #10090 from Icinga/rpi-os
Clarify that our Debian installation docs also apply to the Raspberry Pi OS
2024-08-26 13:54:30 +02:00
Julian Brost 39ae2e8ca4 Utility::FormatDateTime(): provide an overload for tm*
This allows the function to be used both with a double timestamp or a pointer
to a tm struct. With this, a similar implementation inside the tests can simply
use our regular function.
2024-08-23 12:48:50 +02:00
Julian Brost d5b3ffaa6d Utility::FormatDateTime(): handle invalid format strings on Windows
On Windows, the strftime() function family invokes an invalid parameter handler
when the format string is invalid (see the "Remarks" section in their
documentation). std::put_time() shows the same behavior as it uses
_wcsftime_l() internally. The default invalid parameter handler may terminate
the process, which can be a problem given that the format string can be
specified by the user from the Icinga DSL.

Thus, temporarily set a thread-local no-op handler to disable the default one
allowing the program to continue. This then simply results in the function
returning an error which then results in an exception as we ask the stream to
throw one.

See also:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strftime-wcsftime-strftime-l-wcsftime-l?view=msvc-170
https://learn.microsoft.com/en-us/cpp/c-runtime-library/parameter-validation?view=msvc-170
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/set-invalid-parameter-handler-set-thread-local-invalid-parameter-handler?view=msvc-170
2024-08-23 12:48:50 +02:00
Julian Brost 0285028689 Utility::FormatDateTime(): handle errors from strftime()
So far, the return value of strftime() was simply ignored and the output buffer
passed to the icinga::String constructor. However, there are error conditions
where strftime() returns 0 to signal an error, like if the buffer was too small
for the output. In that case, there's no guarantee on the buffer contents and
reading it can result in undefined behavior. Unfortunately, returning 0 can
also indicate success and strftime() doesn't set errno, so there's no reliable
way to distinguish both situations. Thus, the implementation now returns the
empty string in both cases.

I attempted to use std::put_time() at first as that allows for better error
handling, however, there were problems with the implementation on Windows (see
inline comment), so I put that plan on hold at left strftime() there for the
time being.
2024-08-23 12:42:54 +02:00
Julian Brost c2c66908f6 Utility::FormatDateTime(): use localtime_s() on Windows
localtime() is not thread-safe as it returns a pointer to a shared tm struct.
Everywhere except on Windows, localtime_r() is used already which avoids the
problem by using a struct allocated by the caller for the output.

Windows actually has a similar function called localtime_s() which has the same
properties, just with a different name and order of arguments.
2024-08-23 12:42:32 +02:00
Julian Brost 704acdc698 Utility::FormatDateTime(): use boost::numeric_cast<>()
The previous implementation actually had undefined behavior when called with a
double that can't be represented as time_t. With boost::numeric_cast, there's a
convenient cast available that avoids this and throws an exceptions on
overflow.

It's undefined behavior ([0], where the implicit conversion rule comes into
play because the C-style cast uses static_cast [1] which in turn uses the
imlicit conversion as per rule 5 of [2]):

> A prvalue of floating-point type can be converted to a prvalue of any integer
> type. The fractional part is truncated, that is, the fractional part is
> discarded.
>
> * If the truncated value cannot fit into the destination type, the behavior
>   is undefined (even when the destination type is unsigned, modulo arithmetic
>   does not apply).

Note that on Linux amd64, the undefined behavior typically manifests itself in
the result being the minimal value of time_t which then results in localtime_r
failing with EOVERFLOW.

[0]: https://en.cppreference.com/w/cpp/language/implicit_conversion#Floating.E2.80.93integral_conversions
[1]: https://en.cppreference.com/w/cpp/language/explicit_cast
[2]: https://en.cppreference.com/w/cpp/language/static_cast
2024-08-23 12:42:30 +02:00
Julian Brost 090dcfd70f Add tests for Utility::FormatDateTime() 2024-08-22 12:23:22 +02:00
Alexander Aleksandrovič Klimov a8adfeda60
Merge pull request #10120 from Icinga/Al2Klimov-patch-7
doc/02-installation.md: remove outdated info
2024-08-21 14:40:24 +02:00
Alexander A. Klimov d6bb971c7f doc/02-installation.md: remove Raspbian which is not supported anymore 2024-08-21 13:20:25 +02:00
Alexander A. Klimov 14e269060a Clarify that our Debian installation docs also apply to the Raspberry Pi OS 2024-08-21 13:19:54 +02:00
Alexander Aleksandrovič Klimov aab0952bb1
doc/02-installation.md: remove outdated info
The Backports Repository is required for Debian 9, but we don't build even v10 anymore.
2024-08-21 12:09:27 +02:00
Alexander A. Klimov 81607426a2 .deb: let user install icinga-archive-keyring package 2024-08-21 11:48:19 +02:00
Julian Brost 914a26ce79
Merge pull request #10118 from Icinga/Al2Klimov-patch-7
doc/21-development.md: fix bad link address
2024-08-21 11:01:10 +02:00
Julian Brost c4c00537ca
Merge pull request #10114 from Icinga/Boost1.86
Bump Boost shipped for Windows to v1.86
2024-08-21 10:59:51 +02:00
Alexander A. Klimov 584340a203 Bump Boost shipped for Windows to v1.86 2024-08-20 18:18:07 +02:00
Alexander Aleksandrovič Klimov 4fefdd0969
doc/21-development.md: fix bad link address 2024-08-20 18:13:42 +02:00
Julian Brost be50050d2b
Merge pull request #10115 from Icinga/Al2Klimov-patch-7
doc/03-monitoring-basics.md: fix invalid link address
2024-08-20 16:18:40 +02:00
Julian Brost ac84405334
Merge pull request #10116 from Icinga/missing-angle-bracket
Docs: Add missing angle bracket
2024-08-20 10:07:43 +02:00
Julian Brost 4c83d793a6
Merge pull request #9983 from Icinga/broken-timeperiod
Fix broken `TimePeriod/ScheduledDowntime`s
2024-08-20 10:05:59 +02:00
Alexander Aleksandrovič Klimov edb6730858
doc/03-monitoring-basics.md: fix invalid link address 2024-08-19 16:49:12 +02:00
Yonas Habteab ca7cc54438 Checkable: Don't recalculate `next_check` while processing remotely genrated check
Currently, when processing a `CheckResult`, it will first trigger an
`OnNextCheckChanged` event, which is sent to all connected endpoints.
Then, when `Checkable::ProcessCheckResult()` returns, an `OnCheckResult`
event is fired, which is of course also sent to all connected endpoints.

Next, the other endpoints receive the `event::SetNextCheck` cluster
event followed by `event::CheckResult`and invoke
`checkable#SetNextCheck()` and `Checkable#CheckResult()` with the newly
received check. So they also try to recalculate the next check
themselves and invalidate the previously received next check timestamp
from the source endpoint. Since each endpoint randomly initialises its
own scheduling offset, the recalculated next check will always differ by
a split second/millisecond on each of them. As a consequence, two Icinga
DB HA instances will generate two different checksums for the same state
and causes the state histories to be fully resynchronised after a
takeover/Icinga 2 reload.
2024-08-16 16:15:56 +02:00
Alexander Aleksandrovič Klimov 02ba5e4101
Merge pull request #10015 from Icinga/malloc_info
/v1/debug/malloc_info: call malloc_info(3) if available
2024-08-12 14:41:09 +02:00
Alexander A. Klimov f3c7ac11e9 /v1/debug/malloc_info: call malloc_info(3) if available
The GNU libc function malloc_info(3) provides memory allocation and usage
statistics of Icinga 2 itself.
2024-08-09 12:59:25 +02:00
Julian Brost 2bfa1f1649
Merge pull request #10107 from Icinga/timeperiod-nth-day-of-month-off-by-one
Timeperiods: fix off by one when calculating n-th last weekday of the month
2024-08-08 14:40:18 +02:00
Julian Brost c45829b59f Timeperiods: fix off by one when calculating n-th last weekday of the month
A day specification like "monday -1" refers to the last Monday of the month.
However, there was an off by one if the first day of the next month is the same
day of the week, i.e. a Monday in this example.

LegacyTimePeriod::FindNthWeekday() picks a day to start the search for the day
in question. When given a negative n to search for the n-th last day, it
wrongly used the first day of the following month as the start and counted it
as if it was within the current month. This resulted in a 1/7 chance that the
result was one week too late.

This is fixed by using the last day of the current month instead.
2024-08-07 12:06:05 +02:00
Yonas Habteab c4edecc1fb Unregister invalid config objects properly 2024-08-06 16:59:30 +02:00
Julian Brost 07d253009a
Merge pull request #10013 from Icinga/broken-runtime-config-sync
Fix broken runtime config sync
2024-08-06 11:57:24 +02:00
Yonas Habteab 4f94891b52 Add advanced timeperiod range,include/exclude test cases 2024-08-02 11:12:51 +02:00
Yonas Habteab ddf7143777 tests: Add some basic tests cases for `LegacyTimePeriod::IsInTimeRange()` 2024-08-02 11:12:51 +02:00
Yonas Habteab 86347013a6 Check segemnt start date inclusively in `TimePeriod::IsInside()` 2024-08-01 16:16:48 +02:00
Yonas Habteab 4daa03dc02 Fix broken timeperiods/scheduleddowntimes 2024-08-01 15:14:34 +02:00
Julian Brost 0463607050
Merge pull request #10104 from Icinga/gha-windows-ctest-fix
GHA: Unbreak Windows Tests
2024-07-31 13:52:03 +02:00
Julian Brost ce81596ad5
Merge pull request #10096 from Icinga/Al2Klimov-patch-7
GHA: add openSUSE 15.6 and SLES 15.6
2024-07-31 12:19:52 +02:00
Alvar Penning 8db33e5b3c
GHA: Unbreak Windows Tests
As seen in the recent GHA run for #10102, the two Windows Actions have
failed. The output log contains:

> DEBUG:   27+  >>>> ctest.exe -C "${env:CMAKE_BUILD_TYPE}" -T test -O $env:ICINGA2_BUILDPATH/Test.xml
> --output-on-failure --log_level=all
> CMake Error: Unknown argument: --log_level=all
> CMake Error: Run 'ctest --help' for all supported options.

After consulting ctest(1), older versions included, I have never found a
mention of the "--log_level" flag. Since the useful
"--output-on-failure" flag is already set, which will "[o]utput anything
outputted by the test program if the test should fail", I do not see any
further reason for more logging information.

This flag was introduced in 7665143afa,
but I have not found any reasoning for the flag in particular.
2024-07-31 11:19:22 +02:00
Julian Brost 414d85571b
Merge pull request #10095 from Icinga/el7
GHA: drop EOL EL7
2024-07-31 10:34:12 +02:00
Alexander Aleksandrovič Klimov 6f28fea5bb
GHA: add openSUSE 15.6 and SLES 15.6 2024-07-01 13:29:01 +02:00
Alexander A. Klimov ba52e2ed51 GHA: drop EOL EL7 2024-07-01 12:44:43 +02:00
Alexander Aleksandrovič Klimov bca1a8447a
Merge pull request #10061 from Icinga/strip-cr-in-notification-messages-7510
Strip '\r' in notification messages to avoid 'Content-Type: application/octet-stream'
2024-06-14 11:51:02 +02:00