5542 Commits

Author SHA1 Message Date
Julian Brost
a2a5c3f28d InfluxdbWriter: only flush from work queue
There is no explicit synchronization of access to m_DataBuffer which is fine if
it is only accessed from the single-threaded work queue. However, Stop() also
called Flush() in another thread, leading to concurrent write access to
m_DataBuffer which can result in a crash due to use after free/double free.

Changes in this commit:
* Flush() is renamed to FlushWQ() to show that it should only be called from
  the work queue. Additionally, it now asserts that it is running on the work
  queue.
* Visibility of some data members is changed from protected to private. No
  other classes have to access these at the moment. By this change, accidental
  concurrent access from derived classes in the future is prevented.
* Stop() now flushes by posting FlushWQ() to the work queue and joining it.
2022-02-23 15:08:57 +01:00
Julian Brost
899e020fde LegacyTimePeriod: Prevent modification of input parameters
Many functions of LegacyTimePeriod take a tm pointer as an input parameter and
then pass it to mktime() which actually modifies it. This causes problems if
tm_isdst was intentionally set to -1 (to automatically detect whether DST is
active at some time) and then a function is called that implicitly sets
tm_isdst and then the values of tm are modified in a way that crosses a DST
change. This resulted in 1 hour offsets with ScheduledDowntimes on days with
DST changes.
2022-02-22 11:48:44 +01:00
Alexander Aleksandrovič Klimov
627fd91ac6 Service#GetSeverity(): behave as the respective IDO query of Icinga Web
which doesn't include host reachability.
2022-02-21 16:11:48 +01:00
Julian Brost
69f181f98e IDO: use per-instance notification_id in history
When there are multiple active IDO instances on the same node, before this
commit, all of them would share a single DbValue object for the notification_id
column of the icinga_contactnotifications table. This resulted in the issue
that one database references the notification_id in another database.

This commit fixes this by using a separate DbValue value for each IDO instance.
This needs a new signal as the existing OnQuery and OnMultipleQueries signals
perform the same queries on all IDO instances, but different queries are needed
here per instance (they only differ in the referenced DbValue). Therefore, a
new signal OnMakeQueries is added that takes a std::function which is called
once per IDO instance and can access callbacks to perform one or multiple
queries only on this specific IDO instance.
2022-02-21 16:03:14 +01:00
Julian Brost
485e287d28 Prevent deadlock in ProcessCheckResult
Without this commit, children and parents of a checkable were rescheduled on a
state change while holding the lock for the current checkable. If both ends of
a dependency are checked at the same time and both change state, they could end
up in a deadlock waiting for each other.

This commit fixes this problem by changing the code so that other checkables
are rescheduled only after releasing the lock for the current checkable.
2022-02-18 14:39:48 +01:00
Julian Brost
93461e9397
Merge pull request #9184 from Icinga/bugfix/downtime-all-services-on-child-hosts-212
Fix scheduling of downtimes for all services on child hosts
2022-01-21 18:03:32 +01:00
Julian Brost
9fc426e20e Don't trigger a fixed downtime like a flexible one
When creating a fixed downtime that starts immediately while the checkable is
in a non-OK state, previously the code path for flexible downtimes was used to
trigger this downtime. This is fixed by this commit which resolves two issued:

1. Missing downtime start notification: notifications work differently for
   fixed and flexible downtimes. This resulted in missing downtime start
   notifications under the conditions described above.
2. Incorrect downtime trigger time: this code path would incorrectly assume the
   timestamp of the last checkable as the trigger time which is incorrect for
   fixed downtimes.
2022-01-20 11:45:38 +01:00
Julian Brost
b9e2499148 Prevent duplicate donwtimes when combining child_options and all_services 2022-01-20 11:40:21 +01:00
Julian Brost
f298314216 Fix scheduling of downtimes for all services on child hosts
The loop iterated over the services of the wrong host resulting in duplicate
downtimes scheduled for services of the parent host instead of downtimes for
services of the child host.
2022-01-20 11:40:21 +01:00
Julian Brost
49cef4e907
Merge pull request #9125 from Icinga/bugfix/icinga2-crashes-when-sending-notifications-8186
Avoid "type" key in dicts being part of object state attrs
2022-01-19 15:49:02 +01:00
Alexander A. Klimov
e9e555468d Handle "type" key in dicts being part of object state attrs
i.e. the confusion of the state file deserializator with e.g. `"type":32` on startup.
That would unexpectedly restore (the now ignored) null (not `{"type":32}`) as there's no type "32".

