1483 Commits

Author SHA1 Message Date
Julian Brost
33a52d8655 Replace EventuallyAtomic with AtomicOrLocked which falls back to a mutex
Apparently there was a reason for making the members of generated classes
atomic. However, this was only done for some types, others were still accessed
using non-atomic operations. For members of type T::Ptr (i.e.  intrusive_ptr<T>),
this can result in a double free when multiple threads access the same variable
and at least one of them writes to the variable.

This commit makes use of std::atomic<T> for more T (it removes the additional
constraint sizeof(T) <= sizeof(void*)) and uses a type including a mutex for
load and store operations as a fallback.
2022-06-14 12:23:04 +02:00
Alexander A. Klimov
dba78f73da mkclass: make .ti class members atomic if possible
... not to have to lock the objects while setting attributes.
2022-06-14 12:23:04 +02:00
Julian Brost
d281107f33 Fix mixed up arguments for Downtime::RemoveDowntime()
PR #8879 backported a call to that function as is without considering the
different signature of that function between 2.12 and 2.13+.

master:
  static void RemoveDowntime(
    const String& id,      // downtime->GetName()
    bool includeChildren,  // false
    bool cancelled,        // true
    bool expired = false,
    const String& removedBy = "",
    const MessageOrigin::Ptr& origin = nullptr
  );

support/2.12 without this commit:
  static void RemoveDowntime(
    const String& id,      // downtime->GetName()
    bool cancelled,        // false
    bool expired = false,  // true
    const MessageOrigin::Ptr& origin = nullptr
  );

support/2.12 with this commit:
  static void RemoveDowntime(
    const String& id,  // downtime->GetName()
    bool cancelled,    // true
    bool expired = false,
    const MessageOrigin::Ptr& origin = nullptr
  );
2022-04-19 17:32:56 +02:00
Julian Brost
15f71f434a Fix mixed up arguments for Downtime::AddDowntime()
PR #9184 backported a call to that function as is without considering the
different signature of that function between 2.12 and 2.13+.

master:
  static Ptr AddDowntime(
    const intrusive_ptr<Checkable>& checkable,   // childService
    const String& author,                        // author
    const String& comment,                       // comment
    double startTime,                            // startTime
    double endTime,                              // endTime
    bool fixed,                                  // fixed
    const String& triggeredBy,                   // triggerName
    double duration,                             // duration
    const String& scheduledDowntime = String(),  // String()
    const String& scheduledBy = String(),        // String()
    const String& parent = String(),             // childDowntimeName
    const String& id = String(),
    const MessageOrigin::Ptr& origin = nullptr
  );

support/2.12 without this commit:
  static Ptr AddDowntime(
    const intrusive_ptr<Checkable>& checkable,   // childService
    const String& author,                        // author
    const String& comment,                       // comment
    double startTime,                            // startTime
    double endTime,                              // endTime
    bool fixed,                                  // fixed
    const String& triggeredBy,                   // triggerName
    double duration,                             // duration
    const String& scheduledDowntime = String(),  // String()
    const String& scheduledBy = String(),        // String()
    const String& id = String(),                 // childService
    const MessageOrigin::Ptr& origin = nullptr
  );

support/2.12 with this commit:
  static Ptr AddDowntime(
    const intrusive_ptr<Checkable>& checkable,   // childService
    const String& author,                        // author
    const String& comment,                       // comment
    double startTime,                            // startTime
    double endTime,                              // endTime
    bool fixed,                                  // fixed
    const String& triggeredBy,                   // triggerName
    double duration,                             // duration
    const String& scheduledDowntime = String(),
    const String& scheduledBy = String(),
    const String& id = String(),
    const MessageOrigin::Ptr& origin = nullptr
  );
2022-04-19 17:18:06 +02:00
Julian Brost
77aec49667
Revert "Service#GetSeverity(): behave as the respective IDO query of Icinga Web" 2022-04-01 15:06:47 +02:00
Julian Brost
5d2625c711
Merge pull request #9294 from Icinga/bugfix/override-default-template-apply-rules-7914
Apply rules: import default templates first
2022-03-29 16:03:46 +02:00
Alexander A. Klimov
07cd15f48f Apply rules: import default templates first
... to allow to override the attributes they set.

refs #7914
2022-03-24 14:04:58 +01:00
Julian Brost
77eed19482
Merge pull request #9246 from Icinga/bugfix/timeperiod-dst-2.0-212
LegacyTimePeriod::ScriptFunc: fix DST edge-cases
2022-03-08 15:28:20 +01:00
Julian Brost
9dcd2da9b3
Merge pull request #9229 from Icinga/bugfix/processcheckresult-dependency-deadlock-2.12
Prevent deadlock in ProcessCheckResult
2022-03-07 11:15:11 +01:00
Julian Brost
93217de515 LegacyTimePeriod::ScriptFunc: fix DST edge-cases
This change fixes two problems:
* The internal functions used by ScriptFunc more or less expect to operate on
  full days, but ScriptFunc may have called them with some random timestamp
  during the day. This is fixed by always using midnight of the day as
  reference time.
* Previously, the code advanced a timestamp to the next day by adding 24 hours.
  On days with DST changes, this could either still be on the same day (a day
  may have 25 hours) or skip an entire day (a day may have 23 hours). This is
  fixed by using a struct tm to advance the time to the next day.
