Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def getCtmArchiveJobLog(ctmApiClient, data):
    ctmData = data
    ctmJobID = w3rkstatt.getJsonValue(path="$.job_id", data=ctmData)
    ctmJobRunCounter = w3rkstatt.getJsonValue(path="$.run_counter",
                                              data=ctmData)
    value = ctm.getCtmArchiveJobLog(ctmApiClient=ctmApiClient,
                                    ctmJobID=ctmJobID,
                                    ctmJobRunCounter=ctmJobRunCounter)
    if _localDebugAdv:
        logger.debug('CMT Job Log Raw: %s', value)
    return value
Ejemplo n.º 3
0
def getCtmArchiveJobRunOutput(ctmApiClient, data):
    ctmData = data
    ctmJobID = w3rkstatt.getJsonValue(path="$.job_id", data=ctmData)
    ctmJobRunCounter = w3rkstatt.getJsonValue(path="$.run_counter",
                                              data=ctmData)
    value = ctm.getCtmArchiveJobOutput(ctmApiClient=ctmApiClient,
                                       ctmJobID=ctmJobID,
                                       ctmJobRunId=ctmJobRunCounter)
    ctmJobOutput = ctm.transformCtmJobOutput(data=value)
    if _localDebugAdv:
        logger.debug('CMT Job Output Raw: %s', ctmJobOutput)
    return ctmJobOutput
Ejemplo n.º 4
0
def getCtmJobInfo(ctmApiClient, data):
    # Get Job Info via CTM API
    ctmData = data
    ctmDataCenter = w3rkstatt.getJsonValue(path="$.data_center", data=ctmData)
    ctmOrderId = w3rkstatt.getJsonValue(path="$.order_id", data=ctmData)
    if _localDebugAdv:
        logger.info('CTM Get Job Info: "%s:%s"', ctmDataCenter, ctmOrderId)
    jData = ctm.getCtmJobInfo(ctmApiClient=ctmApiClient,
                              ctmServer=ctmDataCenter,
                              ctmOrderID=ctmOrderId)

    return jData
Ejemplo n.º 5
0
def extractChangeState(change):
    '''
    Extract ITSM Change state

    :param str change: change details
    :return: content
    :rtype: str
    :raises ValueError: N/A
    :raises TypeError: N/A    
    '''

    status = ""
    jData = json.loads(change)
    crqInfo = w3rkstatt.getJsonValue(path="$.entries..values", data=jData)

    if len(crqInfo) > 1:
        stateId = int(
            w3rkstatt.getJsonValue(path="$.ChangeRequestStatusString",
                                   data=crqInfo))
    else:
        stateId = 99

    # jQl    = "$.*.change-request-status.mapping.[?id='" + stateId + "')].name"
    if (stateId == 0):
        status = "Draft"
    elif (stateId == 1):
        status = "Request For Authorization"
    elif (stateId == 2):
        status = "Request For Change"
    elif (stateId == 3):
        status = "Planning In Progress"
    elif (stateId == 4):
        status = "Scheduled For Review"
    elif (stateId == 5):
        status = "Scheduled For Approval"
    elif (stateId == 6):
        status = "Scheduled"
    elif (stateId == 7):
        status = "Implementation In Progress"
    elif (stateId == 8):
        status = "Pending"
    elif (stateId == 9):
        status = "Rejected"
    elif (stateId == 10):
        status = "Completed"
    elif (stateId == 11):
        status = "Closed"
    elif (stateId == 12):
        status = "Cancelled"
    else:
        status = "Unknown"

    return status
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
def demoSMTP():

    email_from = None
    email_from_name = None
    email_rcpt = w3rkstatt.getJsonValue(path="$.MAIL.user", data=jCfgData)
    email_subject = "W3rkstatt Community Python Scripts"
    email_message = "User Acceptance Testing in progress"
    email_data = None
    email_template = None

    # Create E-Mail Body
    email_html_message = smtp.prepareEmail(eml_from=email_from,
                                           eml_from_name=email_from_name,
                                           eml_to=email_rcpt,
                                           eml_subbject=email_subject,
                                           eml_message=email_message,
                                           eml_data=email_data,
                                           eml_template=email_template)

    # Send E-mail
    if smtp_ssl:
        smtp.sendEmailSmtpSSL(eml_from=email_from,
                              eml_to=email_rcpt,
                              eml_message=email_html_message)
    else:
        smtp.sendEmailSmtp(eml_from=email_from,
                           eml_to=email_rcpt,
                           eml_message=email_html_message)
