[ZBXNEXT-3899] Possibility to convert SNMP DateandTime to Timestamp in Preprocessing Created: 2017 May 30  Updated: 2022 Nov 09

Status: Open
Project: ZABBIX FEATURE REQUESTS
Component/s: Frontend (F), Server (S)
Affects Version/s: 3.4 (plan)
Fix Version/s: None

Type: New Feature Request Priority: Major
Reporter: Kay Schroeder Assignee: Unassigned
Resolution: Unresolved Votes: 5
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

We have several systems with SNMP-Values of octetstring, formatted in a special manner for Date and Time:

ateAndTime ::= TEXTUAL-CONVENTION
DISPLAY-HINT "2d-1d-1d,1d:1d:1d.1d,1a1d:1d"
STATUS current
DESCRIPTION
"A date-time specification.

field octets contents range
----- ------ -------- -----
1 1-2 year 0..65536
2 3 month 1..12
3 4 day 1..31
4 5 hour 0..23
5 6 minutes 0..59
6 7 seconds 0..60
(use 60 for leap-second)
7 8 deci-seconds 0..9
8 9 direction from UTC '+' / '-'
9 10 hours from UTC 0..11

10 11 minutes from UTC 0..59

For example, Tuesday May 26, 1992 at 1:30:15 PM EDT would be
displayed as:

1992-5-26,13:30:15.0,-4:0

Note that if only local time is known, then timezone
information (fields 8-10) is not present."
SYNTAX OCTET STRING (SIZE (8 | 11))

For us it is useful to get this converted into a timestamp so that we can work with several trigger functions. I know about the new feature of preprocessing and I think this functionality could be a good additional feature to have it implemented.

Kind Regards,
Kay



 Comments   
Comment by alex dekker [ 2017 May 31 ]

This would be useful for dealing with snapshot age on HP SANs.

Comment by Glebs Ivanovskis (Inactive) [ 2017 Jun 05 ]

Would be nice if you pointed us to the format specification.

Comment by Kay Schroeder [ 2017 Jul 08 ]

Glebs, the syntax above should be the general syntax and should work in general.

Comment by Marc [ 2017 Jul 08 ]

Sounds rather like a use case for ZBXNEXT-3508 to me.

Comment by alex dekker [ 2017 Oct 05 ]

Glebs, format specification is in RFC2579 p18.

Comment by David Collier [ 2021 Jan 15 ]

Is this feature being worked on? We have exactly the same requirement for handling Date / Time fields returned as STRING variables from SNMP agent items.

Comment by Malcolm [ 2021 Jun 11 ]

For anyone still looking for a solution, the below can be thrown into a Javascript preprocessing rule to create a unixtime/epoch timestamp:

p_date =  Date.UTC(
    parseInt("0x" + value.slice(0,2) + value.slice(3,5)),
    parseInt("0x" + value.slice(6,8)),
    parseInt("0x" + value.slice(9,11)),
    parseInt("0x" + value.slice(12,14)),
    parseInt("0x" + value.slice(15,17)),
    parseInt("0x" + value.slice(18,20)),
    parseInt("0x" + value.slice(21,23))
) / 1000

utc_direction = String.fromCharCode(parseInt("0x" + value.slice(24,26))) == '-' ? -1 : 1
p_date += parseInt("0x" + value.slice(27,29)) * 3600 * utc_direction
p_date += parseInt("0x" + value.slice(30,32)) * 60 * utc_direction

return p_date
Comment by Mickael Martin [ 2022 Nov 09 ]

Hello,

I try to use this format to monitor FORTINET-FORTIGATE-MIB::fgHaStatsSyncDatimeUnsucc and FORTINET-FORTIGATE-MIB::fgHaStatsSyncDatimeSucc.

For me, your code is wrong on calculation on month : Date.UTC use an index between 0 and 11 and not 1 to 12. Moreover, you can have this format without UTC direction. So, I propose this fix :

value=value.trim()
p_date =  Date.UTC(
    parseInt("0x" + value.slice(0,2) + value.slice(3,5)),
    parseInt("0x" + value.slice(6,8) -1),
    parseInt("0x" + value.slice(9,11)),
    parseInt("0x" + value.slice(12,14)),
    parseInt("0x" + value.slice(15,17)),
    parseInt("0x" + value.slice(18,20)),
    parseInt("0x" + value.slice(21,23))
) / 1000if (value.length > 23){
utc_direction = String.fromCharCode(parseInt("0x" + value.slice(24,26))) == '-' ? -1 : 1
p_date += parseInt("0x" + value.slice(27,29)) * 3600 * utc_direction
p_date += parseInt("0x" + value.slice(30,32)) * 60 * utc_direction}
return p_date; 

 

Generated at Fri May 02 07:48:00 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.