DateTime function with timezone

(Chris) #1


is there currently a possibility to add a timezone to the DateTime function ?

in this case i try to montor a file with a date in the filename, but the server is in another Timezone.
The monitoring checks the last write to a file (to check if a application is dead).

Here my example:

vars.someattribute = {{ return "C:\\folder\\log\\filename_" + DateTime().format("%Y-%m-%d") + ".log" }}

Is there currently a possibility to do this?

I did not find anything in the docs about this:

Would it be better to create a feature request ?

Regards & Thanks


You can print the timezone using “%z” but you can not change it.

<11> => DateTime().format("%H:%m%z")

(Michael Friedrich) #3

This won’t work reliably, since the custom attribute is evaluated on the master/satellite, and not the agent which actually executes the check. So you’ll need to know about the agent’s timezone in advance and construct a suitable DateTime object exclusively for this agent host and timezone (which won’t work since the constructor cannot provide such an offset). The relevant code parts are located here: in case you want to look into a patch here.