Automic Workload Automation

Expand all | Collapse all

Multiple PREP_PROCESS_VARs

  • 1.  Multiple PREP_PROCESS_VARs

    Posted Aug 17, 2016 09:30 AM
    Hi.  I'm fairly good at scripting, but nested PREP_PROCESS_VARs I find confusing.   :/

    I am trying to implement a process that I can run via a time event every 15 minutes checking the status of agents.  If an agent is down - I want to automatically restart it.  

    However, I also want the ability to have an exception list.  For example, I might be doing maintenance on a server and I don't want that agent to be restarted every 15 minutes.  

    So that's my scenario.

    But  I'm having problems with the fact that I'm comparing one variable (list of all agents) to the contents of another variable (list of agents to ignore).  I'm sure this is a simple fix, but I've been working on this most of yesterday afternoon and this morning and tried a variety of things and I just can't get this to work.

    Or let me rephrase - my current code works fine IF I only have 1 entry in my exception list.  If I have multiple - it doesn't work.

    Any scripting gurus out there have time to take a look at this?



    ! *************************************************************************************
    ! ***                                                                               ***
    ! ***  This routine is used to check for agents that are down and restart them.     ***
    ! ***                                                                               ***
    ! *************************************************************************************
    ! Get a dynamic list of agents by querying the database.

    :SET &HNDA# = PREP_PROCESS_VAR(SYSTEM.X.LIST_OF_AGENTS.VARA.X)
    :PROCESS &HNDA#
    ! Check to see if the agent is up or down
    :  SET &AGENT_NAMEA# = GET_PROCESS_LINE(&HNDA#, 2)
    :  SET &FOUND# = ''
    :  IF SYS_HOST_ALIVE(&AGENT_NAMEA#)= 'Y'
    :    PRINT '&AGENT_NAMEA# is alive!'
    :  ELSE
    ! Need to check if the down agent is on the exclusion list.
    :    PRINT ''
    :    PRINT '&AGENT_NAMEA# appears to be down!'
    :    SET &HNDB# = PREP_PROCESS_VAR(ESP.MONITORING.AGENT_EXCEPTION_LIST.VARA.X)
    !
    ! There will always be an entry in the Exception List variable so that it enters the 
    ! PREP_PROCESS_VAR loop.
    !
    :    PROCESS &HNDB#
    :      SET &FOUND# = GET_PROCESS_LINE(&HNDB#, 1)
    !
    ! If it finds the dummy entry do nothing.
    !
    :      IF &FOUND# = 'DO NOT REMOVE'
    :      ELSE
    :        PRINT '&FOUND# seems to be from the exception list variable.'
    :      ENDIF
    !
    ! If the entry on the exception list matches one of the down agents then no
    ! restart will be done.
    !
    :      IF &FOUND# = &AGENT_NAMEA#
    :        PRINT 'Since &AGENT_NAMEA# is on the exception list - we will not attempt to restart it.'
    :        PRINT ''
    :      ELSE
    !
    ! If it finds the dummy entry do nothing.
    !
    :        IF &FOUND# = 'DO NOT REMOVE'
    !
    ! If it is not on the exception list - then attempt to restart it.
    !
    :        ELSE
    :          PRINT ''
    :          PRINT '&AGENT_NAMEA# is down - attempting to restart.'
    :          PRINT ''
    :          SET &AGENT_TYPE# = GET_PROCESS_LINE(&HNDA#, 5)
    :          SET &SERVICE_MGR_NAME# = GET_PROCESS_LINE(&HNDA#, 4)
    :          IF &AGENT_TYPE# <> 'WINDOWS' OR 'UNIX'
    :            SET &AGENT_NAMEA# = GET_VAR(SYSTEM.X.AGENT_SERVER_INFO.VARA.X, '&AGENT_NAMEA#', 2)
    :          ENDIF
    :          PUBLISH &AGENT_NAMEA#, , TASK
    :          PUBLISH &AGENT_TYPE#, , TASK
    :          PUBLISH &SERVICE_MGR_NAME#, , TASK
    :          SET &ALIAS# = 'ESP.MONITORING.AGENT_STATUS_&AGENT_NAMEA#.JOBS.U'
    :          SET &ACTOBJ# = ACTIVATE_UC_OBJECT(ESP.MONITORING.AGENT_RESTART.JOBS.U, , , , , PASS_VALUES, , &ALIAS#)
    :        ENDIF
    :      ENDIF
    :    ENDPROCESS
    :    CLOSE_PROCESS &HNDB#
    :  ENDIF
    :ENDPROCESS
    :CLOSE_PROCESS &HNDA#


  • 2.  Multiple PREP_PROCESS_VARs

    Posted Aug 17, 2016 09:47 AM
    How about using EXECUTE_ON_END, EXECUTE_ON_LOST and EXECUTE_ON_START in Client 0 instead of polling every 15 minutes?

    6pypxv8xdymp.pnghttps://us.v-cdn.net/5019921/uploads/editor/pl/6pypxv8xdymp.png" width="627">



  • 3.  Multiple PREP_PROCESS_VARs

    Posted Aug 17, 2016 10:13 AM
    Hi Laura,
    I'll try this at my end and get back to you soon.
    BR,
    Antoine


  • 4.  Multiple PREP_PROCESS_VARs

    Posted Aug 17, 2016 10:18 AM
    Could you post a screenshot of the ESP.MONITORING.AGENT_EXCEPTION_LIST.VARA.X object's content?



  • 5.  Multiple PREP_PROCESS_VARs

    Posted Aug 17, 2016 10:24 AM
    I would also need a screenshot of SYSTEM.X.AGENT_SERVER_INFO.VARA.X .

    BR,
    Antoine



  • 6.  Multiple PREP_PROCESS_VARs

    Posted Aug 17, 2016 10:35 AM
    I had to create the AGENT_SERVER_INFO variable because my RA agents don't have the server names as the agent names.  I posted something else on how to find that out, but this was best I could do for now.

    hh87jblwqbg4.pnghttps://us.v-cdn.net/5019921/uploads/editor/h3/hh87jblwqbg4.png" width="948">


  • 7.  Multiple PREP_PROCESS_VARs

    Posted Aug 17, 2016 11:04 AM
    Laura:

    A cursory view of the logic ensuring that all of the IF/ELSE/ENDIF sets are "closed" as are the PREP_PROCESS_VAR sets, looks good to me.  I have occasionally encountered situations where a missing ENDIF was not detected and I got spurious and difficult to diagnose results.

    If it were me, I'd use the Execute once dialog and trace the activation protocol to see the logic path being executed.  Also I might place some type of debug statements, such as PRINT statements or a loop counter of some type to see how many times that the inner process is executed and what it finds with each keyword and value.

    For what it's worth we have a small number of PREP_PROCESS_VAR pieces of logic that are nested, similar to yours, under our V8 system and they operate properly.

    Good luck and if I think of anything else I'll chime in again.


  • 8.  Multiple PREP_PROCESS_VARs

    Posted Aug 18, 2016 03:43 AM

    Another suggestion - maybe easier :-)

    What about using a VARA.MULTI object for Agent exclusion?

     

    I did a short example, created a VARA.SQLi listing ALL defined agents ignoring limitations in HACL for other clients):

    select * from OH

    where oh_otype='HOST'

    and oh_idnr >100000

     

    and a static VARA containing my Agents to exclude: WIN03 and WIN04 (black circle)

     

    Both VARAs are source of my VARA.multi - Difference (red circle)

     

     

    here the screenshot:
    ffw99w76u6d7.pnghttps://us.v-cdn.net/5019921/uploads/editor/dg/ffw99w76u6d7.png" width="1166">

    All Agents of my Clt1 system overview in blue.

    Possibly that helps.


  • 9.  Multiple PREP_PROCESS_VARs

    Posted Aug 18, 2016 06:50 AM

    Hello,

    Just two general hints:

    •  A sql select of current objects should always have an „oh_deleteflag = 0“in it. So it should look like:

     

    select * from OH

    where oh_otype='HOST'

    and oh_idnr > 100000

    and oh_deleteflag = 0

     

     

    • Another way to get all Agents of a system by PREP_PROCESS_VAR is:

    :set &hnd# = PREP_PROCESS_VAR(UC_EX_HOSTCHAR,,) :process &hnd# :  set &Agent_Name# = GET_PROCESS_LINE(&hnd#,1) :  print &Agent_Name# :endprocess

    KR, Josef




  • 10.  Multiple PREP_PROCESS_VARs

    Posted Aug 18, 2016 08:07 AM
    and oh_deleteflag = 0

    ..oops forgotten ..
    THX Josef :-)



  • 11.  Multiple PREP_PROCESS_VARs

    Posted Aug 18, 2016 08:36 AM
    FrankMuffke  - thank you SOO much!  What a wonderful idea!  I am still trying to have new functionality like this come to mind when I run into challenges like this.  Using the MULTI variable worked amazingly well.  I cut down my code considerably.

    :SET &HNDA# = PREP_PROCESS_VAR(ESP.MONITORING.EXCLUDE_AGENTS_ON_EXCEPTION_LIST.VARA.X)
    :PROCESS &HNDA#
    :  SET &AGENT_NAMEA# = GET_PROCESS_LINE(&HNDA#,2)
    :  IF SYS_HOST_ALIVE(&AGENT_NAMEA#)= 'Y'
    :    PRINT '&AGENT_NAMEA# is alive!'
    :  ELSE
    :    PRINT ''
    :    PRINT '&AGENT_NAMEA# is down - attempting to restart.'
    :    PRINT ''
    :    SET &AGENT_TYPE# = GET_PROCESS_LINE(&HNDA#,5)
    :    SET &SERVICE_MGR_NAME# = GET_PROCESS_LINE(&HNDA#,4)
    :    IF &AGENT_TYPE# <> 'WINDOWS' OR 'UNIX'
    :      SET &AGENT_NAMEA# = GET_VAR(SYSTEM.X.AGENT_SERVER_INFO.VARA.X,'&AGENT_NAMEA#',2)
    :    ENDIF
    :    PUBLISH &AGENT_NAMEA#,,TASK
    :    PUBLISH &AGENT_TYPE#,,TASK
    :    PUBLISH &SERVICE_MGR_NAME#,,TASK
    :    SET &ALIAS#  = 'ESP.MONITORING.RESTART_DOWN_AGENT_&AGENT_NAMEA#.JOBS.U'
    :    SET &ACTOBJ# = ACTIVATE_UC_OBJECT(ESP.MONITORING.RESTART_DOWN_AGENT.JOBS.U,,,,,PASS_VALUES, , &ALIAS#)
    :  ENDIF
    :ENDPROCESS
    :CLOSE_PROCESS &HNDA#



    Thanks for everyone's ideas / help!




  • 12.  Multiple PREP_PROCESS_VARs

    Posted Aug 18, 2016 08:40 AM
    No problem - great that it works well now :-)


  • 13.  Multiple PREP_PROCESS_VARs

    Posted Aug 18, 2016 09:17 AM
    Is this something you think I should attach as an export?  Or put in the Marketplace?  I know there is an Agent Restarter process there, but mine is slightly different - it restarts ALL down agents (minus the ones on the exception list).  The other one gives you the option to select which ones.  Both have their uses.  I wasn't sure if anyone would be interested in mine though.  If anyone is - let me know.


  • 14.  Multiple PREP_PROCESS_VARs

    Posted Aug 18, 2016 09:27 AM
    Possibly I would be great adding an XML export of it to this thread.
    (Including AE Version :-) )