206 Commits

Author SHA1 Message Date
Alexander A. Klimov
04457f5f16 IcingaDB::PrepareObject(): round Notification#times.{begin,end} not to crash Go daemon
The latter expects ints, not floats - not to mention strings.
Luckily Icinga already enforces numeric strings so that we can cast it to number.
2023-07-03 17:08:40 +02:00
Alexander A. Klimov
b7ecefb3c0 IcingaDB::PrepareObject(): round Notification#interval and limit it to >=0
otherwise, e.g. with -42.5, the Go daemon crashes. It expects uints there.
2023-07-03 17:08:40 +02:00
Alexander A. Klimov
2f1732e7e6 IcingaDB::PrepareObject(): cut off (0) negative Command#timeout for Redis
not to crash the Go daemon which expects positive values there.
2023-07-03 17:08:40 +02:00
Alexander A. Klimov
766e28e1aa IcingaDB::PrepareObject(): convert non-null Checkable#check_timeout to number
and, in case of null, fall back to Checkable#check_command.timeout, just like
IcingaDB#SerializeState(). Otherwise the Go daemon crashes. It expects a number.
2023-07-03 17:08:40 +02:00
Alexander A. Klimov
f0176001fe Icinga DB: don't write negative Downtime durations into Redis
via `std::max(0, x)` not to crash the Go daemon which can't handle such.
2023-07-03 17:08:40 +02:00
Alexander A. Klimov
99350e6b27 Icinga DB feature: normalize *Command.arguments[*].{required,skip_key,repeat_key} to boolean
At the moment, the Icinga DB feature will use that value as-is and
serialize it to JSON, resulting in a crash in Icinga DB down the road
because it expects a boolean.
2023-07-03 17:08:40 +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
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
Yonas Habteab
a9acb3c9d9 IcingaDB: Adjust some column names according to the DB schema 2022-06-28 16:46:52 +02:00
Alexander A. Klimov
6eebc7868f Introduce Icinga DB check (like the IDO one) 2022-06-28 15:35:34 +02:00
Alexander A. Klimov
f9155a2d5f Introduce IcingaDB::AddKvsToMap() 2022-06-28 15:35:34 +02:00
Alexander Aleksandrovič Klimov
1d16c3a300
Merge pull request #9397 from Icinga/feature/parameter-delimiters-check-execution-6277-2.13
Introduce Command#arguments[].separator
2022-06-23 11:31:07 +02:00
Alexander Aleksandrovič Klimov
9eaa9c9f2e
Merge pull request #9398 from Icinga/bugfix/icingadb-command-arguments-null-2.13
IcingaDB: handle null (Empty) for value/set_if/separator in command arguments
2022-06-23 11:30:43 +02:00
Yonas Habteab
524235872c Bump Redis schema version to 5 2022-06-14 15:07:02 +02:00
Yonas Habteab
7e12927b8a IcingaDB: Add _name suffix to columns referring to name 2022-06-14 15:07:02 +02:00
Alexander A. Klimov
20ae49ad49 Introduce Command#arguments[].separator
... for letting check commands produce argv like --key=value,
not just --key value.

refs #6277
2022-06-14 15:04:09 +02:00
Julian Brost
46c33bedaf IcingaDB: handle null (Empty) for value/set_if/separator in command arguments
Icinga 2 treats null (Empty) as if the corresponding attribute is not
specified. However, without this commit, it would serialize the value as "null"
(i.e. type string), so that it ends up in the database as this string instead
of NULL. This commit adds handling for ValueEmpty so that is serialized as JSON
null value and ends up in the database as NULL.
2022-06-14 14:55:19 +02:00
Alexander A. Klimov
df3be79194 Icinga DB: correct ack comments' is_sticky
On ack Icinga first adds a comment, then acks the checkable
so the ack event has the comment ID.

But due to the yet missing ack the comment was missing is_sticky.
That's corrected now.
2022-03-30 09:45:39 +02:00
Alexander Aleksandrovič Klimov
5f1e0ee2aa
Merge pull request #9302 from Icinga/bugfix/icingadb-ignore-acks-in-comment-history-2.13
IcingaDB#SendRemovedComment(): ignore ack comments like #SendAddedCom…
2022-03-29 21:37:29 +02:00
Alexander A. Klimov
8d3a847998 IcingaDB#SendRemovedComment(): ignore ack comments like #SendAddedComment()
Icinga DB doesn't expect comment history for ack comments.

