Support Questions

Find answers, ask questions, and share your expertise

The format of alerts timestamp values in API

avatar
New Contributor

Hi,

I am trying to convert "original_timestamp" into human-friendly format. I suppose the values are presented in UNIX Epoch format but for some reason I cannot convert them to date.

Example:

"Alert" : {
        "cluster_name" : "appslogs",
        "component_name" : "AMBARI_AGENT",
        "definition_id" : 50,
        "definition_name" : "ambari_agent_disk_usage",
        "host_name" : "1516.local.net",
        "id" : 303,
        "instance" : null,
        "label" : "Host Disk Usage",
        "latest_timestamp" : 1459169433304,
        "maintenance_state" : "OFF",
        "original_timestamp" : 1458822573305,
        "scope" : "HOST",
        "service_name" : "AMBARI",
        "state" : "WARNING",
        "text" : "Capacity Used: [70.92%, 5.9 GB], Capacity Total: [8.3 GB], path=/usr/hdp. Total free space is less than 2.0 GB"
      }
btop@gw-01:~$ date -d '@1458822573305'
Sat Mar 31 15:35:05 EEST 48198

Returned date is obviously incorrect.

So the question is: what's a format of presented values? And how to convert it into date?

Looking forward to your response! Thanks!

1 ACCEPTED SOLUTION

avatar
Super Collaborator

Both Unix and Java report epoch from January 1, 1970. However, Unix reports in seconds, while Java reports in milliseconds. The value above is in milliseconds, so you need to divide by 1000:

date -d @1458822573
Thu Mar 24 12:29:33 UTC 2016

View solution in original post

1 REPLY 1

avatar
Super Collaborator

Both Unix and Java report epoch from January 1, 1970. However, Unix reports in seconds, while Java reports in milliseconds. The value above is in milliseconds, so you need to divide by 1000:

date -d @1458822573
Thu Mar 24 12:29:33 UTC 2016