diff --git a/C/plugins/common/include/omf.h b/C/plugins/common/include/omf.h index 14a2a785f1..14622105d8 100644 --- a/C/plugins/common/include/omf.h +++ b/C/plugins/common/include/omf.h @@ -114,6 +114,11 @@ class OMF // Removed mapped object types found in input data void unsetMapObjectTypes(std::map& dataSuperSet) const; + void setStaticData(std::vector> *staticData) + { + m_staticData = staticData; + }; + private: /** * Builds the HTTP header to send @@ -217,6 +222,12 @@ class OMF // Data types cache[key] = (key_type_id, key data types) std::map* m_OMFDataTypes; + /** + * Static data to send to OMF + */ + std::vector> + *m_staticData; + }; /** diff --git a/C/plugins/common/omf.cpp b/C/plugins/common/omf.cpp index be93c571c1..8117fe5bb4 100644 --- a/C/plugins/common/omf.cpp +++ b/C/plugins/common/omf.cpp @@ -806,10 +806,15 @@ const std::string OMF::createTypeData(const Reading& reading) const // Add the Static data part - string tData("[{ \"type\": \"object\", \"properties\": { " -"\"Company\": {\"type\": \"string\"}, \"Location\": {\"type\": \"string\"}, " -"\"Name\": { \"type\": \"string\", \"isindex\": true } }, " -"\"classification\": \"static\", \"id\": \""); + string tData("[{ \"type\": \"object\", \"properties\": { "); + for (auto it = m_staticData->cbegin(); it != m_staticData->cend(); ++it) + { + tData.append("\""); + tData.append(it->first.c_str()); + tData.append("\": {\"type\": \"string\"},"); + } + tData.append("\"Name\": { \"type\": \"string\", \"isindex\": true } }, " + "\"classification\": \"static\", \"id\": \""); // Add type_id + '_' + asset_name + '_typename_sensor' OMF::setAssetTypeTag(reading.getAssetName(), @@ -913,8 +918,16 @@ const std::string OMF::createStaticData(const Reading& reading) const "typename_sensor", sData); - sData.append("\", \"values\": [{\"Location\": \"Palo Alto\", " -"\"Company\": \"Dianomic\", \"Name\": \""); + sData.append("\", \"values\": [{"); + for (auto it = m_staticData->cbegin(); it != m_staticData->cend(); ++it) + { + sData.append("\""); + sData.append(it->first.c_str()); + sData.append("\": \""); + sData.append(it->second.c_str()); + sData.append("\", "); + } + sData.append(" \"Name\": \""); // Add asset_name sData.append(reading.getAssetName()); diff --git a/C/plugins/north/PI_Server_V2/plugin.cpp b/C/plugins/north/PI_Server_V2/plugin.cpp index 966041e7e9..3cb79cc7cc 100644 --- a/C/plugins/north/PI_Server_V2/plugin.cpp +++ b/C/plugins/north/PI_Server_V2/plugin.cpp @@ -125,6 +125,8 @@ typedef struct string producerToken; // PI Server connector token string formatNumber; // OMF protocol Number format string formatInteger; // OMF protocol Integer format + vector> + staticData; // Static data // Errors considered not blocking in the communication with the PI Server std::vector notBlockingErrors; @@ -186,6 +188,8 @@ PLUGIN_HANDLE plugin_init(ConfigCategory* configData) string formatNumber = configData->getValue("formatNumber"); string formatInteger = configData->getValue("formatInteger"); + + /** * Extract host, port, path from URL */ @@ -227,6 +231,30 @@ PLUGIN_HANDLE plugin_init(ConfigCategory* configData) JSONStringToVectorString(connInfo->notBlockingErrors , configData->getValue("notBlockingErrors"), std::string("errors400")); + /** + * Add static data + * Split the string up into each pair + */ + string staticData = configData->getValue("StaticData"); + size_t pos = 0; + size_t start = 0; + do { + pos = staticData.find(",", start); + string item = staticData.substr(start, pos); + start = pos + 1; + size_t pos2 = 0; + if ((pos2 = item.find(":")) != string::npos) + { + string name = item.substr(0, pos2); + while (name[0] == ' ') + name = name.substr(1); + string value = item.substr(pos2 + 1); + while (value[0] == ' ') + value = value.substr(1); + pair sData = make_pair(name, value); + connInfo->staticData.push_back(sData); + } + } while (pos != string::npos); #if VERBOSE_LOG // Log plugin configuration @@ -333,6 +361,7 @@ uint32_t plugin_send(const PLUGIN_HANDLE handle, connInfo->omf->setFormatType(OMF_TYPE_INTEGER, connInfo->formatInteger); + connInfo->omf->setStaticData(&connInfo->staticData); connInfo->omf->setNotBlockingErrors(connInfo->notBlockingErrors); // Send data