Hi!
Actually, there is no write access to mapping tables from NXSL. We can use either persistent storage or custom attributes. Persistent storage record length is limited to 2000 chars and unlimited for custom attributes, so let's use them.
There are two scripts, first one should be set as EPP filter script so it will be executed when event comes:
s = GetCustomAttribute($node, "EventTimestamps");
if (s != NULL and s != "")
{
a = s->split(",");
}
else
{
a = %();
}
if (a->size < 2000) a->append(time());
SetCustomAttribute($node, "EventTimestamps", ArrayToString(a,","));
return true;
Every time when event comes, this script will add unixtime to the custom attribute on the node. There's a limit of 2000 records so that the string won't grow endlessly.
The second script should be executed periodically - we can use script DCI with needed interval, e.g. 1 hour or 24 hours. You can just use interval or you can set cron schedule so that this DCI get's collected at exact moment:
period = 3600 * 24; // in seconds
s = GetCustomAttribute($node, "EventTimestamps");
a2 = %();
now = time();
if (s != NULL and s != "")
{
a = s->split(",");
for (i = a->minIndex; i <= a->maxIndex; i++)
{
if (a[i] > now - period) a2->append(a[i]);
}
}
SetCustomAttribute($node, "EventTimestamps", ArrayToString(a2,","));
return a2->size;
The script goes through all recorded timestamps, throws away those that are older then specified period, saves updated custom attribute and counts the number of records.