<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Bug in DCI Data Recalculation when using relative periods and NXSL time() func.]]></title><description><![CDATA[<p dir="auto">Dear NetXMS team,</p>
<p dir="auto">I seem to have found a scenario related to <em>DCI Data Recalculation</em>, during which the server (Version 3.2-400) does not behave as expected. The scenario is as follows:</p>
<p dir="auto">For some of my DCIs I use secondary DCIs, which feature a longer retention period and a bigger polling interval, to avoid storing data with fine granularity over a long period of time.</p>
<p dir="auto">These secondary DCIs use different aggregation scripts, based on what kind of data the primary DCI returns. The most common script is a simple average calculation, like this:</p>
<pre><code>return GetAvgDCIValue($node, FindDCIByDescription($node, "gateway.RTT"), time()-3600, time());
</code></pre>
<p dir="auto">You can see that (with a polling interval of 1 hour) the secondary DCI simply returns the average value of the primary DCI for the last hour.</p>
<p dir="auto">This method works perfectly fine, as long as the server is running.</p>
<p dir="auto"><strong>And this is where the problem comes in:</strong></p>
<p dir="auto">If for some reason, the server was down and the secondary DCIs could not poll any data (the primary DCIs still gathers data, as it is coming from a NetXMS Agent, which stores the data on its local DB during server downtime), I want to use the DCI Data Recalculation feature, to recalculate the secondary DCI data, based on the data that the primary DCI could still gather during the downtime via the Agent.</p>
<p dir="auto">However, it seems like the NXSL function <em>time()</em> always returns the actual current timestamp, instead of the timestamp of the value to recalculate.<br />
Just to make it a little clearer: Imagine the current timestamp is <strong>X</strong> and the server should recalculate a DCI value at the timestamp <strong>Y</strong> (with <strong>Y &lt; X</strong>). The transformation script shown above is supposed to calculate the average of the primary DCI for the period of one hour before timestamp <strong>Y</strong> and <strong>not X</strong>.</p>
<p dir="auto">This behavior leads to the situation that for every recalculated value of the secondary DCI, the <em>time()</em> function returns timestamp <strong>X</strong>, meaning the recalculated average value will always be the one for the latest one hour period (relative to <strong>actual</strong> present), which is not correct.</p>
<p dir="auto">One way I could see to resolve this problem is to have an option for the DCI Data Recalculation, which makes the server always take the timestamp of the value that is currently being recalculated and (temporarily) set this as the current timestamp, which will then be returned by the <em>time()</em> function, just for the process of data recalculation.</p>
<p dir="auto">Additionally, I could also think of an option, which allows to "fill gaps" in the data (e.g. caused by server downtime). Maybe by checking the polling interval and generating the missing values. If no RAW values are present, the transformation script could still be executed. For a script like the one above, this would still return values to the final data.</p>
<p dir="auto">Hopefully, these thoughts will be helpful to you.</p>
<p dir="auto">Thank you and kind regards,<br />
fbu</p>
]]></description><link>https://forum.netxms.org/topic/6505/bug-in-dci-data-recalculation-when-using-relative-periods-and-nxsl-time-func.</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Nov 2026 14:04:31 GMT</lastBuildDate><atom:link href="https://forum.netxms.org/topic/6505.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 24 Apr 2020 10:27:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Bug in DCI Data Recalculation when using relative periods and NXSL time() func. on Tue, 05 May 2020 07:51:34 GMT]]></title><description><![CDATA[<p dir="auto">While this approach is certainly an alternative to mine, it does not help with the core problem, which is the DCI Data Recalculation:</p>
<p dir="auto">Unfortunately, you cannot pass a <em>timestamp</em> parameter the functions <strong>PushDCIData</strong>, which could define where to put the new value in the DCI table. Therefore, it will always put the new value to the <em>actual current timestamp</em>.</p>
<p dir="auto">When looking at the sourcecode, I would see the following location, at which this problem could be addressed:</p>
<p dir="auto">In line 114 of <em>src/server/core/dci_recalc.cpp</em>, the <em>recalculateValue(value)</em> function is called, which calls the function <em>transform(value, elapsedTime)</em> in line 2151 of <em>src/server/core/dcitem.cpp</em>.<br />
In this function, in <strong>line 999</strong> of the same file (<em>dcitem.cp</em>p), a <strong>ScriptVMHandle</strong> object is created, using the function <strong>CreateServerScriptVM(...)</strong>. This function <em>CreateServerScriptVM(...)</em> could have an optional <em>timestamp parameter</em>, which would tell the script VM to simulate an execution at the given point in time, defined by the given parameter.</p>
<p dir="auto">The value for this timestamp parameter could be extracted from the <em>ItemValue &amp;value</em> (which is the current DCI value to be recalculated) of the calling function, using <em>value.getTimeStamp()</em>.</p>
<p dir="auto">This approach, however, would require refactoring the implementation of NXSL functions, like <em>time()</em>, <em>GetDCIValue(...)</em> or <em>GetDCIRawValue(...)</em> as their behavior should then be adapted, accordingly.</p>
<p dir="auto">(I'm sorry, if I have some weird ideas, which might sound reasonable to me but not for others  ;D)</p>
]]></description><link>https://forum.netxms.org/post/27817</link><guid isPermaLink="true">https://forum.netxms.org/post/27817</guid><dc:creator><![CDATA[fbu]]></dc:creator><pubDate>Tue, 05 May 2020 07:51:34 GMT</pubDate></item><item><title><![CDATA[Reply to Bug in DCI Data Recalculation when using relative periods and NXSL time() func. on Thu, 30 Apr 2020 21:05:58 GMT]]></title><description><![CDATA[<p dir="auto">Not sure, if that approach would suit your situation, but here's an alternative</p>
<p dir="auto">DCI object has attribute lastPollTime. That's the time stamp of last time that DCI got data. You can read this value in transformation script of your "primary" DCI. When delayed data would be coming to the server, this attribute will show correct timestamp of each incoming datapoint.</p>
<p dir="auto">The idea is that you can configure your "secondary" DCIs as push DCIs. And implement the logic in the transformation script of the "primary" DCI.</p>
<p dir="auto">E.g. if a new hour has started, you can calculate the average of the "primary" DCI and push it to the "secondary". Some more logic requred to do it only once - you can use a custom attribute and store last time there.</p>
]]></description><link>https://forum.netxms.org/post/27807</link><guid isPermaLink="true">https://forum.netxms.org/post/27807</guid><dc:creator><![CDATA[Filipp Sudanov]]></dc:creator><pubDate>Thu, 30 Apr 2020 21:05:58 GMT</pubDate></item></channel></rss>