diff --git a/src/tmx/Messages/include/MessageTypes.h b/src/tmx/Messages/include/MessageTypes.h index e0fd09c70..3360788fe 100644 --- a/src/tmx/Messages/include/MessageTypes.h +++ b/src/tmx/Messages/include/MessageTypes.h @@ -92,6 +92,7 @@ static CONSTEXPR const char *MSGSUBTYPE_OUTGOING_STRING = "Outgoing"; static CONSTEXPR const char *MSGSUBTYPE_SHUTDOWN_STRING = "Shutdown"; static CONSTEXPR const char *MSGSUBTYPE_TIMESYNC_STRING = "TimeSync"; static CONSTEXPR const char *MSGSUBTYPE_SENSOR_DETECTED_OBJECT_STRING = "SensorDetectedObject"; +static CONSTEXPR const char *MSGSUBTYPE_RSU_STATUS_STRING = "RSUStatus"; } /* End namespace messages */ diff --git a/src/tmx/Messages/include/RSUStatusMessage.h b/src/tmx/Messages/include/RSUStatusMessage.h new file mode 100644 index 000000000..a5e276268 --- /dev/null +++ b/src/tmx/Messages/include/RSUStatusMessage.h @@ -0,0 +1,25 @@ +#pragma once + + +#include +#include "MessageTypes.h" + + +namespace tmx::messages { + + +class RSUStatusMessage : public tmx::message +{ + public: + RSUStatusMessage() {} + + /// Message type for routing this message through TMX core. + static constexpr const char* MessageType = MSGTYPE_APPLICATION_STRING; + + /// Message sub type for routing this message through TMX core. + static constexpr const char* MessageSubType = MSGSUBTYPE_RSU_STATUS_STRING; + }; + +} /* namespace tmx::messages */ + + diff --git a/src/tmx/TmxUtils/src/SNMPClient.cpp b/src/tmx/TmxUtils/src/SNMPClient.cpp index 857c41692..e6d1a5c80 100644 --- a/src/tmx/TmxUtils/src/SNMPClient.cpp +++ b/src/tmx/TmxUtils/src/SNMPClient.cpp @@ -178,6 +178,7 @@ namespace tmx::utils { // get Integer value if(vars->type == ASN_INTEGER){ if(vars->val.integer){ + val.type = snmp_response_obj::response_type::INTEGER; val.val_int = *vars->val.integer; PLOG(logDEBUG1) << "Integer value in object: " << val.val_int; } @@ -194,6 +195,7 @@ namespace tmx::utils { { val.val_string.push_back(vars->val.string[i]); } + val.type = snmp_response_obj::response_type::STRING; } else{ diff --git a/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUHealthMonitorPlugin.cpp b/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUHealthMonitorPlugin.cpp index cf86db8c5..93062c445 100755 --- a/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUHealthMonitorPlugin.cpp +++ b/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUHealthMonitorPlugin.cpp @@ -56,6 +56,7 @@ namespace RSUHealthMonitor ptree pt; istringstream iss(json_str); read_json(iss, pt); + _rsuOIDConfigMap.clear(); BOOST_FOREACH (ptree::value_type &child, pt.get_child("RSUOIDConfig")) { // Array elements have no names. @@ -84,14 +85,14 @@ namespace RSUHealthMonitor { while (true) { - PLOG(logERROR) << "RSU status update call at every " << _interval; - - for_each(_rsuOIDConfigMap.begin(), _rsuOIDConfigMap.end(), [this](RSUOIDConfig &config) + PLOG(logDEBUG) << "RSU status update call at every " << _interval << "seconds!"; + Json::Value rsuStatuJson; + //Sending RSU SNMP call for each field as each field has its own OID. + for_each(_rsuOIDConfigMap.begin(), _rsuOIDConfigMap.end(), [this, &rsuStatuJson](RSUOIDConfig &config) { try { - Json::Value rsuStatuJson; - PLOG(logINFO) << "SNMP RSU status call for field:"<< config.field << ", OID: " << config.oid << " RSU IP: " << _rsuIp << ", RSU port: " << _snmpPort << ", User: " << _securityUser << ", auth pass phrase: " << _authPassPhrase; + PLOG(logINFO) << "SNMP RSU status call for field:"<< config.field << ", OID: " << config.oid; snmp_response_obj responseVal; if(_snmpClientPtr != nullptr) { @@ -104,16 +105,22 @@ namespace RSUHealthMonitor { string response_str(responseVal.val_string.begin(), responseVal.val_string.end()); rsuStatuJson[config.field] = response_str; - } - Json::FastWriter fasterWirter; - string json_str = fasterWirter.write(rsuStatuJson); - PLOG(logINFO) << "SNMP Response: "<< json_str; + } } } catch (std::exception &ex) { PLOG(logERROR) << "SNMP call failure due to: " << ex.what(); } }); + //Broadcast the RSU status info when there are any RSU responses. + if (!rsuStatuJson.empty()) + { + Json::FastWriter fasterWirter; + string json_str = fasterWirter.write(rsuStatuJson); + tmx::messages::RSUStatusMessage sendRsuStatusMsg; + sendRsuStatusMsg.set_contents(json_str); + BroadcastMessage(sendRsuStatusMsg); + } this_thread::sleep_for(chrono::seconds(_interval)); } } diff --git a/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUHealthMonitorPlugin.h b/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUHealthMonitorPlugin.h index cba7d517b..1132945ce 100755 --- a/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUHealthMonitorPlugin.h +++ b/src/v2i-hub/RSUHealthMonitorPlugin/src/RSUHealthMonitorPlugin.h @@ -9,6 +9,7 @@ #include #include "SNMPClient.h" #include +#include "RSUStatusMessage.h" using namespace tmx::utils; using namespace std;