1195 Commits

Author SHA1 Message Date
Yonas Habteab
e3fa5f4ae5 HTTP: send http status accepted where appropriate
This better reflects the request handling, since the headers are sent
before the request is fully processed. This status code just indicates
that we successfully accepted the request but is not guaranteed that all
the subsequent actions will also be successful.
2025-09-16 14:04:57 +02:00
Yonas Habteab
e7c088b05b HTTP: stream responses where appropriate 2025-09-16 14:04:56 +02:00
Yonas Habteab
047f44a3b3 Remove thread-local AuthenticatedApiUser & pass it as param instead 2025-09-16 14:04:56 +02:00
Yonas Habteab
5ca244c72f Add SendJsonBody() overload for streaming HTTP response
This is similar to the already existing `HttpUtility::SendJsonBody()`
function but for streaming.
2025-09-16 14:04:56 +02:00
Yonas Habteab
ccf4eebc3d Make ValueGenerator more flexible & easy to use
This commit refactors the ValueGenerator class to be a template that can
work with any container type. Previously, one has to manually take care
of the used container by lazily iterating over it within a lambda. Now,
the `ValueGenerator` class itself takes care of all the iteration,
making it easier to use and less error-prone. The new base `Generator`
class is required to allow the `JsonEncoder` to handle generators in a
type-erased manner.
2025-09-16 14:04:56 +02:00
Yonas Habteab
5f862ce3bb HttpServerConnection: use std::chrono for m_Seen 2025-09-12 13:40:36 +02:00
Yonas Habteab
97ad0fc552 Make HTTP livness timout configurable for unittests
It's annoying to have to wait 10 seconds for the `liveness_disconnect`
test to complete, so make the timeout configurable and set it to a way
lower value to test the functionality.
2025-09-12 12:54:18 +02:00
Julian Brost
87df80d322
Merge pull request #10516 from Icinga/http-handlers-stream-refactor
Refactor HTTP connection handling and some handlers to stream responses
2025-08-29 11:33:34 +02:00
Johannes Schmidt
4782ea8a75 Make inherited protected functions of ApiListener public
This is needed so it's possible to manually add an ApiListener object
for the purpose of unit-testing.
2025-08-28 13:22:18 +02:00
Johannes Schmidt
bb75d73012 Refactor ObjectQueryHandler to use new JSON stream encoder 2025-08-28 13:22:18 +02:00
Johannes Schmidt
62b2dadbac Remove extra parameters from HTTP handler signature
These parameters are no longer needed since they were only used
by EventsHandler which was refactored in an earlier commit.
2025-08-28 13:22:18 +02:00
Johannes Schmidt
d32f04a863 Refactor EventsHandler to stream responses via chunked encoding 2025-08-28 13:22:18 +02:00
Johannes Schmidt
3832bb4296 Use new HTTP message classes in HttpServerConnection and Handlers 2025-08-28 13:22:18 +02:00
Johannes Schmidt
37df843700 Add HttpRequest and HttpResponse classes 2025-08-28 13:22:15 +02:00
Alexander Aleksandrovič Klimov
9905e9af32
Merge pull request #10389 from Icinga/zone-endpoint-order
Zone#GetEndpoints(): return endpoints in the specified order, not randomly🎲
2025-08-22 10:11:51 +02:00
Alexander Aleksandrovič Klimov
5f2ee6e119
Merge pull request #10393 from Icinga/zone-endpoint-log
ApiListener#RelayMessageOne(): log🪵 to which Endpoint messages are relayed
2025-08-22 10:11:25 +02:00
Alexander A. Klimov
17b49bd5b6 ApiListener#RelayMessageOne(): log to which Endpoint messages are relayed
if they're for our parent Zone.
2025-08-15 11:03:55 +02:00
Yonas Habteab
ce3275d27f Disallow stage deletions during reload
Once the new worker process has read the config, it also includes a
`include */include.conf` statement within the config packages root
directory, and from there on we must not allow to delete any stage
directory from the config package. Otherwise, when the worker actually
evaluates that include statement, it will fail to find the directory
where the include file is located, or the `active.conf` file, which is
included from each stage's `include.conf` file, thus causing the worker
fail.

