transformation script input value always have same data type as DCI (issue #NX-1361)
authorVictor Kirhenshtein <victor@netxms.org>
Wed, 22 Nov 2017 16:58:23 +0000 (18:58 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Wed, 22 Nov 2017 16:58:23 +0000 (18:58 +0200)
ChangeLog
src/server/core/dcitem.cpp
src/server/include/nms_dcoll.h

index d99d9ca..dd18154 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,7 +16,7 @@
 - Option to read log files using VSS snapshots on Windows
 - Per stage confirmation in database manager during database check
 - Fixed file download cancelation
-- Fixed issues: NX-662, NX-703, NX-1045, NX-1201, NX-1268, NX-1339, NX-1341, NX-1342, NX-1343, NX-1344
+- Fixed issues: NX-662, NX-703, NX-1045, NX-1201, NX-1252, NX-1268, NX-1339, NX-1341, NX-1342, NX-1343, NX-1344, NX-1361
 
 
 *
index 7416779..4961795 100644 (file)
@@ -902,7 +902,8 @@ bool DCItem::transform(ItemValue &value, time_t nElapsedTime)
       NXSL_VM *vm = new NXSL_VM(new NXSL_ServerEnv());
       if (vm->load(m_transformationScript))
       {
-         NXSL_Value *pValue = new NXSL_Value((const TCHAR *)value);
+         NXSL_Value *nxslValue = new NXSL_Value(value.getString());
+         nxslValue->convert(getNXSLDataType()); // make sure that input NXSL variable type is the same as DCI type
          vm->setGlobalVariable(_T("$object"), m_owner->createNXSLObject());
          if (m_owner->getObjectClass() == OBJECT_NODE)
          {
@@ -913,32 +914,32 @@ bool DCItem::transform(ItemValue &value, time_t nElapsedTime)
 
          // remove lock from DCI for script execution to avoid deadlocks
          unlock();
-         success = vm->run(1, &pValue);
+         success = vm->run(1, &nxslValue);
          lock();
          if (success)
          {
-            pValue = vm->getResult();
-            if (pValue != NULL)
+            nxslValue = vm->getResult();
+            if (nxslValue != NULL)
             {
                switch(m_dataType)
                {
                   case DCI_DT_INT:
-                     value = pValue->getValueAsInt32();
+                     value = nxslValue->getValueAsInt32();
                      break;
                   case DCI_DT_UINT:
-                     value = pValue->getValueAsUInt32();
+                     value = nxslValue->getValueAsUInt32();
                      break;
                   case DCI_DT_INT64:
-                     value = pValue->getValueAsInt64();
+                     value = nxslValue->getValueAsInt64();
                      break;
                   case DCI_DT_UINT64:
-                     value = pValue->getValueAsUInt64();
+                     value = nxslValue->getValueAsUInt64();
                      break;
                   case DCI_DT_FLOAT:
-                     value = pValue->getValueAsReal();
+                     value = nxslValue->getValueAsReal();
                      break;
                   case DCI_DT_STRING:
-                     value = CHECK_NULL_EX(pValue->getValueAsCString());
+                     value = CHECK_NULL_EX(nxslValue->getValueAsCString());
                      break;
                   default:
                      break;
@@ -974,6 +975,15 @@ bool DCItem::transform(ItemValue &value, time_t nElapsedTime)
 }
 
 /**
+ * Get DCI data type as NXSL data type
+ */
+int DCItem::getNXSLDataType() const
+{
+   static int nxslTypes[] = { NXSL_DT_INT32, NXSL_DT_UINT32, NXSL_DT_INT64, NXSL_DT_UINT64, NXSL_DT_STRING, NXSL_DT_REAL, NXSL_DT_NULL };
+   return ((m_dataType >= 0) && (m_dataType < sizeof(nxslTypes) / sizeof(int))) ? nxslTypes[m_dataType] : NXSL_DT_STRING;
+}
+
+/**
  * Set new ID and node/template association
  */
 void DCItem::changeBinding(UINT32 dwNewId, Template *pNewNode, BOOL doMacroExpansion)
index 1a0871a..f8a5750 100644 (file)
@@ -395,6 +395,7 @@ public:
    void reloadCache();
 
    int getDataType() const { return m_dataType; }
+   int getNXSLDataType() const;
        bool isInterpretSnmpRawValue() const { return (m_flags & DCF_RAW_VALUE_OCTET_STRING) ? true : false; }
        WORD getSnmpRawValueType() const { return m_snmpRawValueType; }
        bool hasActiveThreshold();