6129 Commits

Author SHA1 Message Date
Alexander Aleksandrovič Klimov
ee0af27a82
Merge pull request #9681 from Icinga/flush-temp-files-213
Deduplicate and stabilize fragile filesystem transactions
2023-02-15 20:51:41 +01:00
Alexander A. Klimov
9ea9b10014 Include Utility::SetFileOwnership() inside FS transactions
to make them even more atomic.
2023-02-15 17:20:37 +01:00
Alexander A. Klimov
d2e3a094c1 Introduce AtomicFile#GetTempFilename() 2023-02-15 17:20:35 +01:00
Alexander A. Klimov
69b3c81ea1 Remove unused Utility::CreateTempFile() 2023-02-15 17:20:02 +01:00
Alexander A. Klimov
34844c146d Deduplicate and stabilize fragile filesystem transactions
by using AtomicFile so they ensure all or nothing of a file gets replaced.
2023-02-15 17:19:57 +01:00
Alexander A. Klimov
f0c1764adc Introduce AtomicFile::Write() 2023-02-15 16:25:39 +01:00
Alexander A. Klimov
a497645127 Setup all signal handlers with SA_RESTART flag
so interrupted syscalls get auto-restarted and callers
don't get or have to handle the EINTR error.
2023-02-15 11:08:29 +01:00
Alexander A. Klimov
a1bda3300e Fix compile error on Solaris 11.4
by not using LOG_FTP which is not defined there.
2023-02-15 10:48:05 +01:00
Alexander A. Klimov
41c97d65b7 CheckerComponent#CheckThreadProc(): also propagate next check update to Icinga DB
if caused by dependency or check period.

Now as long as any of the above causes check skips
next check and next update will be up-to-date in Icinga DB,
so the checkable won't slide into false positive overdue.
2023-02-15 10:46:08 +01:00
Alexander A. Klimov
f84ffdad68 Handle boost::beast::http::basic_fields#operator[]() signature change (v1.81)
Use always working std::string(x), not broken x.to_string().
(x is a return value.)
2023-02-15 10:41:31 +01:00
Alexander A. Klimov
68198f2ef9 Handle boost::beast::http::basic_fields#set() signature change (v1.81)
Make String convertible to boost::beast::string_view (always working),
not boost::string_view (broken).
2023-02-15 10:41:31 +01:00
Yonas Habteab
a15bbfe913 Use service short name for evaluating targeted service rules 2022-11-04 12:47:41 +01:00
Yonas Habteab
e29de04687 Avoid evaluating the same filter twice for the same target 2022-11-04 12:47:41 +01:00
Alexander A. Klimov
cc67510063 ApplyRule::RuleMap: reduce complexity, save unnecessary lookups 2022-11-04 12:47:41 +01:00
Alexander A. Klimov
0bf093af14 Targeted apply rules: don't unnecessarily eval filter 2022-11-04 12:47:41 +01:00
Alexander A. Klimov
09d810dbd9 VariableExpression#GetVariable(): return by const ref not to unnecessarily malloc() 2022-11-04 12:47:41 +01:00
Alexander A. Klimov
840bfb6be1 Unify storages of regular/targeted apply rules: std::vector<ApplyRule::Ptr> 2022-11-04 12:47:41 +01:00
Alexander A. Klimov
1935137a8d Separately handle apply rules targetting only specific parent objects
not to unnecessarily run e.g. the filter assign where host.name=="example.com"
for all hosts being not example.com.
2022-11-04 12:47:41 +01:00
Alexander A. Klimov
3d2a6bbfb1 Allow hashmaps of String 2022-11-04 12:47:41 +01:00
Alexander A. Klimov
80ee597b72 Allow intrusive pointers to ApplyRule 2022-11-04 12:47:41 +01:00
Alexander A. Klimov
cf3e02243e Remove unused ApplyRule#m_TargetType 2022-11-02 11:06:12 +01:00
Alexander A. Klimov
fcedb01d0d Lookup apply rules faster by Type*, not String and by map instead of ==/!=
1. The lookup of apply rules per source type now implies
   no String(const char*) (no malloc()) and just pointer (uint64) comparisions
