|
1 | 1 | function add_timestamp(tag, timestamp, record) |
2 | | - if record["@timestamp"] == nil then |
3 | | - local seconds = timestamp[1] |
4 | | - local formatted_time = os.date("!%Y-%m-%dT%H:%M:%S", seconds) .. string.format(".%03dZ", timestamp[2]/1000000) |
5 | | - record["@timestamp"] = formatted_time |
| 2 | + |
| 3 | + local event_timestamp = nil |
| 4 | + |
| 5 | + if record["Event"] ~= nil and record["Event"]["System"] ~= nil and |
| 6 | + record["Event"]["System"]["TimeCreated"] ~= nil and |
| 7 | + record["Event"]["System"]["TimeCreated"]["#attributes"] ~= nil and |
| 8 | + record["Event"]["System"]["TimeCreated"]["#attributes"]["SystemTime"] ~= nil then |
| 9 | + |
| 10 | + event_timestamp = record["Event"]["System"]["TimeCreated"]["#attributes"]["SystemTime"] |
| 11 | + end |
| 12 | + |
| 13 | + |
| 14 | + if record["@timestamp"] == nil and record["timestamp"] ~= nil then |
| 15 | + event_timestamp = record["timestamp"] |
| 16 | + record["timestamp"] = nil |
| 17 | + end |
| 18 | + |
| 19 | + if event_timestamp ~= nil and event_timestamp ~= "" then |
| 20 | + record["@timestamp"] = event_timestamp |
| 21 | + else |
| 22 | + if record["@timestamp"] == nil then |
| 23 | + local seconds = math.floor(timestamp) |
| 24 | + local nanoseconds = (timestamp - seconds) * 1e9 |
| 25 | + local milliseconds = math.floor(nanoseconds / 1e6) |
| 26 | + local formatted_time = os.date("!%Y-%m-%dT%H:%M:%S", seconds) .. string.format(".%03dZ", milliseconds) |
| 27 | + record["@timestamp"] = formatted_time |
| 28 | + end |
6 | 29 | end |
7 | 30 |
|
8 | 31 | return 1, timestamp, record |
|
0 commit comments