Ejemplo n.º 8
0
def createChangeWorklog(token, data):
    '''
    Create ITSM Change Worklog entry

    :param str token: authentication token
    :param str data: application data
    :return: content
    :rtype: dict
    :raises ValueError: N/A
    :raises TypeError: N/A    
    '''

    authToken = "AR-JWT " + token
    headers = {
        'content-type': 'application/json',
        'cache-control': "no-cache",
        'Authorization': authToken
    }
    entryFields = "fields=values(Infrastructure Change Id)"
    entryRespone = apiPost(form=itsm_form_crq,
                           headers=headers,
                           body=data,
                           fields=entryFields).replace(" ", "")
    entryJson = json.loads(entryRespone)
    entryID = w3rkstatt.getJsonValue(path="$.*.InfrastructureChangeId",
                                     data=entryJson)
    return entryID
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
def getCtmJobRunLog(ctmApiClient, data):
    ctmData = data
    ctmJobID = w3rkstatt.getJsonValue(path="$.job_id", data=ctmData)
    ctmJobRunCounter = w3rkstatt.getJsonValue(path="$.run_counter", data=data)
    if _localDebugAdv:
        logger.info('CTM Get Job Log: "%s # %s"', ctmJobID, ctmJobRunCounter)

    sLogData = ctm.getCtmJobLog(ctmApiClient=ctmApiClient, ctmJobID=ctmJobID)
    if _localDebugAdv:
        logger.info('CMT QA Get Job Run Log: %s', sLogData)

    # Based on config, extract level of details
    if ctm_job_log_level == "full":
        jCtmJobLog = ctm.transformCtmJobLog(data=sLogData)
    else:
        jCtmJobLog = ctm.transformCtmJobLogMini(data=sLogData,
                                                runCounter=ctmJobRunCounter)

    if _localDebugAdv:
        logger.debug('CMT Job Log Raw: %s', jCtmJobLog)

    sCtmJobLog = str(jCtmJobLog)

    return sCtmJobLog
Ejemplo n.º 11
0
def demoITSM():
    itsm_demo_crq = w3rkstatt.getJsonValue(path="$.ITSM.change.demo",
                                           data=jCfgData)
    itsm_demo_inc = w3rkstatt.getJsonValue(path="$.ITSM.incident.demo",
                                           data=jCfgData)

    authToken = itsm.authenticate()
    if authToken != None:
        # Demo ITSM Change Integration
        if itsm_demo_crq:
            changeID = testChangeCreate(token=authToken)
            logger.info('ITSM: Change   ID: "%s"', changeID)

            crqInfo = itsm.getChange(token=authToken, change=changeID)
            logger.info('ITSM: Change Info: %s', crqInfo)

            crqStatus = itsm.extractChangeState(change=crqInfo)
            logger.info('ITSM: Change State: "%s"', crqStatus)

        # Demo ITSM Incident Integration
        if itsm_demo_inc:
            incidentID = testIncidentCreate(token=authToken)
            logger.info('ITSM: Incident ID: "%s"', incidentID)

            incInfo = itsm.getIncident(token=authToken, incident=incidentID)
            logger.info('ITSM: Incident: %s', incInfo)

            incStatus = itsm.getIncidentStatus(token=authToken,
                                               incident=incidentID)
            logger.info('ITSM: Incident State: "%s"', incStatus)

            incWLogStatus = testIncidentWorklog(token=authToken,
                                                incident=incidentID)
            logger.info('ITSM: Incident Worklog Status: "%s"', incWLogStatus)

        itsm.logout(token=authToken)
Ejemplo n.º 12
0
def getIncidentStatus(token, incident):
    '''
    Get ITSM Incident status

    :param str token: authentication token
    :param str incident: incident  number
    :return: content
    :rtype: dict
    :raises ValueError: N/A
    :raises TypeError: N/A    
    '''

    incInfo = json.loads(getIncident(token=token, incident=incident))
    status = w3rkstatt.getJsonValue(path="$.values.Status", data=incInfo)

    return status
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
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
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
def testIncidentCreate(token):
    data = {
        "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":
            "CTM WCM: Incident Creation " + str(epoch),
            "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),
            "TemplateID":
            "AGGAA5V0GO2Y0APMV93LPLY5FREVV1"
            # "Urgency" : "3-Medium",
            # "Vendor Ticket Number" : "INC9969625",
            # "z1D_View_Access":"Internal",
            # "z1D_WorklogDetails": "Test",
            # "z1D_Activity_Type": "General Information",
            # "z1D_CommunicationSource": "Other",
            # "z1D_Secure_Log": "Locked",
            # "z1D_Details": "Adding Work notes"
        }
    }
    data2log = w3rkstatt.jsonTranslateValuesAdv(data=data)
    logger.info('ITSM Incident Data: %s ', data2log)
    result = itsm.createIncident(token, data)
    return result