Before:

1. Acked checkable recovers
2. Icinga clears ack comments w/o setting removal time
3. Icinga DB gets neither removal time, nor expire time
4. Icinga DB falls back to NULL and violates NOT NULL constraint
2022-03-29 16:16:06 +02:00
Julian Brost
41043f86a8 Icinga DB: discard comment removals with missing information
If comments get removed in unintended ways (i.e. not by expiring or by using
the remove-comment API action), the comment object misses information to create
a proper history event for Icinga DB. Therefor, discard these events.
2022-03-29 15:56:25 +02:00
Julian Brost
332dcb8bec
Merge pull request #9271 from Icinga/feature/icingadb-redis-lost-history-memory-213
Icinga DB: keep history in memory until written to Redis
2022-03-29 13:57:48 +02:00
Julian Brost
12293d999c
Merge pull request #9190 from Icinga/bugfix/sync-missing-history-information-213
Icinga DB: ensure consistent history streams in HA setup
2022-03-07 11:32:15 +01:00
Julian Brost
db84b834ca
Merge pull request #9214 from Icinga/feature/icingadb-add-previous_soft_state-to-host_state-and-service_state-9210-213
IcingaDB: Add previous_soft_state to host_state and service_state
2022-03-07 11:19:50 +01:00
Alexander A. Klimov
f1a942681f IcingaDB#Send*(): don't enqueue any history once stopped 2022-03-03 09:57:03 +01:00
Alexander A. Klimov
3cc82069cd Icinga DB: log amount of history kept in memory every 10s 2022-03-03 09:57:03 +01:00
Alexander A. Klimov
0137713d15 Icinga DB: keep history in memory until written to Redis
by putting the messages into a Bulker and retrying each chunk.
2022-03-03 09:57:03 +01:00
Alexander A. Klimov
3c8c248508 Icinga DB: ensure is_reachable and severity don't miss updates
refs #9143
2022-02-23 16:06:31 +01:00
Julian Brost
175fd2df44 Icinga DB: remove obsolete StateChangeHandler overload
This version of StateChangeHandler is no longer called anywhere as it was the
wrong function for all previous callers anyways.
2022-02-23 11:08:56 +01:00
Julian Brost
b60d3e5665 Icinga DB: make host problem change events update the state tables but not write state history
StateChangeHandler() is the function used when the actual hard/soft state
changes and thus also writes state history. This is not desired in this case,
instead, a runtime update should be generated, therefore call UpdateState()
instead.

refs #9063
2022-02-23 11:08:56 +01:00
Julian Brost
3466dacaac Icinga DB: make acknowledgement events update the state tables but not write state history
StateChangeHandler() is the function used when the actual hard/soft state
changes and thus also writes state history. This is not desired in this case,
instead, a runtime update should be generated, therefore call UpdateState()
instead.

refs #9063
2022-02-23 11:08:56 +01:00
Julian Brost
5ea0208b83 Icinga DB: make downtime events update the state tables but not write state history
StateChangeHandler() is the function used when the actual hard/soft state
changes and thus also writes state history. This is not desired in this case,
instead, a runtime update should be generated, therefore call UpdateState()
instead.

refs #9063
2022-02-23 11:08:56 +01:00
Julian Brost
f671374762 Icinga DB: don't reimplement volatile state update in SendConfigUpdate
Sending a volatile state update is already implemented in UpdateState, so just
use that function instead of generating the update queries.
2022-02-23 11:08:56 +01:00
Julian Brost
244575ecbd Icinga DB: Merge SendStatusUpdate into UpdateState
Previously, both funktions did related operations but had unclear and confusing
naming:
- UpdateState updated the icinga:{host,service}:state Redis keys.
- SendStatusUpdate sent a runtime update for the icinga:{host,service}:state.

This commit merges both functions into one with a new mode parameter. The
following modes are now supported:
- Volatile: Update the icinga:{host,service}:state Redis key.
- Full: Perform the volatile state update and in addition send a corresponding
  runtime update so that this state update gets written through to the
  persistent database by a running icingadb process.
