laura_albrecht_automic

Multiple PREP_PROCESS_VARs

Discussion created by laura_albrecht_automic on Aug 17, 2016
Latest reply on Aug 18, 2016 by Wolfgang_Brueckler_1288
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#

Outcomes