Update threshold to entity-manager
Save path&interface when creating thresholds,and then set DBUS value
corresponding to path&interface when setting thresholds;
I have a requirement to set the threshold to restart without losing. In
addition, I can see that the threshold can be saved in the file in the
entity-manager, which can meet my requirements.
Data flow:
Old version: IPMI set threshold -> virtualsensors (DBUS) What
I want to achieve: IPMI set threshold -> virtualsensors (DBUS) ->
filesystem
I found that it can be implemented as follows: IPMI set
threshold -> virtual-sensors (DBUS) -> entitymanager -> filesystem
Because the threshold setting in dbus-sensors is: IPMI set threshold ->
dbus-sensors (DBUS) -> entitymanager -> filesystem
Tested:
The following print result shows this process:
IPMI set threshold -> virtual sensors (DBUS) -> entitymanager
root@NULL:~# busctl introspect xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/nvme/NVMe_MAX/NVMe_MAX_Temp xyz.openbmc_project.Configuration.ModifiedMedian.Thresholds0
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
.Delete method - - -
.Direction property s "greater than" emits-change writable
.Name property s "upper critical" emits-change writable
.Severity property d 1 emits-change writable
.Value property d 116 emits-change writable
root@NULL:~# ipmitool sensor list | grep NVM
NVMe_MAX_Temp | na | degrees C | na | na | 1.000 | 6.000 | 111.000 | 116.000 | na
root@NULL:~# ipmitool sensor thresh NVMe_MAX_Temp ucr 119
Locating sensor record 'NVMe_MAX_Temp'...
Setting sensor "NVMe_MAX_Temp" Upper Critical threshold to 119.000
root@NULL:~# ipmitool sensor list | grep NVM
NVMe_MAX_Temp | na | degrees C | na | na | 1.000 | 6.000 | 111.000 | 119.000 | na
root@NULL:~# busctl introspect xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/nvme/NVMe_MAX/NVMe_MAX_Temp xyz.openbmc_project.Configuration.ModifiedMedian.Thresholds0
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
.Delete method - - -
.Direction property s "greater than" emits-change writable
.Name property s "upper critical" emits-change writable
.Severity property d 1 emits-change writable
.Value property d 119 emits-change writable
root@NULL:~# busctl introspect xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/nvme/NVMe_MAX/NVMe_MAX_Temp xyz.openbmc_project.Configuration.ModifiedMedian.Thresholds0
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
.Delete method - - -
.Direction property s "greater than" emits-change writable
.Name property s "upper critical" emits-change writable
.Severity property d 1 emits-change writable
.Value property d 119 emits-change writable
root@NULL:~#
Signed-off-by: Tao Lin <lintao.lc@inspur.com>
Change-Id: I0f5eeb06d0b3aaf4f5806bfa68672dedcb087f26
diff --git a/dbusUtils.hpp b/dbusUtils.hpp
index 0495ceb..b664c48 100644
--- a/dbusUtils.hpp
+++ b/dbusUtils.hpp
@@ -1,6 +1,9 @@
#include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
+const constexpr char* entityManagerBusName =
+ "xyz.openbmc_project.EntityManager";
const char* propIntf = "org.freedesktop.DBus.Properties";
const char* mapperBusName = "xyz.openbmc_project.ObjectMapper";
const char* mapperPath = "/xyz/openbmc_project/object_mapper";
@@ -8,6 +11,7 @@
const char* methodGetObject = "GetObject";
const char* methodGet = "Get";
+const char* methodSet = "Set";
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
@@ -76,3 +80,26 @@
return std::get<T>(value);
}
+
+int setDbusProperty(sdbusplus::bus_t& bus, const std::string& service,
+ const std::string& path, const std::string& intf,
+ const std::string& property, const Value& value)
+{
+ try
+ {
+ auto method = bus.new_method_call(service.c_str(), path.c_str(),
+ propIntf, methodSet);
+ method.append(intf, property, value);
+ auto msg = bus.call(method);
+ }
+ catch (const sdbusplus::exception_t& e)
+ {
+ lg2::error(
+ "Faild to set dbus property. service:{SERVICE} path:{PATH} intf:{INTF} Property:{PROP},{ERRMSG}",
+ "SERVICE", service, "PATH", path, "INTF", intf, "PROP", property,
+ "ERRMSG", e);
+ return -1;
+ }
+
+ return 0;
+}