From fae5b88e485cda7e8ddf2444619c7b276079e356 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 8 Jun 2018 12:47:45 +0200 Subject: [PATCH] Add all stats similar to /v1/status --- lib/redis/rediswriter-stats.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/redis/rediswriter-stats.cpp b/lib/redis/rediswriter-stats.cpp index 152d0b64b..1a234b64d 100644 --- a/lib/redis/rediswriter-stats.cpp +++ b/lib/redis/rediswriter-stats.cpp @@ -28,21 +28,33 @@ using namespace icinga; Dictionary::Ptr RedisWriter::GetStats() { + Dictionary::Ptr stats = new Dictionary(); + //TODO: Figure out if more stats can be useful here. Dictionary::Ptr statsFunctions = ScriptGlobal::Get("StatsFunctions", &Empty); if (!statsFunctions) Dictionary::Ptr(); - Function::Ptr func = statsFunctions->Get("CIB"); + ObjectLock olock(statsFunctions); - Dictionary::Ptr status = new Dictionary(); - Array::Ptr perfdata = new Array(); + for (const Dictionary::Pair& kv : statsFunctions) + { + Function::Ptr func = kv.second; - func->Invoke({ status, perfdata }); + if (!func) + BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid status function name.")); -// String jsonStats = JsonEncode(status); + Dictionary::Ptr status = new Dictionary(); + Array::Ptr perfdata = new Array(); + func->Invoke({ status, perfdata }); - return status; + stats->Set(kv.first, new Dictionary({ + { "status", status }, + { "perfdata", Serialize(perfdata, FAState) } + })); + } + + return stats; }