Ejemplo n.º 17
0
    from src import w3rkstatt as w3rkstatt
    from src import core_ctm as ctm

import time, logging
import sys, getopt, platform, argparse
import os, json
from collections import OrderedDict
import pandas as pd
from io import StringIO

import jsonpath_rw_ext
from jsonpath_ng.ext import parse

# Get configuration from bmcs_core.json
jCfgData = w3rkstatt.getProjectConfig()
cfgFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.config_folder",
                                   data=jCfgData)
logFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.log_folder", data=jCfgData)
tmpFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.template_folder",
                                   data=jCfgData)
cryptoFile = w3rkstatt.getJsonValue(path="$.DEFAULT.crypto_file",
                                    data=jCfgData)

data_folder = w3rkstatt.getJsonValue(path="$.DEFAULT.data_folder",
                                     data=jCfgData)
ctm_host = w3rkstatt.getJsonValue(path="$.CTM.host", data=jCfgData)
ctm_port = w3rkstatt.getJsonValue(path="$.CTM.port", data=jCfgData)

# Assign module defaults
_localDebug = False
_localDebugAdv = False
_localInfo = True
Ejemplo n.º 18
0
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
Ejemplo n.º 19
0
def testChangeCreate(token):
    timeDelta = w3rkstatt.getJsonValue(path="$.ITSM.defaults.timedelta",
                                       data=jCfgData)
    startDate = w3rkstatt.getCurrentDate(timeFormat=_timeFormat)
    endDate = w3rkstatt.addTimeDelta(date=startDate,
                                     timeFormat=_timeFormat,
                                     delta=timeDelta)

    data = {
        "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":
            "CTM WCM: Change Creation " + str(epoch),
            "Impact":
            w3rkstatt.getJsonValue(path="$.ITSM.change.impact", data=jCfgData),
            "Urgency":
            w3rkstatt.getJsonValue(path="$.ITSM.change.urgency",
                                   data=jCfgData),
            "Status":
            w3rkstatt.getJsonValue(path="$.ITSM.change.status", data=jCfgData),
            "Status Reason":
            w3rkstatt.getJsonValue(path="$.ITSM.change.status_reason",
                                   data=jCfgData),
            "Vendor Ticket Number":
            "CMT 99",
            "ServiceCI":
            w3rkstatt.getJsonValue(path="$.ITSM.defaults.service-ci",
                                   data=jCfgData),
            "Company3":
            w3rkstatt.getJsonValue(path="$.ITSM.defaults.support-company",
                                   data=jCfgData),
            "Support Organization":
            w3rkstatt.getJsonValue(path="$.ITSM.defaults.support-organization",
                                   data=jCfgData),
            "Support Group Name":
            w3rkstatt.getJsonValue(path="$.ITSM.defaults.assigned-group",
                                   data=jCfgData),
            "Location Company":
            w3rkstatt.getJsonValue(path="$.ITSM.defaults.location-company",
                                   data=jCfgData),
            "Region":
            w3rkstatt.getJsonValue(path="$.ITSM.defaults.region",
                                   data=jCfgData),
            "Site Group":
            w3rkstatt.getJsonValue(path="$.ITSM.defaults.site-group",
                                   data=jCfgData),
            "Site":
            w3rkstatt.getJsonValue(path="$.ITSM.defaults.site", 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 Cat Tier 1(2)":
            w3rkstatt.getJsonValue(path="$.ITSM.defaults.prod_cat_1",
                                   data=jCfgData),
            "Product Cat Tier 2 (2)":
            w3rkstatt.getJsonValue(path="$.ITSM.defaults.prod_cat_2",
                                   data=jCfgData),
            "Product Cat Tier 3 (2)":
            w3rkstatt.getJsonValue(path="$.ITSM.defaults.prod_cat_3",
                                   data=jCfgData),
            "Scheduled Start Date":
            startDate,
            "Scheduled End Date":
            endDate,
            "TemplateID":
            itsm.itsm_tmpl_crq
        }
    }
    result = itsm.createChange(token, data)
    return result
