Time in a Trigger (tip)

triggers

#1

If you want the current time in a trigger, use the getTimestampMSec() function.

Sample Trigger

Note: for testing purposes, this trigger is hooked to the DNS_Request event.

var qname = DNS.qname;    // get the DNS query

var Msec = getTimestampMSec();    // get time since epoch in ms
var Sec = new Date ( Msec ).toString();    // convert to human readable string

// same as above, but in one line
var SecOther = new Date (  getTimestampMSec() ).toString();

// dump the output
debug (qname + " : "
    + "Msec=" + Msec + " : "
    + "Sec=" + Sec + " : "
    + "SecOther=" + SecOther + " : "
);  

Output

After assigning this trigger to a device and making a DNS lookup from that device, here is what I will see in the Runtime Log for the trigger:

Mon Jan 07 09:47:54
forum.extrahop.com : Msec=1357580874832 : Sec=Mon Jan 07 2013 09:47:54 GMT-0800 (PST) : SecOther=Mon Jan 07 2013 09:47:54 GMT-0800 (PST) :