Co-Authored-By: Johannes Schmidt <johannes.schmidt@icinga.com>
2025-07-24 16:02:30 +02:00
Yonas Habteab
1ac4d83963 Use AtomicFile where applicable in ConfigPackageUtility 2025-07-24 10:54:39 +02:00
Yonas Habteab
35f42fa5a3 Handle concurrent config package updates gracefully
Previously, we used a simple boolean to track the state of the package updates,
and didn't reset it back when the config validation was successful because it was
assumed that if we successfully validated the config beforehand, then the worker
would also successfully reload the config afterwards, and that the old worker would
be terminated. However, this assumption is not always true due to a number of reasons
that I can't even think of right now, but the most obvious one is that after we successfully
validated the config, the config  might have changed again before the worker was able
to reload it. If that happens, then the new worker might fail to successfully validate
the config due to the recent changes, in which case the old worker would remain active,
and this flag would still be set to true, causing any subsequent requests to fail with a
`423` until you manually restart the Icinga 2 service.

So, in order to prevent such a situation, we are additionally tracking the last time a reload
failed and allow to bypass the `m_RunningPackageUpdates` flag only if the last reload failed
time was changed since the previous request.
2025-07-24 10:54:39 +02:00
Julian Brost
827f85c327
Merge pull request #10387 from Icinga/cnt-msg
Introduce Endpoint#messages_received_per_type
2025-07-16 17:29:24 +02:00
Johannes Schmidt
82bb636d2b Use WaitGroup to wait for or abort HTTP requests
The wait group gets passed to HttpServerConnection, then down to the
HttpHandlers. For those handlers that modify the program state, the
wait group is locked so ApiListener will wait on Stop() for the
request to complete. If the request iterates over config objects,
a further check on the state of the wait group is added to abort early
and not delay program shutdown. In that case, 503 responses will be
sent to the client.

Additionally, in HttpServerConnection, no further requests than the
one already started will be allowed once the wait group is joining.
2025-06-13 14:48:15 +02:00
Johannes Schmidt
33777f6f3f Disconnect JSON-RPC clients on ApiListner::Stop() 2025-06-13 14:48:15 +02:00
Johannes Schmidt
00802ed9fa Stop ApiListener::ListenerCoroutineProc() when Stop() is called 2025-06-13 14:48:11 +02:00
Julian Brost
4e08adc532
Merge pull request #10161 from Icinga/authBYhost-10157
ApiListener::UpdateObjectAuthority(): distribute auth. by object's host
2025-06-06 15:03:32 +02:00
Yonas Habteab
3d04eb456a
Merge pull request #10415 from Icinga/abort-no-endpoint-conns
Abort connections with no valid endpoint
2025-06-02 16:21:46 +02:00
Julian Brost
c253e7eb6e
Merge pull request #10397 from Icinga/activation-priority-10179
Checkable#ProcessCheckResult(): discard🗑️ CR or delay its producers shutdown
2025-05-28 12:30:40 +02:00
Alexander A. Klimov
f4691dd054 Require to pass WaitGroup::Ptr to several methods
Namely:

