* Update the state information of a checkable in Redis. * * What is updated exactly depends on the mode parameter: * - VolatileState: Update the volatile state information stored in icinga:host:state or icinga:service:state as well * as the corresponding checksum stored in icinga:checksum:host:state or icinga:checksum:service:state. * - RuntimeState: Write a runtime update to the icinga:
| 1325 | * @param mode Mode of operation (DirtyBits:VolatileState, DirtyBits::RuntimeState, or DirtyBits::FullState) |
| 1326 | */ |
| 1327 | void IcingaDB::UpdateState(const Checkable::Ptr& checkable, uint32_t mode) |
| 1328 | { |
| 1329 | Dictionary::Ptr stateAttrs = SerializeState(checkable); |
| 1330 | |
| 1331 | String checksum = HashValue(stateAttrs); |
| 1332 | |
| 1333 | auto [redisStateKey, redisChecksumKey] = GetCheckableStateKeys(checkable->GetReflectionType()); |
| 1334 | if (mode & icingadb::task_queue::VolatileState) { |
| 1335 | String objectKey = GetObjectIdentifier(checkable); |
| 1336 | m_RconWorker->FireAndForgetQueries({ |
| 1337 | {"HSET", redisStateKey, objectKey, JsonEncode(stateAttrs)}, |
| 1338 | {"HSET", redisChecksumKey, objectKey, JsonEncode(new Dictionary({{"checksum", checksum}}))}, |
| 1339 | }); |
| 1340 | } |
| 1341 | |
| 1342 | if (mode & icingadb::task_queue::RuntimeState) { |
| 1343 | ObjectLock olock(stateAttrs); |
| 1344 | |
| 1345 | RedisConnection::Query streamadd({ |
| 1346 | "XADD", "icinga:runtime:state", "MAXLEN", "~", "1000000", "*", |
| 1347 | "runtime_type", "upsert", |
| 1348 | "redis_key", redisStateKey, |
| 1349 | "checksum", checksum, |
| 1350 | }); |
| 1351 | |
| 1352 | for (const Dictionary::Pair& kv : stateAttrs) { |
| 1353 | streamadd.emplace_back(kv.first); |
| 1354 | streamadd.emplace_back(IcingaToStreamValue(kv.second)); |
| 1355 | } |
| 1356 | |
| 1357 | m_RconWorker->FireAndForgetQuery(std::move(streamadd), {0, 1}); |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | /** |
| 1362 | * Update the dependency state information of the given checkable and its associated dependency groups in Redis. |
nothing calls this directly
no test coverage detected