13691 Commits

Author SHA1 Message Date
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
Alexander A. Klimov
449e5c026d GHA: drop EOL EL7 2024-08-06 10:59:34 +02:00
Alexander Aleksandrovič Klimov
6a7b440cfd
Merge pull request #10084 from Icinga/win2143
Bump Windows deps
2024-06-12 13:03:05 +02:00
Alexander A. Klimov
d856cab9d9 Bump OpenSSL shipped for Windows to v3.0.14 2024-06-12 10:25:11 +02:00
Alexander A. Klimov
3a3454e1b5 Bump Boost shipped for Windows to v1.85
Note: For doc/21-development.md use:

perl -pi -e 's/(boost[-\w]*?1[-_]?)84/${1}85/g' doc/21-development.md
2024-06-12 10:25:11 +02:00
Alexander Aleksandrovič Klimov
62a92c10b5
Merge pull request #10075 from Icinga/gha2143
Update GitHub actions
2024-06-10 10:59:37 +02:00
Alexander Aleksandrovič Klimov
39be31c305 CMakeLists.txt: set(CPACK_WIX_INSTALL_SCOPE NONE)
to stick to CMake pre-v3.29 behavior. CMake v3.29 introduces CPACK_WIX_INSTALL_SCOPE. Its default conflicts with the ALLUSERS property in our icinga-installer/icinga2.wixpatch.cmake.
2024-06-07 15:50:54 +02:00
Alexander Aleksandrovič Klimov
8b6c73166c GHA: Docker: don't run on support/* branches
PRs to them are already covered and we don't need support* image tags.
2024-06-07 15:49:10 +02:00
Alexander Aleksandrovič Klimov
469bc7e9fd GHA: drop Debian 10
which will be EOL in 2.5 months.
2024-06-07 15:49:10 +02:00
Alexander Aleksandrovič Klimov
00d77443a0 GHA: add upcoming Fedora 40 2024-06-07 15:49:10 +02:00
Alexander Aleksandrovič Klimov
a00e57c06b GHA: add upcoming Ubuntu 24.04 2024-06-07 15:49:10 +02:00
Alexander A. Klimov
6ba41b01e4 GHA AUTHORS check: handle PRs from forks
where the ref names differ compared to own PRs. Instead refer to the base branch and the head branch via generic HEAD^<parent number> where HEAD is a merge commit.
2024-06-07 15:49:10 +02:00
Alexander Aleksandrovič Klimov
fc4ff8b7af
Merge pull request #9971 from Icinga/2142
Icinga 2.14.2
v2.14.2
2024-01-17 19:49:18 +01:00
Alexander Aleksandrovič Klimov
d6a2528af5
Merge pull request #9970 from Icinga/2142backport
Log HTTP request processing time and ship Boost 1.84 on Windows
2024-01-17 19:11:54 +01:00
Alexander Aleksandrovič Klimov
37d9ae752f
Merge pull request #9969 from Icinga/influx-disk-9948-214
Influx DB: truncate timestamps to whole seconds to save disk space
2024-01-17 19:04:39 +01:00
Alexander A. Klimov
5bb2024976 Icinga 2.14.2 2024-01-17 17:53:00 +01:00
Alexander A. Klimov
fd5f3c57d9 Bump Boost shipped for Windows to v1.84
Note: For doc/21-development.md use:

perl -pi -e 's/(boost[-\w]*?1[-_]?)83/${1}84/g' doc/21-development.md

(cherry picked from commit 77313d751c8ae78f0114f62c248455bfadf47041)
2024-01-17 17:11:10 +01:00
Alexander A. Klimov
6817a148bd HttpServerConnection: log request processing time as well
(cherry picked from commit b6874cc8d40336fbc9eb6c60e9d1be9313365a58)
2024-01-17 17:11:10 +01:00
Alexander A. Klimov
3a274ac305 Revert "Influx DB: don't unneccessarily truncate timestamps to whole seconds"
This reverts commit eaa3cd83adf860732b955a77b8f5fca7e30c65c2.

(cherry picked from commit cc9db3756fa68b303c13258cbb1500d691b1b770)
2024-01-17 17:07:13 +01:00
Alexander A. Klimov
1b5bc20e50 Revert "Remove no-op InfluxDB URL param"
This reverts commit 21f548d3c07189c6a413cf88c2b60cc9ada73497.

(cherry picked from commit fc5b1178c643d37dfa1ce8512966b95961bac18f)
2024-01-17 17:07:13 +01:00
Alexander Aleksandrovič Klimov
f2c83fbbf2
Merge pull request #9950 from Icinga/probot/sync-changelog/support/2.14/9fa41f3b4fbae83d4ca5bbfce4771031b6bd1fa4
CHANGELOG.md: add v2.13.9
v2.14.1
2023-12-20 17:30:01 +01:00
Alexander A. Klimov
b85cd98eb1 CHANGELOG.md: add v2.13.9 2023-12-20 16:27:56 +00:00
Alexander Aleksandrovič Klimov
9fa41f3b4f
Merge pull request #9940 from Icinga/2141
Icinga 2.14.1
2023-12-20 17:27:43 +01:00
Alexander Aleksandrovič Klimov
61d190f892
Merge pull request #9947 from Icinga/2141morebackport
Truncate too big notification command lines, fix GelfWriter deadlock and return 503 in /v1/console/* during reload
2023-12-20 12:44:07 +01:00
Alexander Aleksandrovič Klimov
3ddbbebc63
Merge pull request #9946 from Icinga/2141backport
Disable TLS renegotiation, bump Windows deps and fix Icinga DB crashes
2023-12-20 12:40:41 +01:00
Alexander A. Klimov
41b692793b Icinga 2.14.1 2023-12-20 10:56:15 +01:00
Alexander A. Klimov
fecb209fe0 GelfWriter: protect m_Stream via m_WorkQueue, not ObjectLock(this)
On shutdown or HA re-connect ConfigObject#SetAuthority(false) is called which
does ObjectLock(this) and ConfigObject#Pause(). GelfWriter#Pause(), with the
above ObjectLock, calls m_WorkQueue.Join(). But items inside that also doing
ObjectLock(this) cause a deadlock.
2023-12-20 10:46:51 +01:00
Mattia Codato
85c5a7c901 Prevent calls to command API while the configuration is reloading.
Fixes #9840
2023-12-20 10:46:51 +01:00
Alexander A. Klimov
0eeac3b385 PluginNotificationTask::ScriptFunc(): on Linux truncate output and comment
not to run into an exec(3) error E2BIG due to a too long argument.
This sends a notification with truncated output instead of not sending.
2023-12-20 10:46:51 +01:00
Alexander A. Klimov
7efdae6a53 IcingaDB#SendConfigDelete(): fix missing nullptr check before deref 2023-12-20 10:30:01 +01:00