- RuntimeOnly: Special mode for callers that can ensure that a volatile update
  for the current state was already performed but has to be upgraded to a full
  update.

refs #9063
2022-02-23 11:08:56 +01:00
Alexander A. Klimov
c613e62454 IcingaDB: Add previous_soft_state to host_state and service_state
refs #9210
2022-02-14 11:32:46 +01:00
Julian Brost
4c2f6faa61 Sync comment and downtime removal info for Icinga DB history
When a comment or downtime is removed manually, the name of the requestor and
timestamp have to be synced to other nodes in the cluster to allow all of them
to generate a consistent Icinga DB history stream.

refs #9101
2022-01-24 18:03:03 +01:00
Julian Brost
cd2ae9a886
Merge pull request #9182 from Icinga/bugfix/icinga-db-notification-history-might-use-incorrect-previous_hard_state-9132-213
IcingaDB#SendSentNotification(): make stream deterministic via CheckResult#previous_hard_state
2022-01-21 18:05:49 +01:00
Alexander A. Klimov
2e7fe4da95 IcingaDB#SendSentNotification(): make stream deterministic via CheckResult#previous_hard_state
Now it gets everything from one source, the CheckResult.

refs #9132
2022-01-20 11:27:19 +01:00
Alexander A. Klimov
50e3e31e04 Icinga DB: ensure icinga:*command:argument#order is an int
The config parser requires *Command#arguments#order to be a Number, i.e. 42,
4.2 or even "4.2". That's int-casted where needed, now also for Icinga DB.

Before:

```
object CheckCommand "9117" {
	command = [ "true" ]
	arguments = {
		"4.2" = { order = "4.2" }
	}
}
```

2022-01-03T13:25:07.166+0100	FATAL	icingadb	json: cannot unmarshal string into Go value of type int64
2022-01-20 11:17:22 +01:00
Noah Hilverling
4fd1b153fa IcingaDB::AddObjectDataToRuntimeUpdates(): Copy data before modifying 2021-11-12 17:55:47 +01:00
Noah Hilverling
2d2b165a79 Icinga DB: Make sure object relationships are handled correctly 2021-11-12 17:55:47 +01:00
Noah Hilverling
73d98cc2ff
Merge pull request #9083 from Icinga/bugfix/icingadb-improve-object-identifier-function-2.13
IcingaDB: Remove GetObjectIdentifiersWithoutEnv()
2021-11-12 13:04:07 +01:00
Noah Hilverling
b55e924e8b IcingaDB: Prefix command_id with command type 2021-11-12 10:19:18 +01:00
Noah Hilverling
d164d66808 IcingaDB: Remove GetObjectIdentifiersWithoutEnv()
Having the command type be a part of the command ID isn't needed anywhere. Removing this simplifies the way we generate IDs in general, because we don't need Prepend() anymore.

The command type was only needed to prevent ID collisions within the command_envvar and command_argument tables. Those tables have since been separated into {check,event,notification}command_envvar and {check,event,notification}command_argument tables.
2021-11-12 10:18:33 +01:00
Julian Brost
9a5ba28e0c Icinga DB: increase Redis schema version
PR #9036 introduces some incompatible changes to the Redis schema, most
importantly where Icinga DB has to read the environment from: now it has to use
a new top-level key of the icinga:stats message instead of a value in the
IcingaApplication part of that message.
2021-11-11 16:58:16 +01:00
Julian Brost
42fc3cdcfc IcingaDB: introduce a new environment ID derived from the CA public key
In order to avoid changes to the environment ID, it is now no longer derived
from the Environment constant but instead from the public key of the CA
certificate. This ensures that it is different between clusters by default, so
no additional changes have to be done to allow two clusters to use Icinga DB to
write into the same database.

To prevent the ID from changing when the CA certificate is replaced, it is also
persisted into the file /var/lib/icinga2/icingadb.env, so if that file exists,
it takes precedence over the CA certificate.
2021-11-11 16:58:16 +01:00
Noah Hilverling
e1dbfa1011
Merge pull request #9076 from Icinga/feature/icingadb-history-deterministic-ids-2.13
Icinga DB: make icinga:history:stream:*#event_id deterministic
2021-11-11 16:57:10 +01:00