Automic Workload Automation

  • 1.  Built-in AE epoch time function?

    Posted Sep 17, 2015 06:36 PM
    Hi all,

    We are looking for a built-in epoch time function, which would make our lives so much easier. 

    Brief usecase:
    Job runs once a minute to check numerous host's health. If health is not good, it should perform some reactive processing to restore health which includes many host reboots.

    BUT:
    • reactive processing should never occur more than once in 15 minute period
    • reactive processing should never occur more than twice in 60 minute period
    For this reason, we need to track the last time reactive processing has taken place, and compare to current time if we are about to try reactive processing again. epoch would make this a very simple numeric comparison. e.g.:
    current_epoch - last_epoch < 900 = ABORT
    The above doesn't care about hour/day barriers, which is why it rocks.

    With the time and date functions we see documented, calculating the difference in time becomes a much larger task. Are we just missing the function that takes two timestamps (that includes date & time) and can output the difference in minutes?

    With what we see, we could capture time and date separately, then make use of the two DIFF* functions, but then we're forced to considering these pieces of time information individually, which is bad. What happens when we cross day/time barriers? Like if the last execution occurred at 23:55, and it's now 00:05 on the next day. We need to make sense of what the last and current date is, and make sense of the last and current times, and eventually arrive at it being only a 10 minute difference. That would take numerous IFs and well thought out logic. The more we looked at it, the more pitfalls we found that needed consideration. So we're thinking there must be a better way, right?

    So firstly, we're not overlooking an epoch function, right? If that doesn't exist, has anyone here had to build time logic like this? Is this sort of time dependency built in somewhere else?

    One alternative we're looking at is building a separate agent-reliant JOBS to run an epoch command, output, PREP_PROCESS_REPORT, capture in a VARA, etc... but shouldn't this just be natively available in the application? We also found PREP_PROCESS which is really cool but still reliant on an agent to get a simple epoch timestamp which isn't ideal. The JOBS route at least supports a HOSTG so that is covered, but takes quite a bit of work just to get one CLI line output into a variable in AE script. PREP_PROCESS maybe shines here, but does not accept a HOSTG, so we should really do a PREP_PROCESS_AGENTGROUP first to cover our bases and to make sure we're selecting a host that is not offline/being rebooted (see usecase statement above).

    BTW, wasn't it possible in Application Manager to build little modules that would run against the core host's OS at job runtime?  Of course these modules would need to be tightly controlled, but something like this would be really cool:
    :SET &EPOCH# = USER_DEFINED_GET_EPOCH_TIME_MODULE()
    We are on Automation Engine v9 sp8.


  • 2.  Built-in AE epoch time function?

    Posted Sep 17, 2015 06:57 PM
    Maybe use ADD_TIMESTAMP() to advance it to the next-allowed-start-time before doing a comparison?


  • 3.  Built-in AE epoch time function?

    Posted Sep 18, 2015 10:37 AM
    Hi Pete,

    It wasn't getting two timestamps that was the issue , but rather doing logical comparisons with the string-style outputs all the functions use, which is why I thought epoch would be nice. I was actually looking at SUB_TIMESTAMP, but ADD_TIMESTAMP would work, too. However, the output format for these is "YYYY-MM-DD HH:MM:SS," which does not suggest you can do numeric logic comparisons.

    However, I've just made surprising discovery. You can apparently compare the string formatted date/time outputs with an IF, and Automic does make sense of it! It didn't even occur to me to try based on the format.

    For example, this code:
    :SET &CURRENT_TIME# = SYS_TIMESTAMP_PHYSICAL("TZ.EASTERN")
    :SET &LAST_SWAP_TIME# = SUB_TIMESTAMP(&CURRENT_TIME#,"00:10:00")  
    :IF &CURRENT_TIME# > &LAST_SWAP_TIME#
    :  P 'current time greater than last swap time'
    :ELSE
    :  P 'current time NOT greater than last swap time'
    :ENDIF

    Will output this:
    2015-09-18 09:44:10 - U0020408 current time: 2015-09-18 09:44:10 2015-09-18 09:44:10 - U0020408 last swap time: 2015-09-18 09:34:10 2015-09-18 09:44:10 - U0020408 current time greater than last swap time
    I'm going to do more testing to make sure it's computing this the way I think/hope, but it looks promising. This being the case, epoch isn't necessary, at least not in my case

    Well this has been a fun learning exercise, thx for reading :blush: 
    ~Eric


  • 4.  Built-in AE epoch time function?

    Posted Sep 18, 2015 10:56 AM
    @Eric Felker - as far as I can tell the comparison of something like two timestamps are purely a character string comparison and I don't think that the variables are considered as anything "special".  This is something that we routinely use to perform logic similar to yours and it has worked reliably (under V8).


  • 5.  Built-in AE epoch time function?

    Posted Sep 18, 2015 01:13 PM
    Mark Hadler said:
    @Eric Felker - as far as I can tell the comparison of something like two timestamps are purely a character string comparison and I don't think that the variables are considered as anything "special".  This is something that we routinely use to perform logic similar to yours and it has worked reliably (under V8).
    Yes, I think you're right, but turns out a string comparison is enough for it to work, as long as it's reliable.  I expected such a comparison to cause an error or behave erratically. Appreciate the confirmation!


  • 6.  Built-in AE epoch time function?
    Best Answer

    Posted Sep 29, 2015 03:36 PM
    BTW, wasn't it possible in Application Manager to build little modules that would run against the core host's OS at job runtime?  Of course these modules would need to be tightly controlled, but something like this would be really cool:
    :SET &EPOCH# = USER_DEFINED_GET_EPOCH_TIME_MODULE()
    A lot of great information resulted from this thread, but Backend variables are the alternative I was initially looking for here!


  • 7.  Built-in AE epoch time function?

    Posted May 03, 2016 06:57 PM
    Hi,
     I was looking for a built in solution and came across this thread. We ended up implementing our own include in client 0. It does require a GMT based timezone (No Daylight Savings Offset as well) and seems to work well so far. You can do a diff date to calculate the number of seconds until 00:00:00 &TODAY#. Then you need to do a second diff on time to get the number of seconds between 00:00:00 and &NOW#. Then put them together and get epoch time.

    :set &sdate#=SYS_DATE("YYYY-MM-DD", 'TZ.GMT.E') :set &stime#=SYS_TIME("HH:MM:SS", 'TZ.GMT.E') :set &daysbetween#=diff_date("YYYY-MM-DD;1970-01-01", "YYYY-MM-DD;&sdate#") !:print &daysbetween# days between today and 01/01/1970 :set &daysec#=mult(&daysbetween#,86400) !:print Which equals &daysec# seconds :set &sectoday#=diff_time("HH:MM:SS;&stime#","000000","SS") !:print Seconds today is &sectoday# :set &CURRENT_EPOCH_TIME#=add(&daysec#,&sectoday#) !:print Epoch is &epoch#

    In your workflow you can use the &CURRENT_EPOCH_TIME# variable.