Association not created when sensors from DBus
Save the path when create virtual sensors from DBus.
Main functions after saving:
* Set the threshold on the path corresponding to entity-manager
* Create an association
I found that the sensor created by reading virtual_sensor_config.json will create association.
However,the virtual sensor created from DBus has no association,
so I added this.
In this way, my web/redfish can display this virtual sensor.
```
root@NULL:~# busctl introspect xyz.openbmc_project.VirtualSensor /xyz/openbmc_project/sensors/temperature/NVMe_MAX_Temp xyz.openbmc_project.Association.Definitions
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
.Associations property a(sss) 1 "chassis" "all_sensors" "/xyz/openbmc_project/inventory/system/nvme/NVMe_MAX" emits-change writable
```
The BMC web will find my all_sensor according to the following steps:
```
root@NULL:~# busctl call xyz.openbmc_project.ObjectMapper /xyz/openbmc_project/object_mapper xyz.openbmc_project.ObjectMapper GetSubTreePaths sias /xyz/openbmc_project/inventory 0 2 xyz.openbmc_project.Inventory.Item.Board xyz.openbmc_project.Inventory.Item.Chassis --verbose
MESSAGE "as" {
ARRAY "s" {
STRING "/xyz/openbmc_project/inventory/system/board/FP5280G2_Motherboard";
STRING "/xyz/openbmc_project/inventory/system/chassis";
STRING "/xyz/openbmc_project/inventory/system/nvme/NVMe_MAX";
};
};
root@NULL:~# busctl call xyz.openbmc_project.ObjectMapper /xyz/openbmc_project/inventory/system/nvme/NVMe_MAX/all_sensors org.freedesktop.DBus.Properties Get ss xyz.openbmc_project.Association endpoints --verbose
MESSAGE "v" {
VARIANT "as" {
ARRAY "s" {
STRING "/xyz/openbmc_project/sensors/temperature/NVMe_MAX_Temp";
};
};
};
```
Signed-off-by: Tao Lin <lintao.lc@inspur.com>
Change-Id: I5ab8ce532dde9cff837f85d1e27a0a420942a8ce
diff --git a/virtualSensor.hpp b/virtualSensor.hpp
index 8a9b115..286bca3 100644
--- a/virtualSensor.hpp
+++ b/virtualSensor.hpp
@@ -108,13 +108,15 @@
* @param[in] name - Virtual sensor name
* @param[in] type - Virtual sensor type/unit
* @param[in] calcType - Calculation used to calculate sensor value
+ * @param[in] entityPath - Virtual sensor path in entityManager Dbus
*
*/
VirtualSensor(sdbusplus::bus_t& bus, const char* objPath,
const InterfaceMap& ifacemap, const std::string& name,
- const std::string& type, const std::string& calculationType) :
+ const std::string& type, const std::string& calculationType,
+ const std::string& entityPath) :
ValueObject(bus, objPath, action::defer_emit),
- bus(bus), name(name)
+ bus(bus), name(name), entityPath(entityPath)
{
initVirtualSensor(ifacemap, objPath, type, calculationType);
}
@@ -136,6 +138,11 @@
sdbusplus::bus_t& bus;
/** @brief name of sensor */
std::string name;
+
+ /** @brief Virtual sensor path in entityManager Dbus.
+ * This value is used to set thresholds/create association
+ */
+ std::string entityPath;
/** @brief Expression string for virtual sensor value calculations */
std::string exprStr;
/** @brief symbol table from exprtk */
@@ -243,6 +250,10 @@
threshold->alarmLow(!alarmLow);
}
}
+
+ /** @brief Create Association from entityPath*/
+ void createAssociation(const std::string& objPath,
+ const std::string& entityPath);
};
class VirtualSensors