2022-03-07 09:42:21 +01:00
Julian Brost
9e0459e5e1
Merge pull request #9245 from Icinga/bugfix/adjust-behavior-of-service-get-severity-212
Service#GetSeverity(): behave as the respective IDO query of Icinga Web
2022-03-07 09:24:13 +01:00
Julian Brost
489660fb27
Merge pull request #9261 from Icinga/bugfix/event-handler-spamming-8704-212
Checkable#ExecuteEventHandler(): don't outsource event command run twice
2022-02-25 16:52:50 +01:00
Alexander A. Klimov
74935dad7b Checkable#ExecuteEventHandler(): don't outsource event command run twice
refs #8704
2022-02-24 14:03: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
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
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
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
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
7e0eab3767 ScheduledDowntime::TimerProc(): Catch exceptions to make sure other downtimes are still created 2021-07-06 12:27:16 +02:00
Alexander Aleksandrovič Klimov
8f0b7910b9
Merge pull request #8775 from Icinga/bugfix/problem-notification-at-downtime-end-2.12
Send problem notifications after downtime end for checkables in child zones (2.12)
2021-05-26 11:04:56 +02:00
Alexander Aleksandrovič Klimov
bb4356cc83
Merge pull request #8782 from Icinga/bugfix/concurent-notification-send-and-delete-2.12
Fix crash when notifications are sent while the notification object is deleted (2.12)
2021-05-26 11:01:55 +02:00
Julian Brost
35c9c656a0 AddDowntime: return Downtime::Ptr instead of String containing the name
At numerous places in the code, something like this is performed:

    String name = Downtime::AddDowntime(...);
    Downtime::Ptr downtime = Downtime::GetByName(name);

However, `downtime` can be a `nullptr` after this as it is possible that
the downtime is deleted in between.

This commit changes the return type of `Downtime::AddDowntime` to return
a Downtime::Ptr instead of the full name of the downtime. `AddDowntime`
performs the very same `GetByName()` operation internally, but handles
the `nullptr` case correctly and throws an exception.
2021-05-25 15:59:55 +02:00
Julian Brost
0cef85cf83 Properly handle service downtime referencing a deleted host
Only two out of three cases were handled properly by the code: host
downtimes referencing a deleted host and service downtimes referencing a
deleted service worked fine. However, if a service downtime references a
deleted host, `Host::GetByName()` returns `nullptr` which isn't
accounted for. Use `Service::GetByNamePair()` instead as this performs a
check for the host being null internally.
2021-05-25 15:59:55 +02:00
Julian Brost
30b7a1e65b Use reference-counted pointer in notification callback
`this` could be deleted after `Notification::BeginExecuteNotification`
exited and before `Notification::ExecuteNotificationHelper` finished.
This is fixed by constructing a `Notification::Ptr` and operate on that
one as it is properly reference-counted.
2021-05-25 15:59:29 +02:00
Julian Brost
ddafaa0add Only handle event::SetSuppressed{Notifications,NotificationTypes} within the local zone
Note that even when passing `nullptr` as target zone to `RelayMessage()`, the
cluster message will still be sent to the parent zone. These incoming messages
will now be rejected by the parent nodes. At the moment, there's no way to only
send within the local zone.
2021-05-25 15:58:17 +02:00
Alexander Aleksandrovič Klimov
2ed72c0947
Merge pull request #8506 from Icinga/bugfix/children-recover-too-late
On recovery: re-check children
2020-12-11 15:41:49 +01:00
Alexander A. Klimov
854939a8ce On recovery: re-check children 2020-12-02 12:24:40 +01:00
Alexander A. Klimov
668bf06424 Don't fire suppressed notifications if last parent recovery >= last check result 2020-12-02 12:03:19 +01:00
Noah Hilverling
7a7726c20f
Merge pull request #8174 from Icinga/bugfix/7567
Revert "MacroProcessor::ResolveArguments(): skip null argument values"
2020-09-21 13:59:10 +02:00
Noah Hilverling
cde3db70d1
Merge pull request #8228 from Icinga/bugfix/downtime-checkable-getname
Check !!downtime->GetCheckable() before downtime->GetCheckable()->GetName()
2020-09-14 09:38:28 +02:00
Alexander A. Klimov
8b0ba2275a Check !!downtime->GetCheckable() before downtime->GetCheckable()->GetName()
... not to crash while removing a downtime from a disappeared checkable.
2020-09-11 14:47:46 +02:00
Alexander A. Klimov
ade891bbf5 Revert "MacroProcessor::ResolveArguments(): skip null argument values"
This reverts commit e4bdcedbca069cb9d42c40ce6ce8054ed3ee1b58.
2020-08-13 10:39:55 +02:00
Noah Hilverling
ddf1e50d93 ProcessCheckResult(): Make sure hosts aren't locked during Service::GetSeverity() 2020-08-11 15:24:54 +02:00
Eric Lippmann
e8745f7e96
Merge pull request #7816 from Icinga/feature/notification-timeperiod-6167
Re-send notifications previously suppressed by their time periods
2020-08-03 10:04:27 +02:00
Alexander A. Klimov
c515822649 Re-send notifications previously suppressed by their time periods
refs #6167
2020-07-29 17:13:41 +02:00
Alexander A. Klimov
37c2c7ba90 Checkable#Start(): if #last_check_started > last check, set #next_check to #last_check_started
refs #7888
2020-07-28 11:54:13 +02:00
Alexander A. Klimov
4585a404d6 Checkable#ExecuteCheck(): set #last_check_started to now before #UpdateNextCheck()
refs #7888
2020-07-28 11:54:13 +02:00
Alexander A. Klimov
9dc297987e Sync Checkable#last_check_started
refs #7888
2020-07-28 11:54:13 +02:00