Fix SNMP invalid Destination error
This commit handles invalid SNMP destination error
Tested by:
Configure SNMP with invalid destination IP address
'{"Destination": "snmp://10.6.6.256:162",
"SubscriptionType": "SNMPTrap", "Protocol": "SNMPv2c"}'
Change-Id: I88f81a79a6665a7adc654e138b4f07ce321898a4
Signed-off-by: Ravi Teja <raviteja28031990@gmail.com>
diff --git a/redfish-core/include/snmp_trap_event_clients.hpp b/redfish-core/include/snmp_trap_event_clients.hpp
index 5660fbc..6cc96a6 100644
--- a/redfish-core/include/snmp_trap_event_clients.hpp
+++ b/redfish-core/include/snmp_trap_event_clients.hpp
@@ -129,24 +129,35 @@
"org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
}
-inline void
- afterSnmpClientCreate(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const boost::system::error_code& ec,
- const std::string& dbusSNMPid)
+inline void afterSnmpClientCreate(
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const boost::system::error_code& ec, const sdbusplus::message_t& msg,
+ const std::string& host, const std::string& dbusSNMPid)
{
if (ec)
{
- if (ec.value() != EBADR)
+ const sd_bus_error* dbusError = msg.get_error();
+ if (dbusError != nullptr)
{
- // SNMP not installed
- messages::propertyValueOutOfRange(asyncResp->res, "SNMPv2c",
- "Protocol");
- return;
+ if (std::string_view(
+ "xyz.openbmc_project.Common.Error.InvalidArgument") ==
+ dbusError->name)
+ {
+ messages::propertyValueIncorrect(asyncResp->res, "Destination",
+ host);
+ return;
+ }
+ if (ec.value() != EBADR)
+ {
+ // SNMP not installed
+ messages::propertyValueOutOfRange(asyncResp->res, "SNMPv2c",
+ "Protocol");
+ return;
+ }
}
messages::internalError(asyncResp->res);
return;
}
-
sdbusplus::message::object_path path(dbusSNMPid);
const std::string snmpId = path.filename();
if (snmpId.empty())
@@ -168,9 +179,10 @@
const std::string& host, uint16_t snmpTrapPort)
{
crow::connections::systemBus->async_method_call(
- [asyncResp](const boost::system::error_code& ec,
- const std::string& dbusSNMPid) {
- afterSnmpClientCreate(asyncResp, ec, dbusSNMPid);
+ [asyncResp, host](const boost::system::error_code& ec,
+ const sdbusplus::message_t& msg,
+ const std::string& dbusSNMPid) {
+ afterSnmpClientCreate(asyncResp, ec, msg, host, dbusSNMPid);
},
"xyz.openbmc_project.Network.SNMP",
"/xyz/openbmc_project/network/snmp/manager",