Get current time on asterisk server through ARI

Hi! I wonder if there’s any way (or at least a workaround) to retrieve current time on some asterisk server using ARI.

I am not aware that there is a specific command and I think not even the cli has one (except !date). It’s also not a primary task of a pbx to supply the current time. There are various ways to query the operating system. I think the general approach would be to synchronize every device with a time server. The accuracy should be about 1ms or a little more. So the answer would be: check any device.

That said, I think every Stasis App has timestamps and one can evaluate them.

My only thought is trying to set the value of a variable using System to call the linux date application.

Could you please elaborate on that? I’m new to this, and clarification would be very helpful. I’m in progress of writing a golang app that communicates with asterisk servers via asterisk rest interface provided by this library

Guys, thank you all very much. I finally found a solution to this problem. As it turned out, ARI does offer a way to retrieve current time from asterisk server by pinging it. For more information, follow this link

That’s not really meant for getting the time. It’s just a consequence of the protocol itself, as @EkFudrek mentioned.

I made an incorrect assumption about how dialplan works in this case.

That being said; I found the variable that can be made to return time from the server properly rather than relying on ping.

exten = 24,1,NoOp(Variable Test)
same = n,Set(t=${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})
same = n,NoOp(${t})
    -- Executing [24@6423:1] NoOp("PJSIP/6423-0000001a", "Variable Test") in new stack
    -- Executing [24@6423:2] Set("PJSIP/6423-0000001a", "t=20220919-143923") in new stack
    -- Executing [24@6423:3] NoOp("PJSIP/6423-0000001a", "20220919-143923") in new stack

Why not use EPOCH directly, and avoid the need to parse and account for timezones, and for times duplicated during DST changes.

However the right way of getting time for a modern Linux system is to do an SNTP query or lock a local SNTP daemon to the other system’s time.

I’m going on the assumption they want this to somehow be included in an asterisk log; though if they’re doing call timing then there are more proper ways of doing it.

Not knowing exactly what the goal is I’m just trying to provide a solution that fits their description. They may not be able to do SNTP query and get that data in to where they need it.

Are you saying that you do not know what this is about, but you provide a solution?