refs #8186
2022-01-04 17:17:20 +01:00
Julian Brost
a379f6e08c Make MySQL schema version in full schema file and upgrade files consistent
In the 2.12.6 release, the full schema file sets the version to 1.14.3, whereas
the latest available upgrade file 2.11.0.sql sets it to 1.15.0. Therefore, ship
a new upgrade file 2.12.7.sql for all users who imported their schema with
version 2.11.0 or later and never performed an upgrade since then. Their
databases incorrectly state schema version 1.14.3 and is bumped to the correct
version 1.15.0 by the upgrade. Additionally, the version number in the full
schema is also bumped to the correct version 1.15.0.
2021-12-16 16:04:54 +01:00
Alexander A. Klimov
eb71fb7529 Avoid "type" key in dicts being part of object state attrs
not to confuse the state file deserializator with e.g. `"type":32` on startup.
That would unexpectedly restore null (not `{"type":32}`) as there's no type "32".

refs #8186
2021-12-13 17:56:12 +01:00
Julian Brost
b7dd909a30 GelfWriter: show error message of exceptions 2021-08-17 16:38:54 +02:00
Julian Brost
6db8795ca4 InfluxdbWriter: actually verify TLS server certificates
And add a new option ssl_insecure_noverify to explicitly disable it if desired.
2021-08-17 16:38:39 +02:00
Julian Brost
d7133ae429 GelfWriter: actually verify TLS server certificates
And add a new option insecure_noverify to explicitly disable it if desired.
2021-08-17 16:33:18 +02:00
Julian Brost
bf535969ac ElasticsearchWriter: actually verify TLS server certificates
And add a new option insecure_noverify to explicitly disable it if desired.
2021-08-17 16:33:18 +02:00
Julian Brost
8910abc588 Enable hostname verification in UnbufferedAsioTlsStream 2021-08-17 16:33:18 +02:00
Alexander A. Klimov
b5b83fa515 API: hide ApiListener#ticket_salt 2021-07-09 09:30:45 +02:00
Julian Brost
843353ab69 Remove passwords from API
IdoMysqlConnection, IdoPgsqlConnection, IcingaDB, and ElasticsearchWriter
require passwords in their configuration to authenticate against external
services. This commit ensures that these can no longer be accessed using the
API.
2021-07-09 09:05:05 +02:00
Julian Brost
289a872eaf
Merge pull request #8865 from Icinga/feature/improve-crashlog-212
Improve crashlog
2021-07-09 08:21:44 +02:00
Julian Brost
4a1e6528ea
Merge pull request #8889 from Icinga/bugfix/trigger-fixed-downtimes-immediately-212
Downtime#Start(): trigger fixed downtimes immediately instead of waiting for the timer
2021-07-08 15:33:11 +02:00
Julian Brost
d8ab328c33 Add comments to stack trace formatter and test case 2021-07-08 14:53:15 +02:00
Julian Brost
f5873a8e75 Use backtrace_symbols() when printing stack traces on FreeBSD
Unfortunately, the symbol resolution of boost::stacktrace is broken on
FreeBSD, therefore fall back to using backtrace_symbols() to print the
stack trace saved by Boost.