Ejemplo n.º 20
0
def demoCTM():
    # CTM Login
    try:
        ctmApiObj = ctm.getCtmConnection()
        ctmApiClient = ctmApiObj.api_client
        _ctmActiveApi = True
    except:
        _ctmActiveApi = False
        ctmApiClient = None

    # Log CTM login state
    logger.info('CTM Login Status: %s', _ctmActiveApi)

    ctm_demo_agt = w3rkstatt.getJsonValue(path="$.CTM.ctmag.demo",
                                          data=jCfgData)
    ctm_demo_jobs = w3rkstatt.getJsonValue(path="$.CTM.jobs.demo",
                                           data=jCfgData)
    ctm_demo_alerts = w3rkstatt.getJsonValue(path="$.CTM.alerts.demo",
                                             data=jCfgData)

    if _ctmActiveApi:
        if ctm_demo_alerts:
            ctm_alert_ids = w3rkstatt.getJsonValue(path="$.CTM.alerts.ids",
                                                   data=jCfgData)
            ctm_alert_msg = w3rkstatt.getJsonValue(path="$.CTM.alerts.comment",
                                                   data=jCfgData)
            ctm_alert_urgency = w3rkstatt.getJsonValue(
                path="$.CTM.alerts.urgency", data=jCfgData)
            ctm_alert_status = w3rkstatt.getJsonValue(
                path="$.CTM.alerts.status", data=jCfgData)

            # Alert Comment
            # ctmAlertsCore   = updateCtmAlertCore(ctmApiClient=ctmApiClient,ctmAlertIDs=ctm_alert_ids, ctmAlertComment=ctm_alert_msg, ctmAlertUrgency=ctm_alert_urgency)
            # logger.info('CTM Alert Core: %s', ctmAlertsCore)

            # Alert Status
            ctmAlertsStatus = ctm.updateCtmAlertStatus(
                ctmApiClient=ctmApiClient,
                ctmAlertIDs=ctm_alert_ids,
                ctmAlertStatus=ctm_alert_status)
            logger.info('CTM Alert Status: %s', ctmAlertsStatus)
            # ctmAlerts = updateCtmAlert(ctmApiClient=ctmApiClient,ctmAlertIDs=ctm_alert_ids, ctmAlertComment=ctm_alert_msg)
            # ctmAlerts = w3rkstatt.jsonTranslateValues(ctmAlerts)

            # logger.info('CTM Alert: %s', ctmAlerts)

        if ctm_demo_agt:
            ctm_servers = w3rkstatt.getJsonValues(
                path="$.CTM.datacenter[*].name", data=jCfgData)
            for server in ctm_servers:
                ctmAgents = ctm.getCtmAgents(ctmApiClient=ctmApiClient,
                                             ctmServer=server)
                logger.info('CTM Server: %s', server)
                logger.info('CTM Agents: %s', ctmAgents)

        if ctm_demo_jobs:
            ctm_job_oderid = w3rkstatt.getJsonValue(path="$.CTM.jobs.oderid",
                                                    data=jCfgData)
            ctm_job_srv = w3rkstatt.getJsonValue(path="$.CTM.jobs.server",
                                                 data=jCfgData)
            ctm_job_runid = ctm_job_srv + ":" + ctm_job_oderid

            ctmJobInfo = ctm.getCtmJobInfo(ctmApiClient=ctmApiClient,
                                           ctmServer=ctm_job_srv,
                                           ctmOrderID=ctm_job_oderid)
            # ctmJobStatusAdv = getCtmJobStatusAdv(ctmApiClient=ctmApiClient,ctmServer=ctm_job_srv,ctmOrderID=ctm_job_oderid)
            logger.info('CTM Job: %s', ctmJobInfo)
Ejemplo n.º 21
0
from email.mime.multipart import MIMEMultipart
from json2html import *

# handle dev environment vs. production 
try:
    import w3rkstatt as w3rkstatt
except:
    # fix import issues for modules
    sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
    from src import w3rkstatt as w3rkstat



# Get configuration from bmcs_core.json
jCfgData   = w3rkstatt.getProjectConfig()
cfgFolder  = w3rkstatt.getJsonValue(path="$.DEFAULT.config_folder",data=jCfgData)
logFolder  = w3rkstatt.getJsonValue(path="$.DEFAULT.log_folder",data=jCfgData)
tmpFolder  = w3rkstatt.getJsonValue(path="$.DEFAULT.template_folder",data=jCfgData)
cryptoFile = w3rkstatt.getJsonValue(path="$.DEFAULT.crypto_file",data=jCfgData)