2. Apply rules are now also grouped by target type via a nested map, that obsoletes
   checking the target type while iterating over all rules per source type
2022-11-02 11:06:12 +01:00
Alexander A. Klimov
7f50955674 ApplyRule::GetTargetTypes(): return by const ref not to malloc() 2022-11-02 11:00:47 +01:00
Julian Brost
cdd531445a
Merge pull request #9558 from Icinga/context-evaluating-apply-rules-for-host-213
Construct string once, not unnecessarily N times
2022-11-02 10:48:57 +01:00
Julian Brost
2e02bb52f8
Merge pull request #9561 from Icinga/match-api-permissions-against-join-relations
Match api permissions against joined relations
2022-11-02 10:46:54 +01:00
Julian Brost
2f22be398b
Merge pull request #9560 from Icinga/handle-on-error-213
ConfigItem: Fix infinite recursion caused by `ignore_on_error`
2022-11-02 10:37:56 +01:00
Yonas Habteab
adc42e101d Evaluate permission filters also on all joined relations 2022-10-31 13:01:12 +01:00
Yonas Habteab
02524f5993 ObjectQueryHandler: Check user permissions on joined relations 2022-10-31 13:01:12 +01:00
Yonas Habteab
21b55cb1ac FilterUtility: Outsource permission matching from CheckPermission() to a separate method 2022-10-31 13:01:12 +01:00
Yonas Habteab
bbca13d788 ConfigItem: Don't add items to the new items vector before committing
This also improves the performance a bit, as we longer have to iterate over the items
and copy them into the new items vector.
2022-10-31 12:55:42 +01:00
Yonas Habteab
2adc0bd042 ConfigItem: Fix infinite recursion caused by ignore_on_error when committing an item
When committing an item with `ignore_on_error` flag set fails, the `Commit()` method only returns `nullptr`
and the current item is not being dropped from `m_Items`. `CommittNewItems()` also doesn't check the return
value of `Commit()` but just continues and tries to commit all items from `m_Items` in recursive call. Since
this corrupt item is never removed from `m_Items`, it ends up in an endless recursion till it finally crashes.
2022-10-31 12:55:42 +01:00
Alexander A. Klimov
17c652d8dd Construct string once, not unnecessarily N times 2022-10-31 12:40:59 +01:00
Yonas Habteab
a4de67d558 RedisConnection: Don't log queries that are going to be discarded 2022-10-26 11:55:10 +02:00
Alexander A. Klimov
de60eb445b Logger: don't render log messages which will be disposed anyway
by caching the total minimum log severity of all loggers in a
"global variable" and whether a message's severity is large enough for any of
the loggers in a per-message no-op flag.
2022-10-26 11:55:10 +02:00
Alexander A. Klimov
865c5b8365 Utility::ValidateUTF8(): move a string instead of copying a vector
less malloc() = more speed

Especially as JsonEncode() validates every single input string.
2022-10-26 11:55:10 +02:00
Alexander A. Klimov
2754895c11 Icinga DB: on every check result update state only 1x, not 3x in a row
Before (time: vertical, stack: horizontal):

* Checkable::ExecuteCheck
  * Checkable::UpdateNextCheck
    * IcingaDB::NextCheckChangedHandler
      * HSET icinga:host:state
      * HSET icinga:checksum:host:state
      * ZADD icinga:nextupdate:host
  * RandomCheckTask::ScriptFunc
    * Checkable::ProcessCheckResult
      * Checkable::UpdateNextCheck
        * IcingaDB::NextCheckChangedHandler
          * HSET icinga:host:state
          * HSET icinga:checksum:host:state
          * ZADD icinga:nextupdate:host
      * IcingaDB::NewCheckResultHandler
        * HSET icinga:host:state
        * HSET icinga:checksum:host:state
        * ZADD icinga:nextupdate:host
  * IcingaDB::StateChangeHandler
    * XADD icinga:runtime:state
    * IcingaDB::ForwardHistoryEntries
      * XADD icinga:history:stream:state

