Yes, threshold script is a better place for this.
If you open hint in editor of threshold script, you'll see:
$1 current DCI value;
$2 threshold value;
$dci this DCI object;
$isCluster true if DCI is on cluster;
$node current node object (null if DCI is not on the node);
$object current object.
So you can use $1 instead of GetDCIValueByDescription($node, dciDescription);, this would give you current value of the DCI.
GetDCIValueByDescription() actually gets previously collected value, when server starts, values for frequently collected DCIs are not cached from database to memory, that's would explain script error.
If you open hint in editor of threshold script, you'll see:
$1 current DCI value;
$2 threshold value;
$dci this DCI object;
$isCluster true if DCI is on cluster;
$node current node object (null if DCI is not on the node);
$object current object.
So you can use $1 instead of GetDCIValueByDescription($node, dciDescription);, this would give you current value of the DCI.
GetDCIValueByDescription() actually gets previously collected value, when server starts, values for frequently collected DCIs are not cached from database to memory, that's would explain script error.