def getCtmJobConfig(ctmApiClient, data): jCtmJobInfo = data ctmFolderInfo = getCtmFolder(ctmApiClient=ctmApiClient, data=jCtmJobInfo) jCtmFolderInfo = json.loads(ctmFolderInfo) iCtmFolderInfo = w3rkstatt.getJsonValue(path="$.count", data=jCtmFolderInfo) sStatus = w3rkstatt.getJsonValue(path="$.status", data=jCtmFolderInfo) if ctm_job_detail_level == "full" or iCtmFolderInfo == 1: jCtmJobDetail = ctmFolderInfo sCtmJobDetail = w3rkstatt.dTranslate4Json(data=jCtmJobDetail) else: if _localQA: logger.debug('CMT Job Config: "%s"', jCtmJobInfo) if sStatus: jCtmJobName = w3rkstatt.getJsonValue(path="$.name", data=jCtmJobInfo) jCtmFolderName = w3rkstatt.getJsonValue(path="$.folder", data=jCtmJobInfo) jQl = "$." + str(jCtmFolderName) + "." + str(jCtmJobName) jData = json.loads(ctmFolderInfo) jCtmJobDetail = w3rkstatt.getJsonValue(path=jQl, data=jData) sCtmJobDetail = w3rkstatt.dTranslate4Json(data=jCtmJobDetail) else: sCtmJobDetail = ctmFolderInfo return sCtmJobDetail
def getLocalConnectionProfilesAi(ctmApiClient, ctmServer, ctmAgent, ctmAppType): appTypes = ctmAppType["jobtypes"] jConnProfiles = "" for appType in appTypes: job_type_name = appType["job_type_name"] job_type_id = appType["job_type_id"] appTypeAi = "ApplicationIntegrator:" + job_type_name if _localDebug: pass logger.debug(' - Action: %s : %s', "Get Connection Profile", appTypeAi) jProfiles = ctm.getCtmAgentConnectionProfile(ctmApiClient=ctmApiClient, ctmServer=ctmServer, ctmAgent=ctmAgent, ctmAppType=appTypeAi) jProfilesLen = len(jProfiles) if jProfilesLen > 0: logger.debug(' - Action: %s : %s', "Found Connection Profile", job_type_id) jProfile = '"' + job_type_id + '":' jProfile = jProfile + str(jProfiles) jConnProfiles = jProfile + "," + jConnProfiles else: if _localDebug: jProfile = '"' + job_type_id + '":None' jConnProfiles = jProfile + "," + jConnProfiles jConnProfiles = str(jConnProfiles).rstrip(',') jConnProfilsWrapper = '{"ai":{' + jConnProfiles + '}}' sConnProfile = w3rkstatt.dTranslate4Json(data=jConnProfilsWrapper) return sConnProfile
def getLocalConnectionProfiles(ctmApiClient, ctmServer, ctmAgent, ctmAppType): # Base Applications sCtmAppTypes = ctmAppType jConnProfiles = "" for appType in sCtmAppTypes: if _localDebug: pass logger.debug(' - Action: %s : %s', "Get Connection Profile", appType) jProfiles = ctm.getCtmAgentConnectionProfile(ctmApiClient=ctmApiClient, ctmServer=ctmServer, ctmAgent=ctmAgent, ctmAppType=appType) jProfilesLen = len(jProfiles) if jProfilesLen > 0: logger.debug(' - Action: %s : %s', "Found Connection Profile", appType) jProfile = '"' + appType + '":' jProfile = jProfile + str(jProfiles) jConnProfiles = jProfile + "," + jConnProfiles else: if _localDebug: jProfile = '"' + appType + '":None' jConnProfiles = jProfile + "," + jConnProfiles jConnProfiles = str(jConnProfiles).rstrip(',') jConnProfilsWrapper = '{"apps":{' + jConnProfiles + '}}' sConnProfile = w3rkstatt.dTranslate4Json(data=jConnProfilsWrapper) return sConnProfile
def getCtmRemoteHosts(ctmApiClient, ctmServer): # Get Remote Hosts sRemoteHostsList = "{}" sRemoteHostList = "" jRemoteHosts = ctm.getCtmRemoteHosts(ctmApiClient=ctmApiClient, ctmServer=ctmServer) iRemoteHosts = len(jRemoteHosts) if iRemoteHosts > 1: sRemoteHosts = str(jRemoteHosts) xRemoteHosts = w3rkstatt.dTranslate4Json(data=sRemoteHosts) j = 0 for xRemoteHost in jRemoteHosts: sCtmHostId = str(j).zfill(4) jRemoteHostProperties = ctm.getRemoteHostProperties( ctmApiClient=ctmApiClient, ctmServer=ctmServer, ctmRemoteHost=xRemoteHost) jCtmAgents = jRemoteHostProperties["agents"] iCtmAgents = len(jCtmAgents) sRemoteHostAgentMembers = "" if iCtmAgents > 0: i = 0 for sCtmAgent in jCtmAgents: sCtmAgentName = sCtmAgent sCtmAgentId = str(i).zfill(4) sRemoteHostAgent = '{"id":"R' + sCtmHostId + 'A' + sCtmAgentId + '","server":"' + ctmServer + '","host":"' + xRemoteHost + '","agent":"' + sCtmAgentName + '"}' sRemoteHostAgentMembers = sRemoteHostAgent + "," + sRemoteHostAgentMembers sRemoteHostAgentMembers = str( sRemoteHostAgentMembers).rstrip(",") i = int(i + 1) sRemoteHostList = sRemoteHostAgentMembers + "," + sRemoteHostList sRemoteHostList = str(sRemoteHostList).rstrip(",") j = int(j + 1) yRemoteHostList = w3rkstatt.dTranslate4Json(data=sRemoteHostList) else: yRemoteHostList = "{}" xRemoteHostFinal = '{"remote":[' + yRemoteHostList + ']}' sRemoteHostFinal = w3rkstatt.dTranslate4Json(data=xRemoteHostFinal) jRemoteHostFinal = json.loads(sRemoteHostFinal) return jRemoteHostFinal
def getCtmFolder(ctmApiClient, data): ctmData = data ctmFolderID = w3rkstatt.getJsonValue(path="$.folder_id", data=ctmData) ctmFolder = w3rkstatt.getJsonValue(path="$.folder", data=ctmData) ctmServer = w3rkstatt.getJsonValue(path="$.ctm", data=ctmData) if _localDebugAdv: logger.info('CTM Get Job Folder: "%s @ %s"', ctmFolder, ctmServer) value = ctm.getCtmDeployedFolder(ctmApiClient=ctmApiClient, ctmServer=ctmServer, ctmFolder=ctmFolder) if w3rkstatt.jsonValidator(data=value): ctmfolderInfo = w3rkstatt.dTranslate4Json(data=value) # adjust if CTM API access failed sJobLogStatus = True # Failed to get if "Failed to get" in str(value): sJobLogStatus = False i = 0 if "." in value: xTemp = value.split(".") for xLine in xTemp: zValue = xLine.strip() # construct json string if i == 0: sEntry = '"entry-' + str(i).zfill(4) + '":"' + zValue + '"' else: sEntry = sEntry + ',"entry-' + str(i).zfill( 4) + '":"' + zValue + '"' i += 1 else: sEntry = '"entry-0000": "' + value + '"' jData = '{"count":' + str(i) + ',"status":' + str( sJobLogStatus) + ',"entries":[{' + str(sEntry) + '}]}' sData = w3rkstatt.dTranslate4Json(data=jData) return sData
def getCtmJobLog(ctmApiClient, data): # Get CTM job log after 30 sec - wait for archive server to have log if _localDebugAdv: logger.debug('CMT Job Log: First attempt to retrieve data') time.sleep(2) sCtmJobLog = getCtmJobRunLog(ctmApiClient, data) jCtmJobLog = json.loads(sCtmJobLog) ctmStatus = w3rkstatt.getJsonValue(path="$.status", data=jCtmJobLog) if ctmStatus != True: if _localDebugAdv: logger.debug('CMT Job Log: Second attempt to retrieve data') time.sleep(2) jCtmJobLog = getCtmJobRunLog(ctmApiClient, data) sCtmJobLog = w3rkstatt.dTranslate4Json(data=jCtmJobLog) return sCtmJobLog
def getCtmJobOutput(ctmApiClient, data): # Get CTM job log after 30 sec - wait for archive server to have log if _localDebugAdv: logger.debug('CMT Job Output: First attempt to retrieve data') time.sleep(2) jCtmJobOutput = getCtmJobRunOutput(ctmApiClient, data) ctmStatus = w3rkstatt.getJsonValue(path="$.status", data=jCtmJobOutput) if ctmStatus != True: if _localDebugAdv: logger.debug('CMT Job Output: Second attempt to retrieve data') time.sleep(2) jCtmJobOutput = getCtmJobRunOutput(ctmApiClient, data) # transform to JSON string sCtmJobOutput = w3rkstatt.dTranslate4Json(data=jCtmJobOutput) return sCtmJobOutput
def formatAlert4Job(raw, data): if _localInfo: logger.info('CTM: Analyze Alert for Jobs - Start') jCtmAlert = data ctmOrderId = w3rkstatt.getJsonValue(path="$.order_id", data=jCtmAlert) ctmJobData = None jCtmAlertData = json.dumps(jCtmAlert) sCtmAlertData = str(jCtmAlertData) jCtmAlertRaw = raw if not ctmOrderId == "00000" and ctmOrderId is not None: if "New" in ctmAlertCallType: # Get CTM Job Info ctmJobId = w3rkstatt.getJsonValue(path="$.job_id", data=jCtmAlert) ctmJobName = w3rkstatt.getJsonValue(path="$.job_name", data=jCtmAlert) sCtmJobInfo = '{"ctm_api":"simplified monitoring"}' sCtmJobOutput = '{"ctm_api":"simplified monitoring"}' sCtmJobLog = '{"ctm_api":"simplified monitoring"}' sCtmJobConfig = '{"ctm_api":"simplified monitoring"}' # Prep for str concat sCtmAlertRaw = str(jCtmAlertRaw) ctmJobData = '{"uuid":"' + sUuid + '","raw":[' + sCtmAlertRaw + '],"jobAlert":[' + sCtmAlertData + '],"jobInfo":[' + sCtmJobInfo + '],"jobConfig":[' + sCtmJobConfig + '],"jobLog":[' + sCtmJobLog + '],"jobOutput":[' + sCtmJobOutput + ']}' ctmJobData = w3rkstatt.dTranslate4Json(data=ctmJobData) # Convert event data to the JSON format required by the API. else: sCtmAlertRaw = str(jCtmAlertRaw) sjCtmAlert = w3rkstatt.dTranslate4Json(data=jCtmAlert) # defaults sCtmJobInfo = w3rkstatt.dTranslate4Json(data='{"count":' + str(None) + ',"status":' + str(None) + ',"entries":[]}') sCtmJobOutput = w3rkstatt.dTranslate4Json(data='{"count":' + str(None) + ',"status":' + str(None) + ',"entries":[]}') sCtmJobLog = w3rkstatt.dTranslate4Json(data='{"count":' + str(None) + ',"status":' + str(None) + ',"entries":[]}') sCtmJobConfig = w3rkstatt.dTranslate4Json(data='{"count":' + str(None) + ',"status":' + str(None) + ',"entries":[]}') ctmJobData = '{"uuid":"' + sUuid + '","raw":[' + sCtmAlertRaw + '],"jobAlert":[' + sCtmAlertData + '],"jobInfo":[' + sCtmJobInfo + '],"jobConfig":[' + sCtmJobConfig + '],"jobLog":[' + sCtmJobLog + '],"jobOutput":[' + sCtmJobOutput + ']}' if _localInfo: logger.info('CTM: Analyze Alert for Jobs - End') return ctmJobData
def getHostGroups(ctmApiClient, ctmServer): # Get HostGroups sHostGroupList = '{"groups":[]}' jCtmHostGroups = ctm.getCtmHostGroups(ctmApiClient=ctmApiClient, ctmServer=ctmServer) iCtmHostGroups = len(jCtmHostGroups) lHostGroup = "" if iCtmHostGroups > 0: sjCtmHostGroups = str(jCtmHostGroups) j = 0 for sHostGroupName in jCtmHostGroups: sCtmGroupId = str(j).zfill(4) sHostGroupMembers = "" jHostGroupMembers = ctm.getCtmHostGroupMembers( ctmApiClient=ctmApiClient, ctmServer=ctmServer, ctmHostGroup=sHostGroupName) iHostGroupMembers = len(jHostGroupMembers) i = 0 for sHostGroupMember in jHostGroupMembers: sHostGroupMember = str(sHostGroupMember).replace( "host", str(i).zfill(4)) sCtmAgentName = str(sHostGroupMember).split("'")[3] sCtmAgentId = str(i).zfill(4) sCtmAgentGroup = sHostGroupName sCtmAgent = '{"id":"G' + sCtmGroupId + 'A' + sCtmAgentId + '","server":"' + ctmServer + '","group":"' + sCtmAgentGroup + '","agent":"' + sCtmAgentName + '"}' sHostGroupMembers = sCtmAgent + "," + sHostGroupMembers i = int(i + 1) j = int(j + 1) sHostGroupMembers = w3rkstatt.dTranslate4Json( data=sHostGroupMembers[:-1]) lHostGroup = sHostGroupMembers + ',' + lHostGroup lHostGroup = lHostGroup[:-1] sHostGroupList = '{"groups":[' + lHostGroup + ']}' jHostGroupList = json.loads(sHostGroupList) return jHostGroupList
def analyzeAlert4Job(ctmApiClient, raw, data): if _localInfo: logger.info('CTM: Analyze Alert for Jobs - Start') jCtmAlert = data ctmOrderId = w3rkstatt.getJsonValue(path="$.order_id", data=jCtmAlert) ctmJobData = None jCtmAlertData = json.dumps(jCtmAlert) sCtmAlertData = str(jCtmAlertData) jCtmAlertRaw = raw if not ctmOrderId == "00000" and ctmOrderId is not None: if "New" in ctmAlertCallType: # Get CTM Job Info ctmJobId = w3rkstatt.getJsonValue(path="$.job_id", data=jCtmAlert) ctmJobName = w3rkstatt.getJsonValue(path="$.job_name", data=jCtmAlert) if _ctmActiveApi: sCtmJobInfo = getCtmJobInfo(ctmApiClient=ctmApiClient, data=jCtmAlert) sCtmJobOutput = getCtmJobOutput(ctmApiClient=ctmApiClient, data=jCtmAlert) sCtmJobLog = getCtmJobLog(ctmApiClient=ctmApiClient, data=jCtmAlert) # Create JSON object jCtmJobInfo = json.loads(sCtmJobInfo) jCtmJobLog = json.loads(sCtmJobLog) # Folder / Job Details ctmJobInfoCount = w3rkstatt.getJsonValue(path="$.count", data=jCtmJobInfo) if ctmJobInfoCount >= 1: sCtmJobConfig = getCtmJobConfig(ctmApiClient=ctmApiClient, data=jCtmJobInfo) else: xData = '{"count":0,"status":' + str( None) + ',"entries":[]}' sCtmJobConfig = w3rkstatt.dTranslate4Json(data=xData) else: sCtmJobInfo = '{"ctm_api":"not accessible"}' sCtmJobOutput = '{"ctm_api":"not accessible"}' sCtmJobLog = '{"ctm_api":"not accessible"}' sCtmJobConfig = '{"ctm_api":"not accessible"}' # Prep for str concat sCtmAlertRaw = str(jCtmAlertRaw) ctmJobData = '{"uuid":"' + sUuid + '","raw":[' + sCtmAlertRaw + '],"jobAlert":[' + sCtmAlertData + '],"jobInfo":[' + sCtmJobInfo + '],"jobConfig":[' + sCtmJobConfig + '],"jobLog":[' + sCtmJobLog + '],"jobOutput":[' + sCtmJobOutput + ']}' ctmJobData = w3rkstatt.dTranslate4Json(data=ctmJobData) # Convert event data to the JSON format required by the API. else: sCtmAlertRaw = str(jCtmAlertRaw) sjCtmAlert = w3rkstatt.dTranslate4Json(data=jCtmAlert) # defaults sCtmJobInfo = w3rkstatt.dTranslate4Json(data='{"count":' + str(None) + ',"status":' + str(None) + ',"entries":[]}') sCtmJobOutput = w3rkstatt.dTranslate4Json(data='{"count":' + str(None) + ',"status":' + str(None) + ',"entries":[]}') sCtmJobLog = w3rkstatt.dTranslate4Json(data='{"count":' + str(None) + ',"status":' + str(None) + ',"entries":[]}') sCtmJobConfig = w3rkstatt.dTranslate4Json(data='{"count":' + str(None) + ',"status":' + str(None) + ',"entries":[]}') ctmJobData = '{"uuid":"' + sUuid + '","raw":[' + sCtmAlertRaw + '],"jobAlert":[' + sCtmAlertData + '],"jobInfo":[' + sCtmJobInfo + '],"jobConfig":[' + sCtmJobConfig + '],"jobLog":[' + sCtmJobLog + '],"jobOutput":[' + sCtmJobOutput + ']}' if _localInfo: logger.info('CTM: Analyze Alert for Jobs - End') return ctmJobData
def discoCtm(): # CTM Login try: ctmApiObj = ctm.getCtmConnection() ctmApiClient = ctmApiObj.api_client _ctmActiveApi = True except: _ctmActiveApi = False ctmApiClient = None logger.error('CTM Login Status: %s', _ctmActiveApi) if _ctmActiveApi: jCtmServers = getCtmServers(ctmApiClient=ctmApiClient) jCtmAgentList = {} yCtmAgentList = "" iCtmServers = int(len(jCtmServers)) # Get CTM Job Types and jCtmAiJobTypes = ctm.getDeployedAiJobtypes( ctmApiClient=ctmApiClient, ctmAiJobDeployStatus="ready to deploy") jCtmAiJobTypesDraft = ctm.getDeployedAiJobtypes( ctmApiClient=ctmApiClient, ctmAiJobDeployStatus="draft") sCtmAppTypes = [ "Hadoop", "Database", "FileTransfer", "Informatica", "SAP", "AWS", "Azure" ] # Count CTM AI job types iCtmAiJobTypes = len(jCtmAiJobTypes['jobtypes']) iCtmAiJobTypesDraft = len(jCtmAiJobTypesDraft['jobtypes']) iCtmAppTypes = len(sCtmAppTypes) sCtmAiJobTypes = '{"r2d":"' + str( iCtmAiJobTypes) + '","draft":"' + str( iCtmAiJobTypesDraft) + '","apps":"' + str(iCtmAppTypes) + '"}' # Get CTM Shared Connection Profiles jCtmCentralConnectionProfilesBase = getCentralConnectionProfiles( ctmApiClient=ctmApiClient, jobTypes=sCtmAppTypes) jCtmCentralConnectionProfilesAi = getCentralConnectionProfilesAi( ctmApiClient=ctmApiClient, jobTypes=jCtmAiJobTypes) jCtmCentralConnectionProfilesBaseTemp = str( jCtmCentralConnectionProfilesBase).lstrip('{')[:-1] jCtmCentralConnectionProfilesAiTemp = str( jCtmCentralConnectionProfilesAi).lstrip('{')[:-1] jCtmCentralConnectionProfiles = '{"shared":{' + jCtmCentralConnectionProfilesBaseTemp + ',' + jCtmCentralConnectionProfilesAiTemp + '}}' # Write Control-M AI JobTypes File filePath = writeJobTypesInfoFile(data=jCtmAiJobTypes) filePath = writeJobTypesDraftInfoFile(data=jCtmAiJobTypesDraft) filePath = writeSharedConnectionProfilesInfoFile( data=jCtmCentralConnectionProfiles) for xCtmServer in jCtmServers: sCtmServerName = xCtmServer["name"] sCtmServerFQDN = xCtmServer["host"] logger.debug('CTM Server: %s', sCtmServerName) # Get Control-M Server Parameters jCtmServerParameters = ctm.getCtmServerParams( ctmApiClient=ctmApiClient, ctmServer=sCtmServerName) iCtmServerParameters = len(jCtmServerParameters) if iCtmServerParameters > 0: sCtmServerParameters = w3rkstatt.dTranslate4Json( data=jCtmServerParameters) else: # Mainframe has no data sCtmServerParameters = "[]" # Get Remote Hosts jCtmRemoteHosts = getCtmRemoteHosts(ctmApiClient=ctmApiClient, ctmServer=sCtmServerName) sCtmRemoteHosts = w3rkstatt.dTranslate4Json(data=jCtmRemoteHosts) filePath = writeRemoteHostsInfoFile(ctmServer=sCtmServerName, data=sCtmRemoteHosts) jCtmServerRemoteHosts = json.loads( getServerRemoteHosts(ctmRemoteHosts=jCtmRemoteHosts, ctmServer=sCtmServerName)) iCtmServerRemoteHosts = len(jCtmServerRemoteHosts) if iCtmServerRemoteHosts > 1: sServerRemoteHosts = str(jCtmServerRemoteHosts) sServerRemoteHosts = w3rkstatt.dTranslate4Json( data=sServerRemoteHosts) else: sServerRemoteHosts = "[]" # Get Control-M Agents jCtmAgents = getCtmAgents(ctmApiClient=ctmApiClient, ctmServer=sCtmServerName) xCtmAgents = w3rkstatt.getJsonValue(path="$.agents", data=jCtmAgents) # Get Control-M Hostgroups jCtmHostGroups = getHostGroups(ctmApiClient=ctmApiClient, ctmServer=sCtmServerName) sCtmHostGroups = w3rkstatt.dTranslate4Json(data=jCtmHostGroups) filePath = writeHostGroupsInfoFile(ctmServer=sCtmServerName, data=sCtmHostGroups) # Sample Debug data # xCtmAgents = [{'hostgroups': 'None', 'nodeid': 'vw-aus-ctm-wk01.adprod.bmc.com', 'operating_system': 'Microsoft Windows Server 2016 (Build 14393)', 'status': 'Available', 'version': '9.0.20.000'}] xCtmAgentsInfo = "" if "None" in xCtmAgents: iCtmAgents = 0 xCtmAgentsInfo = {} else: iCtmAgents = len(xCtmAgents) if iCtmAgents > 0: iCtmAgent = 1 for xAgent in xCtmAgents: sParam = w3rkstatt.dTranslate4Json(data=xAgent) jParam = json.loads(sParam) if _localDebug: logger.debug('CTM Agent "%s": %s', str(iCtmAgent), sParam) sAgentName = str( w3rkstatt.getJsonValue(path="$.nodeid", data=jParam)) sAgentStatus = str( w3rkstatt.getJsonValue(path="$.status", data=jParam)) sAgentVersion = str( w3rkstatt.getJsonValue(path="$.version", data=jParam)) sAgentOS = str( w3rkstatt.getJsonValue(path="$.operating_system", data=jParam)) sConnProfile = "" logger.debug('CTM Agent "%s/%s" Status: %s = %s', iCtmAgent, iCtmAgents, sAgentName, sAgentStatus) # Get CTM Agent Remote Hosts jAgentRemoteHosts = json.loads( getAgentRemoteHosts(jCtmRemoteHosts, ctmAgent=sAgentName)) iAgentRemoteHosts = len(jAgentRemoteHosts) if iAgentRemoteHosts == 1: lAgentRemoteHosts = jAgentRemoteHosts[0] sAgentRemoteHosts = str( w3rkstatt.getJsonValue(path="$.hosts", data=lAgentRemoteHosts)) sAgentRemoteHosts = w3rkstatt.dTranslate4Json( data=sAgentRemoteHosts) else: sAgentRemoteHosts = "[]" # Get CTM Agent Hostgroup Membership jAgentHostGroupsMembership = json.loads( getAgentHostGroupsMembership( ctmHostGroups=jCtmHostGroups, ctmAgent=sAgentName)) iAgentHostGroupsMembership = len( jAgentHostGroupsMembership) if iAgentHostGroupsMembership == 1: lAgentHostGroupsMembership = jAgentHostGroupsMembership[ 0] sAgentHostGroupsMembership = str( w3rkstatt.getJsonValue( path="$.groups", data=lAgentHostGroupsMembership)) sAgentHostGroupsMembership = w3rkstatt.dTranslate4Json( data=sAgentHostGroupsMembership) else: sAgentHostGroupsMembership = "[]" # Get Control-M agent info of active agent if sAgentStatus == "Available": # Get CTM Agent Parameters logger.debug(' - Action: %s', "Get Parameters") jCtmAgentParams = ctm.getCtmAgentParams( ctmApiClient=ctmApiClient, ctmServer=sCtmServerName, ctmAgent=sAgentName) dCtmAgentParams = ctm.simplifyCtmJson( data=jCtmAgentParams) jAgentInfo = '{"name":"' + sAgentName + '",' jAgentInfo = jAgentInfo + '"nodeid":"' + sAgentName + '",' jAgentInfo = jAgentInfo + '"status":"' + sAgentStatus + '",' jAgentInfo = jAgentInfo + '"hostgroups":' + sAgentHostGroupsMembership + ',' jAgentInfo = jAgentInfo + '"remote":' + sAgentRemoteHosts + ',' jAgentInfo = jAgentInfo + '"version":"' + sAgentVersion + '",' jAgentInfo = jAgentInfo + '"operating_system":"' + sAgentOS + '",' jAgentInfo = jAgentInfo + '"server_name":"' + sCtmServerName + '",' jAgentInfo = jAgentInfo + '"server_fqdn":"' + sCtmServerFQDN + '",' jAgentInfo = jAgentInfo + '"parameters":' + dCtmAgentParams + ',' # Get CTM Agent Connection Profiles # Base Application and Application Integrator Job Type based connection profile jCtmLocalConnectionProfilesAi = getLocalConnectionProfilesAi( ctmApiClient, ctmServer=sCtmServerName, ctmAgent=sAgentName, ctmAppType=jCtmAiJobTypes) jCtmLocalConnectionProfilesBase = getLocalConnectionProfiles( ctmApiClient=ctmApiClient, ctmServer=sCtmServerName, ctmAgent=sAgentName, ctmAppType=sCtmAppTypes) jCtmLocalConnectionProfilesBaseTemp = str( jCtmLocalConnectionProfilesBase).lstrip('{')[:-1] jCtmLocalConnectionProfilesAiTemp = str( jCtmLocalConnectionProfilesAi).lstrip('{')[:-1] jCtmLocalConnectionProfiles = '"profiles":{' + jCtmLocalConnectionProfilesBaseTemp + ',' + jCtmLocalConnectionProfilesAiTemp + '}' # Add to local CTM agent info jAgentInfo = jAgentInfo + jCtmLocalConnectionProfiles + '}' jAgentInfo = w3rkstatt.dTranslate4Json(data=jAgentInfo) else: jAgentInfo = '{"name":"' + sAgentName + '",' jAgentInfo = jAgentInfo + '"nodeid":"' + sAgentName + '",' jAgentInfo = jAgentInfo + '"status":"' + sAgentStatus + '",' jAgentInfo = jAgentInfo + '"hostgroups":' + sAgentHostGroupsMembership + ',' jAgentInfo = jAgentInfo + '"remote":' + sAgentRemoteHosts + ',' jAgentInfo = jAgentInfo + '"version":"' + sAgentVersion + '",' jAgentInfo = jAgentInfo + '"operating_system":"' + sAgentOS + '",' jAgentInfo = jAgentInfo + '"server_name":"' + sCtmServerName + '",' jAgentInfo = jAgentInfo + '"server_fqdn":"' + sCtmServerFQDN + '"}' if _localDebug: logger.debug('CTM Agent Info: %s', jAgentInfo) if iCtmAgents == 1: xCtmAgentsInfo = str(jAgentInfo).rstrip(',') else: xCtmAgentsInfo = str(jAgentInfo + ',' + xCtmAgentsInfo).rstrip(',') # Internal Agent Counter iCtmAgent = iCtmAgent + 1 # Write Status File for Agent jAgentInfo = w3rkstatt.dTranslate4Json(data=jAgentInfo) filePath = writeAgentInfoFile(ctmAgent=sAgentName, data=jAgentInfo) xCtmAgentList = '{"server":"' + sCtmServerName + '","host":"' + sCtmServerFQDN + '","parameters":' + sCtmServerParameters + ',"runners":' + str( iCtmAgents) + ',"remote":' + str( sServerRemoteHosts) + ',"agents":[' + str( xCtmAgentsInfo) + ']}' # Write Server Status File filePath = writeServerInfoFile(ctmServer=sCtmServerName, data=xCtmAgentList) if iCtmServers > 1: yCtmAgentList = str(xCtmAgentList + ',' + yCtmAgentList).rstrip(',') else: yCtmAgentList = str(xCtmAgentList).rstrip(',') yCtmAgentList = yCtmAgentList zCtmAgentList = '{"inventory":{' + '"servers":[' + yCtmAgentList + '],"profiles":' + jCtmCentralConnectionProfiles + ',"jobtypes":' + sCtmAiJobTypes + '}}' jCtmAgentList = w3rkstatt.dTranslate4Json(data=zCtmAgentList) # Write Inventory File filePath = writeInventoryInfoFile(data=jCtmAgentList) if _localDebug: logger.debug('CTM Servers: %s', jCtmServers) logger.debug('CTM Agents: %s', jCtmAgentList) # Close CTM AAPI connection if _ctmActiveApi: ctm.delCtmConnection(ctmApiObj)
def writeSharedConnectionProfilesInfoFile(data): filename = "ctm.connection.profiles.shared.json" data = w3rkstatt.dTranslate4Json(data=data) filePath = writeInfoFile(file=filename, content=data) return filePath
def writeJobTypesDraftInfoFile(data): filename = "ctm.job.ai.types.draft.json" data = w3rkstatt.dTranslate4Json(data=data) filePath = writeInfoFile(file=filename, content=data) return filePath
def getCtmServersAdv(ctmApiClient): jCtmServers = ctm.getCtmServers(ctmApiClient=ctmApiClient) if _localDebug: logger.debug('CTM Servers: %s', jCtmServers) iCtmServers = int(len(jCtmServers)) yCtmServerList = "" for xCtmServer in jCtmServers: sCtmServerName = xCtmServer["name"] sCtmServerHost = xCtmServer["host"] sCtmServerState = xCtmServer["state"] sCtmServerMsg = xCtmServer["message"] sCtmServerVersion = xCtmServer["version"] jCtmServerParams = ctm.getCtmServerParams(ctmApiClient=ctmApiClient, ctmServer=sCtmServerName) # Prepare new JSON jParameters = '{' jParamEntries = '"name":"' + sCtmServerName + '",' jParamEntries = jParamEntries + '"host":"' + sCtmServerHost + '",' jParamEntries = jParamEntries + '"state":"' + sCtmServerState + '",' jParamEntries = jParamEntries + '"message":"' + sCtmServerMsg + '",' jParamEntries = jParamEntries + '"version":"' + sCtmServerVersion + '",' if len(jCtmServerParams) > 0: for key in jCtmServerParams: sParam = w3rkstatt.dTranslate4Json(data=key) jParam = json.loads(sParam) sParamName = w3rkstatt.getJsonValue(path="$.name", data=jParam).lower() sParamVal = w3rkstatt.getJsonValue(path="$.value", data=jParam) # logger.debug('CTM Server: %s:%s', sParamName,sParamVal) if len(sParamVal) > 0: jParamEntry = '"' + sParamName + '":"' + sParamVal + '"' else: jParamEntry = '"' + sParamName + '":None' jParamEntries = jParamEntry + "," + jParamEntries else: pass jParamEntries = jParamEntries[:-1] jParameters = '{' + str(jParamEntries) + '}' sParameters = w3rkstatt.dTranslate4Json(data=jParameters) jServerParameters = json.loads(sParameters) dParameters = OrderedDict(sorted(jServerParameters.items())) dParameters = json.dumps(dParameters) xCtmServerList = dParameters if iCtmServers > 1: yCtmServerList = xCtmServerList + ',' + yCtmServerList else: yCtmServerList = xCtmServerList yCtmServerList = yCtmServerList[:-1] zCtmServerList = '[' + yCtmServerList + ']' jCtmServers = w3rkstatt.dTranslate4Json(data=zCtmServerList) if _localDebug: logger.debug('CTM Server Parameters: %s', jCtmServers) return jCtmServers