# SMTP Server Settigns
smtp_host      = w3rkstatt.getJsonValue(path="$.MAIL.host",data=jCfgData)
smtp_port      = w3rkstatt.getJsonValue(path="$.MAIL.port",data=jCfgData)
smtp_ssl       = w3rkstatt.getJsonValue(path="$.MAIL.ssl",data=jCfgData)
smtp_user      = w3rkstatt.getJsonValue(path="$.MAIL.user",data=jCfgData)
smtp_user_name = w3rkstatt.getJsonValue(path="$.MAIL.display",data=jCfgData)
smtp_pwd       = w3rkstatt.getJsonValue(path="$.MAIL.pwd",data=jCfgData)

# E-Mail Template
template_name  = w3rkstatt.getJsonValue(path="$.MAIL.template",data=jCfgData)
Ejemplo n.º 22
0
    import core_tso as tso
    import core_smtp as smtp
except:
    # fix import issues for modules
    sys.path.append(
        os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
    from src import w3rkstatt as w3rkstatt
    from src import core_ctm as ctm
    from src import core_itsm as itsm
    from src import core_tsim as tsim
    from src import core_tso as tso
    from src import core_smtp as smtp

# Get configuration from bmcs_core.json
jCfgData = w3rkstatt.getProjectConfig()
cfgFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.config_folder",
                                   data=jCfgData)
logFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.log_folder", data=jCfgData)
tmpFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.template_folder",
                                   data=jCfgData)
cryptoFile = w3rkstatt.getJsonValue(path="$.DEFAULT.crypto_file",
                                    data=jCfgData)
smtp_ssl = w3rkstatt.getJsonValue(path="$.MAIL.ssl", data=jCfgData)

logger = w3rkstatt.logging.getLogger(__name__)
logFile = w3rkstatt.getJsonValue(path="$.DEFAULT.log_file", data=jCfgData)
loglevel = w3rkstatt.getJsonValue(path="$.DEFAULT.loglevel", data=jCfgData)
epoch = time.time()
hostName = w3rkstatt.getHostName()
hostIP = w3rkstatt.getHostIP(hostName)
hostFqdn = w3rkstatt.getHostFqdn(hostName)
domain = w3rkstatt.getHostDomain(hostFqdn)
Ejemplo n.º 23
0
import time, datetime
import sys, getopt

# handle dev environment vs. production
try:
    import w3rkstatt as w3rkstatt
except:
    # fix import issues for modules
    sys.path.append(
        os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
    from src import w3rkstatt as w3rkstat

# Define global variables from w3rkstatt.ini file
# Get configuration from bmcs_core.json
jCfgData = w3rkstatt.getProjectConfig()
cfgFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.config_folder",
                                   data=jCfgData)
logFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.log_folder", data=jCfgData)
tmpFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.template_folder",
                                   data=jCfgData)
cryptoFile = w3rkstatt.getJsonValue(path="$.DEFAULT.crypto_file",
                                    data=jCfgData)

tsim_host = w3rkstatt.getJsonValue(path="$.TSIM.host", data=jCfgData)
tsws_api_ver = w3rkstatt.getJsonValue(path="$.TSPS.api_version", data=jCfgData)
tsps_host = w3rkstatt.getJsonValue(path="$.TSPS.host", data=jCfgData)
tsom_user = w3rkstatt.getJsonValue(path="$.TSIM.user", data=jCfgData)
tsom_pwd = w3rkstatt.getJsonValue(path="$.TSIM.pwd", data=jCfgData)
tsom_tenant = w3rkstatt.getJsonValue(path="$.TSIM.tenant", data=jCfgData)
tsps_ssl_ver = w3rkstatt.getJsonValue(path="$.TSPS.ssl_ignore", data=jCfgData)
# routingId - Name of the cell to send events to
tsim_cell = w3rkstatt.getJsonValue(path="$.TSIM.cell", data=jCfgData)
Ejemplo n.º 24
0
# handle dev environment vs. production
try:
    import w3rkstatt as w3rkstatt
