@ -161,8 +161,15 @@ def OrchestratorSessionSave(inGSettings=None): ## Orchestrator session save
if lL : lL . info (
f " Orchestrator has dump the RDP list before the restart. The RDP List is { inGSettings [ ' RobotRDPActive ' ] [ ' RDPList ' ] } " )
return True
#Check is client is has access for the key list
def UACKeyListCheck ( inRequest , inRoleKeyList ) :
return inRequest . UACClientCheck ( inRoleKeyList = inRoleKeyList )
# Update user access
def OrchestratorUACUpdate ( inGSettings , inADLoginStr , inADStr = " " , inADIsDefaultBool = True , inURLList = [ ] , inCPAllowKeyList = [ ] , inRoleHierarchyAllowedDict = { } ) :
def UACUpdate( inGSettings , inADLoginStr , inADStr = " " , inADIsDefaultBool = True , inURLList = [ ] , inCPAllowKeyList = [ ] , inRoleHierarchyAllowedDict = { } ) :
lUserTurple = ( inADStr . upper ( ) , inADLoginStr . upper ( ) ) # Create turple key for inGSettings["Server"]["AccessUsers"]["RuleDomainUserDict"]
if inURLList == [ ] and lUserTurple not in inGSettings [ " Server " ] [ " AccessUsers " ] [ " RuleDomainUserDict " ] : # Backward compatibility if user is not exist
inURLList = [
@ -198,16 +205,19 @@ def OrchestratorUACUpdate(inGSettings, inADLoginStr, inADStr="", inADIsDefaultBo
inGSettings [ " Server " ] [ " AccessUsers " ] [ " RuleDomainUserDict " ] . update ( { ( " " , inADLoginStr . upper ( ) ) : lRuleDomainUserDict } )
# Add supertoken for the all access (it is need for the robot communication without human)
def Orchestrator UACSuperTokenUpdate( inGSettings , inSuperTokenStr ) :
def UACSuperTokenUpdate( inGSettings , inSuperTokenStr ) :
lLoginStr = " SUPERTOKEN "
Orchestrator UACUpdate( inGSettings = inGSettings , inADLoginStr = lLoginStr )
UACUpdate( inGSettings = inGSettings , inADLoginStr = lLoginStr )
inGSettings [ " Server " ] [ " AccessUsers " ] [ " AuthTokensDict " ] . update (
{ inSuperTokenStr : { " User " : lLoginStr , " Domain " : " " , " TokenDatetime " : datetime . datetime . now ( ) , " FlagDoNotExpire " : True } }
)
# OrchestratorWEB
# # # # # # # # # # # # # # # # # # # # # # #
# OrchestratorWeb defs
# # # # # # # # # # # # # # # # # # # # # # #
# Add control panel HTML, JSON generator or JS when page init
def OrchestratorWebCPUpdate ( inGSettings , inCPKeyStr , inHTMLRenderDef = None , inJSONGeneratorDef = None , inJSInitGeneratorDef = None ) :
def WebCPUpdate( inGSettings , inCPKeyStr , inHTMLRenderDef = None , inJSONGeneratorDef = None , inJSInitGeneratorDef = None ) :
# Create Struct if the re is current key
if inCPKeyStr not in inGSettings [ " CPDict " ] :
inGSettings [ " CPDict " ] [ inCPKeyStr ] = { " HTMLRenderDef " : None , " JSONGeneratorDef " : None , " JSInitGeneratorDef " : None }
@ -221,6 +231,16 @@ def OrchestratorWebCPUpdate(inGSettings, inCPKeyStr, inHTMLRenderDef=None, inJSO
if inJSInitGeneratorDef is not None :
inGSettings [ " CPDict " ] [ inCPKeyStr ] [ " JSInitGeneratorDef " ] = inJSInitGeneratorDef
# Return User info about request Return {"DomainUpperStr":"", "UserNameUpperStr": ""}
def WebUserInfoGet ( inRequest ) :
lDomainUpperStr = inRequest . OpenRPA [ " Domain " ] . upper ( )
lUserUpperStr = inRequest . OpenRPA [ " User " ] . upper ( )
return { " DomainUpperStr " : lDomainUpperStr , " UserNameUpperStr " : lUserUpperStr }
# Return User UAC Hierarchy DICT Return {...}
def WebUserUACHierarchyGet ( inRequest ) :
return inRequest . UserRoleHierarchyGet ( )
## GSettings defs
def GSettingsKeyListValueSet ( inGSettings , inValue , inKeyList = [ ] ) : # Set value in GSettings by the key list
lDict = inGSettings
@ -269,6 +289,19 @@ def GSettingsKeyListValueOperatorPlus(inGSettings, inValue, inKeyList=[]): # Ope
lDict [ inKeyList [ - 1 ] ] + = inValue #Set value
return True
# Add Activity item in Processor list
def ProcessorActivityItemAppend ( inGSettings , inDef , inArgList = [ ] , inArgDict = { } , inArgGSettingsStr = None , inArgLoggerStr = None ) :
lActivityList = [
{
" Def " : inDef , # def link or def alias (look gSettings["Processor"]["AliasDefDict"])
" ArgList " : inArgList , # Args list
" ArgDict " : inArgDict , # Args dictionary
" ArgGSettings " : inArgGSettingsStr , # Name of GSettings attribute: str (ArgDict) or index (for ArgList)
" ArgLogger " : inArgLoggerStr # Name of GSettings attribute: str (ArgDict) or index (for ArgList)
} ,
]
inGSettings [ " ProcessorDict " ] [ " ActivityList " ] + = lActivityList
## Process defs
def ProcessIsStarted ( inProcessNameWOExeStr ) : # Check if process is started
'''
@ -356,8 +389,22 @@ def PythonStart(inModulePathStr, inDefNameStr, inArgList=[], inArgDict={}, inLog
except Exception as e :
if inLogger : inLogger . exception ( " Loop activity error: module/function not founded " )
# # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # #
# Scheduler
# # # # # # # # # # # # # # # # # # # # # # #
# Add activity in time weekly
def SchedulerActivityTimeAddWeekly ( inGSettings , inTimeHHMMStr = " 23:55: " , inWeekdayList = [ ] , inActivityList = [ ] ) :
lActivityTimeItemDict = {
" TimeHH:MMStr " : inTimeHHMMStr , # Time [HH:MM] to trigger activity
" WeekdayList " : inWeekdayList , # List of the weekday index when activity is applicable, Default [1,2,3,4,5,6,7]
" ActivityList " : inActivityList ,
" GUID " : None # # Will be filled in Orchestrator automatically - is needed for detect activity completion
} ,
inGSettings [ " SchedulerDict " ] [ " ActivityTimeList " ] . append ( lActivityTimeItemDict )
# # # # # # # # # # # # # # # # # # # # # # #
# RDPSession
# # # # # # # # # # # # # # # # # # # # # # #
@ -698,7 +745,7 @@ def Orchestrator(inGSettings):
if lL : lL . warning ( f " RDP Session List was restored from previous Orchestrator session " )
#Инициализация настроечных параметров
lDaemonLoopSeconds = gSettingsDict [ " Scheduler " ] [ " ActivityTimeCheckLoopSeconds " ]
lDaemonLoopSeconds = gSettingsDict [ " Scheduler Dict " ] [ " CheckIntervalSecFloat " ]
lDaemonActivityLogDict = { } #Словарь отработанных активностей, ключ - кортеж (<activityType>, <datetime>, <processPath || processName>, <processArgs>)
lDaemonLastDateTime = datetime . datetime . now ( )
gSettingsDict [ " Server " ] [ " WorkingDirectoryPathStr " ] = os . getcwd ( ) # Set working directory in g settings
@ -762,74 +809,81 @@ def Orchestrator(inGSettings):
gDaemonActivityLogDictRefreshSecInt = 10 # The second period for clear lDaemonActivityLogDict from old items
gDaemonActivityLogDictLastTime = time . time ( ) # The second perioad for clean lDaemonActivityLogDict from old items
while True :
lCurrentDateTime = datetime . datetime . now ( )
#Циклический обход правил
lFlagSearchActivityType = True
# Periodically clear the lDaemonActivityLogDict
if time . time ( ) - gDaemonActivityLogDictLastTime > = gDaemonActivityLogDictRefreshSecInt :
gDaemonActivityLogDictLastTime = time . time ( ) # Update the time
for lIndex , lItem in enumerate ( lDaemonActivityLogDict ) :
if lItem [ " ActivityEndDateTime " ] and lCurrentDateTime < = lItem [ " ActivityEndDateTime " ] :
pass
# Activity is actual - do not delete now
else :
# remove the activity - not actual
lDaemonActivityLogDict . pop ( lIndex , None )
lIterationLastDateTime = lDaemonLastDateTime # Get current datetime before iterator (need for iterate all activities in loop)
# Iterate throught the activity list
for lIndex , lItem in enumerate ( gSettingsDict [ " Scheduler " ] [ " ActivityTimeList " ] ) :
# Prepare GUID of the activity
lGUID = None
if " GUID " in lItem and lItem [ " GUID " ] :
lGUID = lItem [ " GUID " ]
else :
lGUID = str ( uuid . uuid4 ( ) )
lItem [ " GUID " ] = lGUID
#Проверка дней недели, в рамках которых можно запускать активность
lItemWeekdayList = lItem . get ( " WeekdayList " , [ 0 , 1 , 2 , 3 , 4 , 5 , 6 ] )
if lCurrentDateTime . weekday ( ) in lItemWeekdayList :
if lFlagSearchActivityType :
#######################################################################
#Branch 1 - if has TimeHH:MM
#######################################################################
if " TimeHH:MM " in lItem :
#Вид активности - запуск процесса
#Сформировать временной штамп, относительно которого надо будет проверять время
#часовой пояс пока не учитываем
lActivityDateTime = datetime . datetime . strptime ( lItem [ " TimeHH:MM " ] , " % H: % M " )
lActivityDateTime = lActivityDateTime . replace ( year = lCurrentDateTime . year , month = lCurrentDateTime . month , day = lCurrentDateTime . day )
#Убедиться в том, что время наступило
if (
lActivityDateTime > = lDaemonLastDateTime and
lCurrentDateTime > = lActivityDateTime ) :
# Log info about activity
if lL : lL . info ( f " Scheduler:: Activity is started. Scheduler item: { lItem } " ) #Logging
# Do the activity
Processor . ActivityListOrDict ( lItem [ " Activity " ] )
lIterationLastDateTime = datetime . datetime . now ( ) # Set the new datetime for the new processor activity
#######################################################################
#Branch 2 - if TimeHH:MMStart, TimeHH:MMStop, ActivityIntervalSeconds
#######################################################################
if " TimeHH:MMStart " in lItem and " TimeHH:MMStop " in lItem and " ActivityIntervalSeconds " in lItem :
#Сформировать временной штамп, относительно которого надо будет проверять время
#часовой пояс пока не учитываем
lActivityDateTime = datetime . datetime . strptime ( lItem [ " TimeHH:MMStart " ] , " % H: % M " )
lActivityDateTime = lActivityDateTime . replace ( year = lCurrentDateTime . year , month = lCurrentDateTime . month , day = lCurrentDateTime . day )
lActivityTimeEndDateTime = datetime . datetime . strptime ( lItem [ " TimeHH:MMStop " ] , " % H: % M " )
lActivityTimeEndDateTime = lActivityTimeEndDateTime . replace ( year = lCurrentDateTime . year , month = lCurrentDateTime . month , day = lCurrentDateTime . day )
#Убедиться в том, что время наступило
if (
lCurrentDateTime < lActivityTimeEndDateTime and
lCurrentDateTime > = lActivityDateTime and
( lGUID , lActivityDateTime ) not in lDaemonActivityLogDict ) :
#Запись в массив отработанных активностей
lDaemonActivityLogDict [ ( lGUID , lActivityDateTime ) ] = { " ActivityStartDateTime " : lCurrentDateTime , " ActivityEndDateTime " : lActivityTimeEndDateTime }
#Запуск циклической процедуры
Timer . activityLoopStart ( lItem [ " ActivityIntervalSeconds " ] , lActivityTimeEndDateTime , lItem [ " Activity " ] )
lDaemonLastDateTime = lIterationLastDateTime # Set the new datetime for the new processor activity
#Уснуть до следующего прогона
time . sleep ( lDaemonLoopSeconds )
try :
lCurrentDateTime = datetime . datetime . now ( )
#Циклический обход правил
lFlagSearchActivityType = True
# Periodically clear the lDaemonActivityLogDict
if time . time ( ) - gDaemonActivityLogDictLastTime > = gDaemonActivityLogDictRefreshSecInt :
gDaemonActivityLogDictLastTime = time . time ( ) # Update the time
for lIndex , lItem in enumerate ( lDaemonActivityLogDict ) :
if lItem [ " ActivityEndDateTime " ] and lCurrentDateTime < = lItem [ " ActivityEndDateTime " ] :
pass
# Activity is actual - do not delete now
else :
# remove the activity - not actual
lDaemonActivityLogDict . pop ( lIndex , None )
lIterationLastDateTime = lDaemonLastDateTime # Get current datetime before iterator (need for iterate all activities in loop)
# Iterate throught the activity list
for lIndex , lItem in enumerate ( gSettingsDict [ " SchedulerDict " ] [ " ActivityTimeList " ] ) :
try :
# Prepare GUID of the activity
lGUID = None
if " GUID " in lItem and lItem [ " GUID " ] :
lGUID = lItem [ " GUID " ]
else :
lGUID = str ( uuid . uuid4 ( ) )
lItem [ " GUID " ] = lGUID
#Проверка дней недели, в рамках которых можно запускать активность
lItemWeekdayList = lItem . get ( " WeekdayList " , [ 0 , 1 , 2 , 3 , 4 , 5 , 6 ] )
if lCurrentDateTime . weekday ( ) in lItemWeekdayList :
if lFlagSearchActivityType :
#######################################################################
#Branch 1 - if has TimeHH:MM
#######################################################################
if " TimeHH:MM " in lItem :
#Вид активности - запуск процесса
#Сформировать временной штамп, относительно которого надо будет проверять время
#часовой пояс пока не учитываем
lActivityDateTime = datetime . datetime . strptime ( lItem [ " TimeHH:MM " ] , " % H: % M " )
lActivityDateTime = lActivityDateTime . replace ( year = lCurrentDateTime . year , month = lCurrentDateTime . month , day = lCurrentDateTime . day )
#Убедиться в том, что время наступило
if (
lActivityDateTime > = lDaemonLastDateTime and
lCurrentDateTime > = lActivityDateTime ) :
# Log info about activity
if lL : lL . info ( f " Scheduler:: Activity list is started in new thread. Scheduler item: { lItem } " ) #Logging
# Do the activity
lThread = threading . Thread ( target = Processor . ActivityListExecute , kwargs = { " inGSettings " : inGSettings , " inActivityList " : lItem [ " ActivityList " ] } )
lThread . start ( )
lIterationLastDateTime = datetime . datetime . now ( ) # Set the new datetime for the new processor activity
#######################################################################
#Branch 2 - if TimeHH:MMStart, TimeHH:MMStop, ActivityIntervalSeconds
#######################################################################
if " TimeHH:MMStart " in lItem and " TimeHH:MMStop " in lItem and " ActivityIntervalSeconds " in lItem :
#Сформировать временной штамп, относительно которого надо будет проверять время
#часовой пояс пока не учитываем
lActivityDateTime = datetime . datetime . strptime ( lItem [ " TimeHH:MMStart " ] , " % H: % M " )
lActivityDateTime = lActivityDateTime . replace ( year = lCurrentDateTime . year , month = lCurrentDateTime . month , day = lCurrentDateTime . day )
lActivityTimeEndDateTime = datetime . datetime . strptime ( lItem [ " TimeHH:MMStop " ] , " % H: % M " )
lActivityTimeEndDateTime = lActivityTimeEndDateTime . replace ( year = lCurrentDateTime . year , month = lCurrentDateTime . month , day = lCurrentDateTime . day )
#Убедиться в том, что время наступило
if (
lCurrentDateTime < lActivityTimeEndDateTime and
lCurrentDateTime > = lActivityDateTime and
( lGUID , lActivityDateTime ) not in lDaemonActivityLogDict ) :
#Запись в массив отработанных активностей
lDaemonActivityLogDict [ ( lGUID , lActivityDateTime ) ] = { " ActivityStartDateTime " : lCurrentDateTime , " ActivityEndDateTime " : lActivityTimeEndDateTime }
#Запуск циклической процедуры
Timer . activityLoopStart ( lItem [ " ActivityIntervalSeconds " ] , lActivityTimeEndDateTime , lItem [ " Activity " ] )
except Exception as e :
if lL : lL . exception ( f " Scheduler: Exception has been catched in Scheduler module when activity time item was initialising. ActivityTimeItem is { lItem } " )
lDaemonLastDateTime = lIterationLastDateTime # Set the new datetime for the new processor activity
#Уснуть до следующего прогона
time . sleep ( lDaemonLoopSeconds )
except Exception as e :
if lL : lL . exception ( f " Scheduler: Exception has been catched in Scheduler module. Global error " )
# Backward compatibility below to 1.2.0
def __deprecated_orchestrator_start__ ( ) :