alarmserver icon indicating copy to clipboard operation
alarmserver copied to clipboard

BUG: 'parsing time "2024-05-01T15:36:59" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "Z07:00"'

Open surdaft opened this issue 1 year ago • 1 comments

I am trying to use the alarmserver with an Annke NVR which returns an event struct like this:

Content-Type: application/xml; charset="UTF-8"
Content-Length: 461

<EventNotificationAlert version="1.0" xmlns="http://www.std-cgi.com/ver20/XMLSchema">
<ipAddress>xxx.xxx.x.xxx</ipAddress>
<portNo>80</portNo>
<protocol>HTTP</protocol>
<macAddress>xx:xx:xx:xx:xx:xx</macAddress>
<channelID>0</channelID>
<dateTime>2024-05-02T09:43:06</dateTime>
<activePostCount>0</activePostCount>
<eventType>videoloss</eventType>
<eventState>inactive</eventState>
<eventDescription>videoloss alarm</eventDescription>
</EventNotificationAlert>

The issue is when the alarmserver comes to unmarshal the XML it fails at the timestamp due to the missing timezone tag - hence the cannot parse "" as "Z07:00"

Reading this article it looks as though we can just create our own Time struct which can handle the format we want to parse. Allowing for a config option to override the default. Eg;

hikvision:
  enabled: true
  cams:
    xx:
      address: xx.xx.xx.xx
      username: xxx
      password: xxx
      event-time-format: 2006-01-02T15:04:05

surdaft avatar May 02 '24 09:05 surdaft