def computeCI(data): ci_name = data ci_attributeMap = {} ci_attributeMap['Name'] = ci_name ci_attributeMap['CLASS'] = "" ci_attributeMap['Description'] = "CTM Application" ci_attributeMap['Priority'] = "PRIORITY_5" ci_attributeMap['HomeCell'] = tsim.tsim_cell ci_attributeMap['ReadSecurity'] = "[Full Access]" ci_attributeMap['WriteSecurity'] = "[Full Access]" ci_attributeMap['status'] = "OK" ci_attributeMap['maintenance_mode'] = "NO" ci_attributeMap[ 'ComponentAliases'] = "[ctm-em:TryBMC:Business Service Automation:TryBMC Payroll:]" ci_attributeMap['HomePageURI'] = "http://www.trybmc.com" ci_attributeMap['ManufacturerName'] = "BMC Software" ci_attributeMap[ 'TokenId'] = "ctm-em:TryBMC:Business Service Automation:TryBMC Payroll:" # Define the dictionary that wraps each event. ci_wrapper = {} ci_wrapper["id"] = ci_name ci_wrapper["className"] = "BMC_ApplicationService" ci_wrapper["attributeMap"] = ci_attributeMap json_data = '{"cilist":[' + w3rkstatt.jsonTranslateValues( str(ci_wrapper)) + ']}' if _localDebug: logger.debug('CTM: CI json payload: %s', json_data) return json_data
def demoTSO(): authToken = tso.authenticate() if authToken != None: logger.info('TSO Login: %s', authToken) if authToken != None: workflow = w3rkstatt.getJsonValue(path="$.TSO.ctm.wcm", data=jCfgData) data = {"inputParameters": [{"name": "data", "value": "test"}]} response = tso.executeTsoProcess(token=authToken, process=workflow, data=data) response = w3rkstatt.jsonTranslateValues(data=response) logger.info('TSO Demo: %s', response) response = tso.getTsoModulesAdv(token=authToken) response = w3rkstatt.jsonTranslateValues(data=response) logger.info('TSO Demo: %s', response)
def getTsoModulesAdv(token): ''' Get the TSO modules with additional information :param str token: authentication token :return: content :rtype: dict :raises ValueError: N/A :raises TypeError: N/A ''' # 'repo': "false" , pattern tsoApi = "module" authToken = token headers = { 'content-type': "application/json", 'cache-control': "no-cache", 'Authentication-Token': authToken, 'repo': "false", } body = {} items01 = apiGet(api=tsoApi, headers=headers, body=body) tsoModules = [] itemsCounter = 0 for item01 in items01: tsoModule = {} tsoModule["name"] = item01["name"] tsoModule["version"] = item01["version"] tsoModule["revision"] = item01["revision"] items02 = items01[itemsCounter]["processes"] tsoProcesses = [] tsoProcesses.clear() for item02 in items02: tsoProcess = {} tsoProcess["name"] = item02["name"] tsoProcesses.append(tsoProcess) tsoModule["processes"] = tsoProcesses tsoModules.append(tsoModule) itemsCounter += 1 json_data = w3rkstatt.jsonTranslateValues(tsoModules) if _localDebug: logger.debug('TSO: Modules Advanced: %s', json_data) return json_data
def executeProcess(process, data=""): ''' Execute a TSO workflow :param str process: workflow name :param str data: workflow payload :return: content :rtype: dict :raises ValueError: N/A :raises TypeError: N/A ''' if _localDebug: logger.debug('TSO Process Name: %s', process) logger.debug('TSO Process Data: %s', data) authToken = authenticate() response = executeTsoProcess(token=authToken, process=process, data=data) response = w3rkstatt.jsonTranslateValues(data=response) logout(authToken) return response
def formatAlert4Infra(raw, data): if _localInfo: logger.info('CTM: Analyze Alert for Infra - Start') jCtmAlert = data ctmCoreData = None jCtmAlertData = json.dumps(jCtmAlert) jCtmAlertRaw = raw if _localInfo: logger.info('CTM: Analyze Alert - Infra Info') # Prep for str concat sCtmAlertRaw = str(jCtmAlertRaw) sCtmAlertData = str(jCtmAlertData) ctmCoreData = '{"uuid":"' + sUuid + '","raw":[' + sCtmAlertRaw + '],"infraAlert":[' + sCtmAlertData + ']}' ctmCoreData = w3rkstatt.jsonTranslateValues(ctmCoreData) ctmCoreData = w3rkstatt.jsonTranslateValuesAdv(ctmCoreData) if _localInfo: logger.info('CTM: Analyze Alert for Infra - End') return ctmCoreData
def getTsoAdapters(token): ''' Get the TSO adapters :param str token: authentication token :return: content :rtype: dict :raises ValueError: N/A :raises TypeError: N/A ''' tsoApi = "adapter?configDataType=JSON" authToken = token headers = { 'content-type': "application/json", 'cache-control': "no-cache", 'Authentication-Token': authToken, 'configDataType': 'JSON' } body = {} items01 = apiGet(api=tsoApi, headers=headers, body=body) tsoAdapters = [] for item01 in items01: tsoAdapter = {} tsoAdapter["name"] = item01["name"] tsoAdapter["version"] = item01["version"] tsoAdapter["revision"] = item01["revision"] tsoAdapter["adapterType"] = item01["adapterType"] tsoAdapter["revision"] = item01["revision"] # adapterType tsoAdapters.append(tsoAdapter) json_data = '{"adapter":' + w3rkstatt.jsonTranslateValues( str(tsoAdapters)) + '}' if _localDebug: logger.debug('TSO: Adapters: %s', json_data) return json_data
def getTsoModules(token): ''' Get the TSO modules :param str token: authentication token :return: content :rtype: dict :raises ValueError: N/A :raises TypeError: N/A ''' # 'repo': "false" , pattern tsoApi = "module" authToken = token headers = { 'content-type': "application/json", 'cache-control': "no-cache", 'Authentication-Token': authToken, 'repo': "false", } body = {} items01 = apiGet(api=tsoApi, headers=headers, body=body) tsoModules = [] for item01 in items01: tsoModule = {} tsoModule["name"] = item01["name"] tsoModule["version"] = item01["version"] tsoModule["revision"] = item01["revision"] tsoModules.append(tsoModule) json_data = '{"module":' + w3rkstatt.jsonTranslateValues( str(tsoModules)) + '}' if _localDebug: logger.debug('TSO: Modules: %s', json_data) return json_data
def createITSM(data): # ITSM Login authToken = itsm.authenticate() jCtmAlert = json.loads(data) # ToDO: Update Incident data # Add Logic to map CTM Alerts to Incident Support Groups sCtmAppMain = w3rkstatt.getJsonValue(path="$.jobAlert.[0].application", data=jCtmAlert) sCtmAppSub = w3rkstatt.getJsonValue(path="$.jobAlert.[0].sub_application", data=jCtmAlert) sCtmJobName = w3rkstatt.getJsonValue(path="$.jobAlert.[0].job_name", data=jCtmAlert) sCtmJobCyclic = w3rkstatt.getJsonValue(path="$.jobInfo.[0].cyclic", data=jCtmAlert) sCtmJobID = w3rkstatt.getJsonValue(path="$.jobAlert.[0].job_id", data=jCtmAlert) sCtmJobRunCount = w3rkstatt.getJsonValue(path="$.jobAlert.[0].run_counter", data=jCtmAlert) sCtmAlertID = w3rkstatt.getJsonValue(path="$.jobAlert.[0].alert_id", data=jCtmAlert) sCtmJobDescSum = w3rkstatt.getJsonValue( path="$.jobAlert.[0].message_summary", data=jCtmAlert) sCtmJobDescDetail = w3rkstatt.getJsonValue( path="$.jobAlert.[0].message_notes", data=jCtmAlert) if sCtmJobCyclic: sCtmVendorTicket = "#" + sCtmJobID + "#Cyclic#" else: sCtmVendorTicket = "#" + sCtmJobID + "#Regular#" + sCtmJobRunCount + "#" + sCtmAlertID + "#" jIncidentData = { "values": { "z1D_Action": "CREATE", "First_Name": w3rkstatt.getJsonValue(path="$.ITSM.defaults.name-first", data=jCfgData), "Last_Name": w3rkstatt.getJsonValue(path="$.ITSM.defaults.name-last", data=jCfgData), "Description": sCtmJobDescSum, "Detailed_Decription": sCtmJobDescDetail, "Impact": w3rkstatt.getJsonValue(path="$.ITSM.incident.impact", data=jCfgData), "Urgency": w3rkstatt.getJsonValue(path="$.ITSM.incident.urgency", data=jCfgData), "Status": w3rkstatt.getJsonValue(path="$.ITSM.incident.status", data=jCfgData), "Reported Source": w3rkstatt.getJsonValue(path="$.ITSM.incident.reported-source", data=jCfgData), "Service_Type": w3rkstatt.getJsonValue(path="$.ITSM.incident.service-type", data=jCfgData), "ServiceCI": w3rkstatt.getJsonValue(path="$.ITSM.defaults.service-ci", data=jCfgData), "Assigned Group": w3rkstatt.getJsonValue(path="$.ITSM.defaults.assigned-group", data=jCfgData), "Assigned Support Company": w3rkstatt.getJsonValue(path="$.ITSM.defaults.support-company", data=jCfgData), "Assigned Support Organization": w3rkstatt.getJsonValue(path="$.ITSM.defaults.support-organization", data=jCfgData), "Categorization Tier 1": w3rkstatt.getJsonValue(path="$.ITSM.defaults.op_cat_1", data=jCfgData), "Categorization Tier 2": w3rkstatt.getJsonValue(path="$.ITSM.defaults.op_cat_2", data=jCfgData), "Categorization Tier 3": w3rkstatt.getJsonValue(path="$.ITSM.defaults.op_cat_3", data=jCfgData), "Product Categorization Tier 1": w3rkstatt.getJsonValue(path="$.ITSM.defaults.prod_cat_1", data=jCfgData), "Product Categorization Tier 2": w3rkstatt.getJsonValue(path="$.ITSM.defaults.prod_cat_2", data=jCfgData), "Product Categorization Tier 3": w3rkstatt.getJsonValue(path="$.ITSM.defaults.prod_cat_3", data=jCfgData), "Product Name": w3rkstatt.getJsonValue(path="$.ITSM.defaults.product_name", data=jCfgData), "Vendor Ticket Number": sCtmVendorTicket, "AWW Custom Field Name": sCtmJobName + "#" + sCtmAppMain + "#" + sCtmAppSub } } incidentId = itsm.createIncident(token=authToken, data=jIncidentData) if _localDebugITSM: sIncidentData = w3rkstatt.jsonTranslateValues(data=jIncidentData) logger.debug('') logger.debug('ITSM Integration Data = %s ', sIncidentData) logger.debug('') logger.debug('ITSM Incident: "%s" ', incidentId) # Worklog entry for CTM Alert jWorklogData = w3rkstatt.getJsonValue(path="$.jobAlert", data=jCtmAlert) createWorklog(token=authToken, data=jWorklogData, incident=incidentId) if _localDebugITSM: sIncidentData = w3rkstatt.jsonTranslateValues(data=jWorklogData) logger.debug('') logger.debug('ITSM Worklog Data = %s ', sIncidentData) logger.debug('') # Worklog entry for CTM Job Info jWorklogData = w3rkstatt.getJsonValue(path="$.jobInfo", data=jCtmAlert) createWorklog(token=authToken, data=jWorklogData, incident=incidentId) # Worklog entry for CTM Job Config jWorklogData = w3rkstatt.getJsonValue(path="$.jobConfig", data=jCtmAlert) createWorklog(token=authToken, data=jWorklogData, incident=incidentId) # Worklog entry for CTM Job Output jWorklogData = w3rkstatt.getJsonValue(path="$.jobLog", data=jCtmAlert) createWorklog(token=authToken, data=jWorklogData, incident=incidentId) # Worklog entry for CTM Job Output jWorklogData = w3rkstatt.getJsonValue(path="$.jobOutput", data=jCtmAlert) createWorklog(token=authToken, data=jWorklogData, incident=incidentId) # ITSM Logoff itsm.itsmLogout(token=authToken) logger.info('ITSM Incident: %s', incidentId) return incidentId