Checkable#ProcessCheckResult()
ClusterCheckTask::ScriptFunc()
ClusterZoneCheckTask::ScriptFunc()
DummyCheckTask::ScriptFunc()
ExceptionCheckTask::ScriptFunc()
IcingaCheckTask::ScriptFunc()
IfwApiCheckTask::ScriptFunc()
NullCheckTask::ScriptFunc()
PluginCheckTask::ScriptFunc()
RandomCheckTask::ScriptFunc()
SleepCheckTask::ScriptFunc()
IdoCheckTask::ScriptFunc()
IcingadbCheck::ScriptFunc()
CheckCommand#Execute()
Checkable#ExecuteCheck()
ClusterEvents::ExecuteCheckFromQueue()
ExternalCommandProcessor::Process*CheckResult()
ExternalCommandCallback
ExternalCommandProcessor::Execute()
ExternalCommandProcessor::ExecuteFromFile()
ExternalCommandProcessor::ProcessFile()
LivestatusQuery#ExecuteCommandHelper()
LivestatusQuery#Execute()
2025-05-23 14:53:58 +02:00
Alexander A. Klimov
c7cca7b460 Add a StoppableWaitGroup, and join it on #Stop(), to:
ApiListener
CheckerComponent
ExternalCommandListener
LivestatusListener
2025-05-23 14:53:58 +02:00
Alexander A. Klimov
77b86bba52 Move l_MyCapabilities -> ApiCapabilities::MyCapabilities 2025-05-23 10:44:16 +02:00
Alexander A. Klimov
6cd83ba2b8 ApiListener::UpdateObjectAuthority(): distribute auth. by object's host
Pin child objects of hosts (HOST!...) to the same endpoint as the host.
This reduces cross-object action latency withing the same host.
If all endpoints know this algorithm, we can use it.
2025-05-23 10:44:16 +02:00
Alexander A. Klimov
18f810a1ea For the same zone, call ApiListener::UpdateObjectAuthority() in icinga::Hello
after setting remote capabilities. They'll become important for teamwork in a zone.
2025-05-22 15:01:06 +02:00
Alexander Aleksandrovič Klimov
ec2080dcc1
Merge pull request #9731 from Icinga/fix-compiler-warnings-by-copy-constructing-loop-variables-explicitly
Fix compiler warnings by (copy-)constructing loop variables explicitly or not at all
2025-05-21 14:26:47 +02:00
Alexander A. Klimov
22e75f08fa Fix compiler warnings by not unnecessarily (copy-)constructing loop variables 2025-05-21 11:36:32 +02:00
Alexander A. Klimov
98d097517b Introduce Endpoint#messages_received_per_type 2025-04-29 11:42:14 +02:00
Alexander A. Klimov
3dd7b15808 Count incoming messages per type and endpoint 2025-04-29 11:42:14 +02:00
Alexander A. Klimov
c566f6dc31 ApiFunction: store own name 2025-04-29 11:42:14 +02:00
Alexander A. Klimov
331ba1f661 Rename AsioConditionVariable to AsioEvent
The current implementation is rather similar to Python's threading.Event, than to a CV.
2025-04-29 11:39:42 +02:00
Johannes Schmidt
353386f404 Abort verified JSON-RPC connections with no valid endpoint 2025-04-23 16:55:16 +02:00
Yonas Habteab
1da497be89 Fix inverted IsHACluster check 2025-04-23 15:18:06 +02:00
Alexander A. Klimov
c2ddd20ef3 Fix compiler warnings by (copy-)constructing loop variables explicitly
for (const T& needle : haystack) creates the illusion that haystack is a
container of T and we're just borrowing needle. In these cases that's not true.
2025-04-22 13:55:49 +02:00
Julian Brost
ccfc72267f Prefer icinga::String::GetData() over icinga::String::CStr()
Creating the string_view from the std::string (as returned by GetData()) uses
the stored length instead of having to detect it by finding '\0'.
2025-04-14 17:30:19 +02:00
Alexander Aleksandrovič Klimov
011c67964e Don't use boost::asio::io_context::strand method removed in Boost 1.87 2025-04-14 17:30:19 +02:00
Alexander Aleksandrovič Klimov
7bd35d8c6b Don't use boost::asio::ip::tcp::resolver::query
It was removed in Boost 1.87.
2025-04-14 17:30:19 +02:00
Alexander A. Klimov
a943c4588b Zone#GetEndpoints(): return endpoints in the specified order, not randomly
ApiListener#RelayMessageOne() relays every given message to the first connected endpoint Zone#GetEndpoints() returns. Randomness in combination with bad luck can direct more traffic (from a particular network segment) to one master than the admin wants.

This change lets the Zone#endpoints order prefer one endpoint over the other.
2025-03-25 13:04:41 +01:00
Alexander A. Klimov
402a6bbf40 Remove unused EventQueue::Unregister() 2025-03-18 11:22:56 +01:00
Alexander A. Klimov
d19c0637ee Remove unused EventQueue::UnregisterIfUnused() 2025-03-18 11:22:56 +01:00
Alexander A. Klimov
41f61ccba4 Remove unused ApiFunction::Unregister() 2025-03-18 11:22:56 +01:00
Alexander A. Klimov
cce03c5903 Remove unused ApiAction::Unregister() 2025-03-18 11:22:56 +01:00
Yonas Habteab
fa63fda75b ApiListener: Simplify deferred SSL shutdown in NewClientHandlerInternal() 2025-03-13 12:12:28 +01:00