mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-26 23:24:09 +02:00
Implement minimal state sync
This commit is contained in:
parent
c825a3f4b5
commit
2215e9e16f
@ -561,18 +561,25 @@ void RedisWriter::SendConfigDelete(const ConfigObject::Ptr& object)
|
|||||||
|
|
||||||
void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object)
|
void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object)
|
||||||
{
|
{
|
||||||
//TODO: Manage type names
|
//TODO: This is probably uncesessary?
|
||||||
//TODO: Figure out what we need when we implement the history and state sync
|
Checkable::Ptr checkable = dynamic_pointer_cast<Checkable>(object);
|
||||||
// UpdateObjectAttrs(m_PrefixStatusObject, object, FAState, "");
|
if (!checkable)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String streamname = "hoststatus";
|
||||||
|
Host::Ptr host = dynamic_pointer_cast<Host>(object);
|
||||||
|
if (!host)
|
||||||
|
streamname = "servicestatus";
|
||||||
|
|
||||||
// /* Serialize config object attributes */
|
/* Serialize config object attributes
|
||||||
// Dictionary::Ptr objectAttrs = SerializeObjectAttrs(object, FAState);
|
* TODO: Flatten last check result
|
||||||
//
|
*/
|
||||||
// String jsonBody = JsonEncode(objectAttrs);
|
auto objectAttrs = SerializeState(object);
|
||||||
//
|
|
||||||
// String objectName = object->GetName();
|
std::vector<String> streamadd({"XADD", streamname, "*", "id", GetObjectIdentifier(object)});
|
||||||
//
|
streamadd.insert(streamadd.end(), std::begin(objectAttrs), std::end(objectAttrs));
|
||||||
|
|
||||||
|
m_Rcon->ExecuteQuery(streamadd);
|
||||||
// ExecuteQuery({ "HSET", "icinga:status:" + typeName, objectName, jsonBody });
|
// ExecuteQuery({ "HSET", "icinga:status:" + typeName, objectName, jsonBody });
|
||||||
//
|
//
|
||||||
// /* Icinga DB part for Icinga Web 2 */
|
// /* Icinga DB part for Icinga Web 2 */
|
||||||
@ -644,6 +651,37 @@ void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object)
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<String> RedisWriter::SerializeState(const Object::Ptr& object)
|
||||||
|
{
|
||||||
|
Type::Ptr type = object->GetReflectionType();
|
||||||
|
|
||||||
|
std::vector<String> resultAttrs = std::vector<String>();
|
||||||
|
|
||||||
|
for (int fid = 0; fid < type->GetFieldCount(); fid++) {
|
||||||
|
Field field = type->GetFieldInfo(fid);
|
||||||
|
|
||||||
|
if ((field.Attributes & FAState) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Value val = object->GetField(fid);
|
||||||
|
|
||||||
|
/* hide attributes which shouldn't be user-visible */
|
||||||
|
if (field.Attributes & FANoUserView)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* hide internal navigation fields */
|
||||||
|
if (field.Attributes & FANavigation && !(field.Attributes & (FAConfig | FAState)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Value sval = Serialize(val);
|
||||||
|
resultAttrs.emplace_back(field.Name);
|
||||||
|
resultAttrs.emplace_back(sval);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultAttrs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<String>
|
std::vector<String>
|
||||||
RedisWriter::UpdateObjectAttrs(const ConfigObject::Ptr& object, int fieldType,
|
RedisWriter::UpdateObjectAttrs(const ConfigObject::Ptr& object, int fieldType,
|
||||||
const String& typeNameOverride)
|
const String& typeNameOverride)
|
||||||
|
@ -73,6 +73,7 @@ private:
|
|||||||
void SendConfigDelete(const ConfigObject::Ptr& object);
|
void SendConfigDelete(const ConfigObject::Ptr& object);
|
||||||
void SendStatusUpdate(const ConfigObject::Ptr& object);
|
void SendStatusUpdate(const ConfigObject::Ptr& object);
|
||||||
std::vector<String> UpdateObjectAttrs(const ConfigObject::Ptr& object, int fieldType, const String& typeNameOverride);
|
std::vector<String> UpdateObjectAttrs(const ConfigObject::Ptr& object, int fieldType, const String& typeNameOverride);
|
||||||
|
std::vector<String> SerializeState(const Object::Ptr& object);
|
||||||
|
|
||||||
/* Stats */
|
/* Stats */
|
||||||
Dictionary::Ptr GetStats();
|
Dictionary::Ptr GetStats();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user