except:
    # fix import issues for modules
    sys.path.append(
        os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
    from src import w3rkstatt as w3rkstat

# Get configuration from bmcs_core.json
# jCfgFile     = os.path.join( w3rkstatt.getCurrentFolder(), "bmcs_core.json")
# jCfgData     = w3rkstatt.getFileJson(jCfgFile)

# Get configuration from bmcs_core.json
jCfgData = w3rkstatt.getProjectConfig()
cfgFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.config_folder",
                                   data=jCfgData)
logFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.log_folder", data=jCfgData)
tmpFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.template_folder",
                                   data=jCfgData)
cryptoFile = w3rkstatt.getJsonValue(path="$.DEFAULT.crypto_file",
                                    data=jCfgData)

tso_host = w3rkstatt.getJsonValue(path="$.TSO.host", data=jCfgData)
tso_port = w3rkstatt.getJsonValue(path="$.TSO.port", data=jCfgData)
tso_ssl = w3rkstatt.getJsonValue(path="$.TSO.ssl", data=jCfgData)
tso_ssl_ver = w3rkstatt.getJsonValue(path="$.TSO.ssl_verification",
                                     data=jCfgData)
tso_user = w3rkstatt.getJsonValue(path="$.TSO.user", data=jCfgData)
tso_pwd = w3rkstatt.getJsonValue(path="$.TSO.pwd", data=jCfgData)

# ITSM REST API
Ejemplo n.º 25
0
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
Ejemplo n.º 26
0
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)
Ejemplo n.º 27
0
    from src import w3rkstatt as w3rkstatt
    from src import core_ctm as ctm

import time, logging
import sys, getopt, platform, argparse
import os, json
from collections import OrderedDict
import collections
from xml.sax.handler import ContentHandler
from xml.sax import make_parser

# Get configuration from bmcs_core.json

# Get configuration from bmcs_core.json
jCfgData = w3rkstatt.getProjectConfig()
cfgFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.config_folder",
                                   data=jCfgData)
logFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.log_folder", data=jCfgData)
tmpFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.template_folder",
                                   data=jCfgData)
cryptoFile = w3rkstatt.getJsonValue(path="$.DEFAULT.crypto_file",
                                    data=jCfgData)

data_folder = w3rkstatt.getJsonValue(path="$.DEFAULT.data_folder",
                                     data=jCfgData)
ctm_host = w3rkstatt.getJsonValue(path="$.CTM.host", data=jCfgData)
ctm_port = w3rkstatt.getJsonValue(path="$.CTM.port", data=jCfgData)

integration_itsm_enabled = w3rkstatt.getJsonValue(path="$.CTM.itsm.enabled",
                                                  data=jCfgData)
integration_tsim_enabled = w3rkstatt.getJsonValue(path="$.CTM.tsim.enabled",
                                                  data=jCfgData)
Ejemplo n.º 28
0
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
Ejemplo n.º 29
0
# handle dev environment vs. production
try:
    import w3rkstatt as w3rkstatt
except:
    # fix import issues for modules
    sys.path.append(
        os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
    from src import w3rkstatt as w3rkstat

# Get configuration from bmcs_core.json
# jCfgFile     = os.path.join( w3rkstatt.getCurrentFolder(), "bmcs_core.json")
# jCfgData     = w3rkstatt.getFileJson(jCfgFile)

# Get configuration from bmcs_core.json
jCfgData = w3rkstatt.getProjectConfig()
cfgFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.config_folder",
                                   data=jCfgData)
logFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.log_folder", data=jCfgData)
tmpFolder = w3rkstatt.getJsonValue(path="$.DEFAULT.template_folder",
                                   data=jCfgData)
cryptoFile = w3rkstatt.getJsonValue(path="$.DEFAULT.crypto_file",
                                    data=jCfgData)

itsm_host = w3rkstatt.getJsonValue(path="$.ITSM.host", data=jCfgData)
itsm_port = w3rkstatt.getJsonValue(path="$.ITSM.port", data=jCfgData)
itsm_ssl = w3rkstatt.getJsonValue(path="$.ITSM.ssl", data=jCfgData)
itsm_ssl_ver = w3rkstatt.getJsonValue(path="$.ITSM.ssl_verification",
                                      data=jCfgData)
itsm_user = w3rkstatt.getJsonValue(path="$.ITSM.user", data=jCfgData)
itsm_pwd = w3rkstatt.getJsonValue(path="$.ITSM.pwd", data=jCfgData)
itsm_api_ns = w3rkstatt.getJsonValue(path="$.ITSM.api_namespace",
                                     data=jCfgData)