NetXMS Support Forum

Development => General => Topic started by: cserzs on February 12, 2022, 08:12:06 PM

Title: How to display duration between trap events?
Post by: cserzs on February 12, 2022, 08:12:06 PM
Hi,

I would like to ask that is there any solution to calculate the elapsed time between a traps pair?
A little more detailed, the problem what I need to solve is the following:
I get a trap about the starting of a signal drop.
From this I generate an event for example with the following text: "Started from 11:00:12 10/02/2020 the RF signal out of tolerance."
When the signal loss ceases (typically max. few minutes), the end-of alarm trap arrives as well. From this I also generate an event that works properly and clears the existing alarm as well.
What I can't solve for the moment is to display the duration of the signal loss (e.g. in seconds) in the end of event text.
Is there any solution to this?
Thank you very much for any suggestions in advance.
Title: Re: How to display duration between trap events?
Post by: Victor Kirhenshtein on February 18, 2022, 05:29:35 PM
Hi,

you can set custom attribute on a node to current time from first event, and for the second event use script macro to read custom attribute value and return the difference with current time. For example:

1. Create script in script library called SetSignalLossTime:

$node->setCustomAttribute(".signalLossTime", time());


2. Create script in script library called GetSignalLossDuration:

t = $node->getCustomAttribute(".signalLossTime");
return (t != null) ? time() - t : 0;


3. Create server action of type script that will execute script SetSignalLossTime.

4. Add action from #3 to EPP rule where you generate alarm for signal loss.

5. In the message template for recovery event add %[GetSignalLossDuration] to insert duration of signal loss.

Best regards,
Victor
Title: Re: How to display duration between trap events?
Post by: cserzs on February 21, 2022, 05:33:45 PM
Hi Victor,

Thank you very much for your detailed support. It works fine.

Best regards, Zsolt