After:

* Checkable::ExecuteCheck
  * Checkable::UpdateNextCheck
  * RandomCheckTask::ScriptFunc
    * Checkable::ProcessCheckResult
      * Checkable::UpdateNextCheck
      * IcingaDB::NewCheckResultHandler
        * HSET icinga:host:state
        * HSET icinga:checksum:host:state
        * ZADD icinga:nextupdate:host
  * IcingaDB::StateChangeHandler
    * XADD icinga:runtime:state
    * IcingaDB::ForwardHistoryEntries
      * XADD icinga:history:stream:state

The first state + nextupdate (for overdue) update comes from next_check being
set to now + interval immediately before doing the actual check (not to trigger
it twice). This update is not only not important for the end user, but even
inappropriate. The end user SHALL see next_check being e.g. in -4s, not 5m, as
the check is running at the moment.

The second one is just redundant as IcingaDB::NewCheckResultHandler (the third
one) is called anyway and will update state + nextupdate as well.
2022-10-26 11:55:10 +02:00
Alexander A. Klimov
ea4b819480 IcingaDB::VersionChangedHandler(): don't handle not synced types
not to surprise (and crash) the Icinga DB daemon with unknown types.
2022-08-10 17:04:29 +02:00
Alexander A. Klimov
ac57ed6cb4 IcingaDB::SendCustomVarsChanged(): don't delete custom vars of not synced types
not to surprise (and crash) the Icinga DB daemon with unknown types.
2022-08-10 17:04:29 +02:00
Julian Brost
1a2ee1241a
Merge pull request #9467 from Icinga/flush-state-file-213
Dump state file atomically not to corrupt it
2022-08-02 09:21:07 +02:00
Alexander A. Klimov
92a01a748d Dump state file atomically not to corrupt it
by using fsync(2) before close(2) and rename(2).
2022-08-01 17:56:37 +02:00
Alexander A. Klimov
53af4f2dd4 Introduce AtomicFile 2022-08-01 17:56:37 +02:00
Julian Brost
cc1e9c05ec Windows: output useful error message for syscall errors 2022-08-01 17:56:37 +02:00
Julian Brost
67fb24cc11 Windows: only include critical messages in early log messages
The point of logging to the Windows Event Log was to catch errors that happen
before the full logging configuration has been loaded and enabled. Messages
like the number of loaded objects per type just cause noise in the log and
provide little benefit. Therefore raise the required log level at this stage.

Note that this commit removes the (never documented) ability to use the -x flag
to change the level. But doing so would require patching the command line of
the service in the registry anyways.
2022-07-26 18:33:22 +02:00
Alexander A. Klimov
b2245be53c Icinga DB: icinga:*:state: rename state to soft_state 2022-06-29 12:30:38 +02:00
Alexander Aleksandrovič Klimov
d35f823a96
Merge pull request #9419 from Icinga/feature/adjust-some-column-names-2.13
IcingaDB: Adjust some column names according to the DB schema
2022-06-28 22:00:00 +02:00
Alexander Aleksandrovič Klimov
8ff3f2aeb1
Merge pull request #9418 from Icinga/feature/icingadb-no-ca-error-message-2.13
Icinga DB: make error message more helpful if API isn't set up
2022-06-28 20:08:24 +02:00
Yonas Habteab
a9acb3c9d9 IcingaDB: Adjust some column names according to the DB schema 2022-06-28 16:46:52 +02:00
Julian Brost
0d0c2678d9 Icinga DB: make error message more helpful if API isn't set up 2022-06-28 15:57:42 +02:00
Julian Brost
ce814853c3 Icinga DB Check: don't check runtime update backlog during full sync 2022-06-28 15:35:34 +02:00
Julian Brost
0649a9dc06 Icinga DB Check: ignore suppressed queries in Redis backlog check
If some kind of query is not supposed to be processed at the moment, there is
little point in checking it. During a full dump, state updates are suppressed
(i.e. delayed), so when a dump takes very long, this would have resulted in a
false Redis backlog warning.
2022-06-28 15:35:34 +02:00