13828 Commits

Author SHA1 Message Date
Yonas Habteab
c9aba3375b
Merge pull request #10119 from Icinga/2.14Boost1.86
Bump Boost shipped for Windows to v1.86
2024-09-17 15:20:05 +02:00
Yonas Habteab
06b01cb574
Merge pull request #10125 from Icinga/output-exit-code-2.14
Mention plugin exit codes outside [0..3] in the plugin output and warning log
2024-09-17 15:18:27 +02:00
Yonas Habteab
7a04966e78
Merge pull request #10131 from Icinga/heavy-update-missing-table-relations-2.14
Update object#config_hash after all relations queries
2024-09-17 15:14:28 +02:00
Alexander Aleksandrovič Klimov
9c50fa5d94
Merge pull request #10132 from Icinga/strip-cr-in-notification-messages-2.14
Strip '\r' in notification messages to avoid 'Content-Type: application/octet-stream'
2024-09-17 15:14:00 +02:00
Yonas Habteab
cad41fa76a
Merge pull request #10129 from Icinga/malloc_info-2.14
/v1/debug/malloc_info: call malloc_info(3) if available
2024-09-17 15:13:47 +02:00
Yonas Habteab
64d5778954
Merge pull request #10130 from Icinga/timeperiod-nth-day-of-month-off-by-one-2.14
Timeperiods: fix off by one when calculating n-th last weekday of the…
2024-09-17 15:10:46 +02:00
Yonas Habteab
ad7495dc0e Don't fail to remove obsolete downtimes 2024-09-17 15:06:45 +02:00
Yonas Habteab
6347c9089d Don't loose args in recursive Downtime::RemoveDowntime() call 2024-09-17 15:06:45 +02:00
Yonas Habteab
088f4e0f48 Introduce & use enum DowntimeRemovalReason 2024-09-17 15:06:45 +02:00
Alexander A. Klimov
d7a590e3ef Remove unused Checkable#RemoveAllDowntimes() 2024-09-17 15:06:45 +02:00
Alexander A. Klimov
b09517e876 Bump Boost shipped for Windows to v1.86 2024-09-17 12:33:47 +02:00
Yonas Habteab
b70f4da208 Don't allow to modify/create/delete an object concurrently 2024-09-17 12:33:35 +02:00
Yonas Habteab
395a1398f6 ConfigObjectUtility#CreateObject(): Use Defer for config path cleanup 2024-09-17 12:33:35 +02:00
Yonas Habteab
42891028ca ApiListener: Process cluster config updates sequentially 2024-09-17 12:33:35 +02:00
Yonas Habteab
3d5e0fef69 Introduce RAII style ObjectNameLock class 2024-09-17 12:33:35 +02:00
Yonas Habteab
cf11fe0177 ConfigObjectUtility: Use AtomicFile to store object config files 2024-09-17 12:33:35 +02:00
Yonas Habteab
5f9868d97a Add advanced timeperiod range,include/exclude test cases 2024-09-17 12:33:27 +02:00
Yonas Habteab
b48dcc9f77 tests: Add some basic tests cases for LegacyTimePeriod::IsInTimeRange() 2024-09-17 12:33:27 +02:00
Yonas Habteab
574cbb4b4e Check segemnt start date inclusively in TimePeriod::IsInside() 2024-09-17 12:33:27 +02:00
Yonas Habteab
ed16377349 Fix broken timeperiods/scheduleddowntimes 2024-09-17 12:33:27 +02:00
Alexander A. Klimov
b3c914242c l_LegacyDowntimesCache: delete removed objects not to leak memory 2024-09-17 12:33:16 +02:00
Alexander A. Klimov
58a10ad312 /v1/actions/schedule-downtime: reject request on invalid trigger_name
For this purpose lookup the specified Downtime. Also pass Downtime objects,
not just names, to Downtime::AddDowntime() not to lookup it twice.
2024-09-17 12:33:16 +02:00
Alexander A. Klimov
a3dd32e6e5 [Refactor] Downtime::GetDowntimeIDFromLegacyID(): return the Downtime itself
not just its name.
2024-09-17 12:33:16 +02:00
Alexander A. Klimov
9cf585b625 [Refactor] l_LegacyDowntimesCache: store Downtime objects, not just their names
to avoid names of vanished objects.
2024-09-17 12:33:16 +02:00
Alexander A. Klimov
1446139125 PluginCheckTask::ProcessFinishedHandler(): warn about exit codes outside 0..3
in the plugin output as well, in addition to the warning log.
2024-09-17 12:33:01 +02:00
Alexander A. Klimov
0605577d4d Make ProcessResult#ExitStatus and CheckResult#exit_status 64-bit ints
so that they can hold Windows exit codes like 3221225477 (>2147483647).
2024-09-17 12:33:01 +02:00
Alexander A. Klimov
2722deb6aa /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-09-17 12:32:52 +02:00
Julian Brost
3247e83957 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-09-17 12:32:10 +02:00
Yonas Habteab
36e8c9c8fd Update object#config_hash after all relations queries 2024-09-17 12:31:38 +02:00
Robert Scheck
bde4257793 Strip '\r' in notification messages to avoid 'Content-Type: application/octet-stream'
Without this patch, an accidential `\r` in e.g. `$NOTIFICATIONCOMMENT`
leads to a `Content-Type: application/octet-stream` header in e-mails.
The accidential `\r` might slip in usually using Icinga/Nagios apps...
2024-09-17 12:29:56 +02:00
Yonas Habteab
31c42dc2ca
Merge pull request #10145 from Icinga/formatdatetime-2.14
Overhaul Utility::FormatDateTime()
2024-09-16 12:41:57 +02:00
Yonas Habteab
27a4a25c9f
Merge pull request #10146 from Icinga/JsonRpcConnection-2.14
JsonRpcConnection#Send*(): discard messages ASAP once shutting down
2024-09-16 11:59:19 +02:00
Yonas Habteab
96839d829b ApiListener: Reorder logging in ApiTimerHandler() 2024-09-03 16:49:02 +02:00
Yonas Habteab
b9b3e7a925 ApiListener: Catch & supress clients runtime errors 2024-09-03 16:49:02 +02:00
Yonas Habteab
561aedab1d JsonRpcConnection: Raise an exception when trying to send to disconnected clients 2024-09-03 16:49:02 +02:00
Julian Brost
02334c5f29 Make sure log file is reopened when ApiListener::ReplayLog() returns 2024-09-03 16:49:02 +02:00
Yonas Habteab
b0b41b1aff Defer: Allow empty initialization & add SetFunc() method 2024-09-03 16:49:01 +02:00
Yonas Habteab
5f2d31bf3c Use Defer class for cleanup in ApiListener::ReplayLog() 2024-09-03 16:49:01 +02:00
Alexander A. Klimov
9a0c7d7c75 ApiListener#ReplayLog(): stop reading files ASAP on send error 2024-09-03 16:49:01 +02:00
Alexander A. Klimov
a6946f9dbf 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-09-03 16:49:01 +02:00
Alexander A. Klimov
81da1cdb26 JsonRpcConnection#Disconnect(): spawn coroutine only if necessary
by checking the now atomic #m_ShuttingDown outside of it.
2024-09-03 16:49:01 +02:00
Julian Brost
a24a43e4d0 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-09-03 15:26:51 +02:00
Julian Brost
542b02621c 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-09-03 15:26:51 +02:00
Julian Brost
6887ac6970 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-09-03 15:26:51 +02:00
Julian Brost
541fd41799 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-09-03 15:26:51 +02:00
Julian Brost
1bc0648b3c 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-09-03 15:26:51 +02:00
Julian Brost
46f1bd5846 Add tests for Utility::FormatDateTime() 2024-09-03 15:26:51 +02:00
Yonas Habteab
eec1d242c3
Merge pull request #10108 from Icinga/gha2143
Update GitHub actions
2024-09-03 14:56:38 +02:00
Alvar Penning
7cbf2e1c2c 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 7665143afa500dd589546665124293b9c1206265,
but I have not found any reasoning for the flag in particular.
2024-08-06 11:30:03 +02:00
Alexander Aleksandrovič Klimov
b68580338b GHA: add openSUSE 15.6 and SLES 15.6 2024-08-06 10:59:34 +02:00