Additionally, -D_GNU_SOURCE is required on FreeBSD for the
_Unwind_Backtrace function used by boost::stacktrace.
2021-07-08 14:53:15 +02:00
Julian Brost
a2e5cfd34f Crash handlers: use more compact string representation 2021-07-08 14:53:15 +02:00
Julian Brost
2310cdb4fa Begin crash log for SIGABRT with error message and timestamp
This makes the format more similar to what the uncaught C++ and SEH
exception handlers write. Previously there was no indication in the
crash log that a SIGABRT happened.
2021-07-08 14:53:15 +02:00
Julian Brost
2330ab59f8 Add some comments to __cxa_throw
Maybe this will save the next person who has to look at this code some
time. Please don't blame me for the implementation, I'm just trying to
reconstruct what it does.
2021-07-08 14:53:15 +02:00
Julian Brost
9fcc781172 Restructure stack and context trace selection in DiagnosticInformation and document behavior
The logic for selecting the traces to print stays the same, but there
are fewer nested ifs now. This changes the format of the returned string
a bit by adding a heading for both traces.
2021-07-08 14:53:15 +02:00
Julian Brost
df59aa0087 Add documentation for cast_exception function 2021-07-08 14:53:15 +02:00
Julian Brost
996f280bfc Pass fallback stacktrace to DiagnosticInformation in terminate handler
By default, DiagnosticInformation uses the stack trace saved when the
exception was thrown, but this mechanism is not in use on Windows.
Gathering a stacktrace in the terminate handler serves as a fallback.
2021-07-08 14:53:15 +02:00
Julian Brost
8b2f4636db Replace icinga::StackTrace with boost::stacktrace::stacktrace
Provides roughly the same functionality but works better on certain
platforms (especially Windows) and is less code to maintain.
2021-07-08 14:53:15 +02:00
Julian Brost
4a29c39eba Print details in uncaught SEH exception handler 2021-07-08 14:53:15 +02:00
Julian Brost
8b67e4a637 Move error message and time to the beginning of the SEH crash log
This is more similar to the normal exception crashlog which also states
the problem and time at the beginning of the file.
2021-07-08 14:53:15 +02:00
Julian Brost
9ebd812da5 Use boost::stacktrace instead of custom implementation in Windows SEH filter 2021-07-08 14:53:15 +02:00
Julian Brost
b5017b78d7 Run termination handler for uncaught C++ exceptions on Windows
On Windows, the termination handler is executed for uncaught C++
exceptions unless a SEH unhandled exception filter is also set. In this
case, this filter has to explicitly chain the default filter to keep
this behavior.
2021-07-08 14:53:15 +02:00
Alexander Aleksandrovič Klimov
088860474c
Merge pull request #8877 from Icinga/bugfix/fixed-dt-end-notify-212
Checkable::NotifyDowntimeEnd(): don't send Downtime end notification unless triggered
2021-07-07 23:55:17 +02:00
Alexander A. Klimov
0cca93543c Checkable::NotifyDowntimeEnd(): don't send Downtime end notification unless triggered
... for fixed Downtimes as well.
2021-07-07 15:42:20 +02:00
Alexander A. Klimov
2bcd249efb On ScheduledDowntime change: remove future downtimes created before change
refs #8309
2021-07-07 15:42:18 +02:00
Alexander A. Klimov
c7ad5f6e2e On ScheduledDowntime change: ignore downtimes created before change
... while creating new downtimes.

refs #8309
2021-07-07 15:42:18 +02:00
Alexander A. Klimov
2dcba12765 Introduce Downtime#config_owner_hash
refs #8309
2021-07-07 15:42:18 +02:00
Alexander A. Klimov
c203716ff3 ScheduledDowntime: ignore not related Downtimes while creating Downtimes 2021-07-07 15:42:18 +02:00
Alexander A. Klimov
13d3d18a7f Downtime#Start(): trigger fixed downtimes immediately instead of waiting for the timer
... not to cause e.g. notifications if a problem occurs
between the downtime start time and the timer routine.
2021-07-07 15:31:46 +02:00
Noah Hilverling
7df2620bda
Merge pull request #8864 from Icinga/bugfix/downtime-for-host-service-with-long-name-8022-212
ConfigObjectUtility::GetObjectConfigPath(): hash names of not already existing objects
2021-07-07 10:39:52 +02:00
Noah Hilverling
4fb27a45cb
Merge pull request #8863 from Icinga/bugfix/harden-scheduled-downtimes-212
ScheduledDowntime::TimerProc(): Catch exceptions to make sure other downtimes are still created
2021-07-07 10:39:44 +02:00
Noah Hilverling
7e0eab3767 ScheduledDowntime::TimerProc(): Catch exceptions to make sure other downtimes are still created 2021-07-06 12:27:16 +02:00
Julian Brost
ecbaa5db67 Add timeout for all new connections
This commit adds a timeout for both establishing new outgoing and incoming
connections. This timeout applies to everything until the connection is in a
state where either JsonRpcConnection or HttpServerConnection takes over.
2021-07-06 11:32:41 +02:00
Julian Brost
97d70daa57 GetObjectConfigPath: only truncate and hash comment and downtime filenames
This partially reverts 68a0079c26686363b6202a8abd2712d2bf96d9f2 and keeps the
fix only for comment and downtime objects for now. For reasoning, please see
the comment in the code.
2021-07-05 16:18:57 +02:00
Julian Brost
eaee629047 GetObjectPath: ensure use of escaped name in all cases and use TruncateUsingHash()
68a0079c26686363b6202a8abd2712d2bf96d9f2 introduced two problems that are fixed
with this commit:
1. The new truncated/hashed name did not use EscapeName()
2. There was a possible collision of names when creating objects with a full
   name of format "[80 characters]...[40 hex digits]" (i.e. the same as the
   truncated/hashed variant but short enough that it isn't hashed)
2021-07-05 16:18:57 +02:00
Julian Brost
bdbe35b42d Utility: add a function to truncate strings while avoiding collisions 2021-07-05 16:18:57 +02:00
Alexander A. Klimov
3788f9170a ConfigObjectUtility::GetObjectConfigPath(): hash names of not already existing objects
... to avoid too long file names.

refs #8022
2021-07-05 16:18:57 +02:00