control: Add 'events' section to dump
Add an events section to the fan control dump that contains all of the
configured events with their contained action and group names.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I8e9fa9ce975ac30837b0842908faeb63ddc31e2a
diff --git a/control/json/actions/action.hpp b/control/json/actions/action.hpp
index 40547b9..cafa542 100644
--- a/control/json/actions/action.hpp
+++ b/control/json/actions/action.hpp
@@ -213,6 +213,25 @@
}
}
+ /**
+ * @brief Dump the action as JSON
+ *
+ * For now just dump its group names
+ *
+ * @return json
+ */
+ json dump() const
+ {
+ json groups = json::array();
+ std::for_each(_groups.begin(), _groups.end(),
+ [&groups](const auto& group) {
+ groups.push_back(group.getName());
+ });
+ json output;
+ output["groups"] = groups;
+ return output;
+ }
+
protected:
/**
* @brief Logs a message to the flight recorder using
diff --git a/control/json/event.cpp b/control/json/event.cpp
index 0f9ab8a..409006a 100644
--- a/control/json/event.cpp
+++ b/control/json/event.cpp
@@ -313,4 +313,25 @@
}
}
+json Event::dump() const
+{
+ json actionData;
+ std::for_each(_actions.begin(), _actions.end(),
+ [&actionData](const auto& action) {
+ actionData[action->getUniqueName()] = action->dump();
+ });
+
+ std::vector<std::string> groupData;
+ std::for_each(_groups.begin(), _groups.end(),
+ [&groupData](const auto& group) {
+ groupData.push_back(group.getName());
+ });
+
+ json eventData;
+ eventData["groups"] = groupData;
+ eventData["actions"] = actionData;
+
+ return eventData;
+}
+
} // namespace phosphor::fan::control::json
diff --git a/control/json/event.hpp b/control/json/event.hpp
index e4e01ea..0873c06 100644
--- a/control/json/event.hpp
+++ b/control/json/event.hpp
@@ -141,6 +141,13 @@
const std::vector<std::string>& profiles,
std::vector<Group>& groups);
+ /**
+ * @brief Return the contained groups and actions as JSON
+ *
+ * @return json - A JSON object of groups and actions
+ */
+ json dump() const;
+
private:
/* The sdbusplus bus object */
sdbusplus::bus::bus& _bus;
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index c9d679f..9129750 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -156,6 +156,10 @@
std::visit([&obj = parameters[name]](auto&& val) { obj = val; }, value);
}
+ std::for_each(_events.begin(), _events.end(), [&data](const auto& event) {
+ data["events"][event.second->getName()] = event.second->dump();
+ });
+
data["services"] = _servTree;
}