Пример #1
0
def CRUDComponents():
    cachetComponentExistences = getCachetComponents("group: {component: False}")
    cachetComponentIDs = getCachetComponents("group: {component: id}")

    # Check which components are already there and mark them accordingly.
    # If a component is not found if will be created.
    for providerName, getComponents in componentFunctions:
        groupName = providerName
        for component in getComponents():
            if component['name'] in cachetComponentExistences[groupName]:
                cachetComponentExistences[groupName][component['name']] = True

                componentID = cachetComponentIDs[groupName][component['name']]
                componentStatus = component['status']
                currentComponentStatus = latestComponentStatuses.get(componentID, 0)
                latestComponentStatuses[componentID] = max(componentStatus, currentComponentStatus)
            else:
                createComponent(component)

    # All components not marked previously will be deleted
    componentIDs = getCachetComponents("group: {component: id}")
    for group in cachetComponentExistences:
        for component in cachetComponentExistences[group]:
            if cachetComponentExistences[group][component] == False:
                deleteComponent(componentIDs[group][component])

    if debug:
        print("Components in Cachet before they where updated:")
        pprint(cachetComponentExistences)
        print("\nEnabled Components:")
        pprint(componentFunctions)
        print("\nComponents to IDs dict:")
        pprint(componentIDs)
Пример #2
0
def CRUDGroups():
    cachetGroups = getCachetGroups("group: False")
    enabledGroups = [module.providerName for module in modules]

    # Check which groups are already there and mark them accordingly.
    # If a group is not found if will be created.
    for group in enabledGroups:
        if group in cachetGroups:
            cachetGroups[group] = True
        else:
            createGroup(group)

    # All groups not marked previously will be deleted
    groupIDs = getCachetGroups("group: id")
    componentIDs = getCachetComponents("group: {component: id}")
    for group in cachetGroups:
        if cachetGroups[group] == False:
            for componentID in componentIDs[group].values():
                deleteComponent(componentID)
            deleteGroup(groupIDs[group])

    if debug:
        print("Groups in Cachet before they where updated:")
        pprint(cachetGroups.keys())
        print("\nEnabled Groups:")
        pprint(enabledGroups)
        print("\nGroups to IDs dict:")
        pprint(groupIDs)
        print("\nComponents to IDs dict:")
        pprint(componentIDs)
Пример #3
0
def getComponents():
    components = []

    groupIDs = getCachetGroups("group: id")
    componentIDs = getCachetComponents("groupID: {component: id}")
    rawComponents = 

    for rawComponent in rawComponents:
        name = 
        description = 
        verbalStatus = 
        status = convert____ComponentStatus(verbalStatus)
        groupID = groupIDs[providerName]
        componentID = componentIDs.get(groupID, {}).get(name)
        provider = providerName

        component = {
            'name': name,
            'description': description,
            'verbalStatus': verbalStatus,
            'status': status,
            'group_id': groupID,
            'component_id': componentID,
            'provider': provider
        }

        if isRelevantComponent(providerName, component):
            components.append(component)

    return components
Пример #4
0
def getComponents():
    # DomainFactory doesn't expose Components at the time being
    components = []

    groupIDs = getCachetGroups("group: id")
    componentIDs = getCachetComponents("groupID: {component: id}")

    name = "Allgemein"
    description = "DomainFactory Mail-Service"
    status = 1
    groupID = groupIDs[providerName]
    componentID = componentIDs.get(groupID, {}).get(name)
    provider = providerName

    generalComponent = {
        'name': name,
        'description': description,
        'status': status,
        'group_id': groupID,
        'component_id': componentID,
        'provider': provider
    }

    if isRelevantComponent(providerName, generalComponent):
        components.append(generalComponent)

    return components
Пример #5
0
def getComponents():
    components = []

    groupIDs = getCachetGroups("group: id")
    componentIDs = getCachetComponents("groupID: {component: id}")
    rawComponents = parsedWebPage.select(".component")

    componentDescription = {
        "Basic Telephony":
        "Basic telephony, incoming/outgoing calls, phone registration etc.",
        "Secondary Telephony":
        "Secondary services like conferencing, eFax, voicemail",
        "Administration":
        "Service portal, CDR portal, mynfon.net",
        "User self care":
        "NControl, star codes, XML menus etc.",
        "Devices":
        "Phone provisioning, FMC, device incidents",
        "PSTN-Termination":
        "Incoming/Outgoing telephony to/from other carriers/PSTN",
        "Upstream/Peerings":
        "IP connectivity to the internet and other carriers",
        "Third Party Integration / Value Add Services":
        "Skype for Business connectors, NMeeting+, voice recording etc."
    }

    for rawComponent in rawComponents:
        name = rawComponent.select(".component_name")[0].text.strip()
        description = componentDescription[name]
        verbalStatus = rawComponent.select(".component-status")[0].text.strip()
        status = convertNfonComponentStatus(verbalStatus)
        groupID = groupIDs[providerName]
        componentID = componentIDs.get(groupID, {}).get(name)
        provider = providerName

        component = {
            'name': name,
            'description': description,
            'verbalStatus': verbalStatus,
            'status': status,
            'group_id': groupID,
            'component_id': componentID,
            'provider': provider
        }

        if isRelevantComponent(providerName, component):
            components.append(component)

    return components
Пример #6
0
def convertNfonComponents(verbalComponents):
    componentIDs = getCachetComponents("group: {component: id}")

    if verbalComponents.find(",") != -1:
        componentID = [
            componentIDs[providerName][component]
            for component in verbalComponents.split(", ")
        ][0]
    else:
        component = verbalComponents
        if component in componentIDs[providerName]:
            componentID = componentIDs[providerName][component]
        else:
            componentID = None

    return componentID
Пример #7
0
def getIncidents():
    incidents = []

    rawIncidents = parsedWebPage.select(".error_block")
    if not rawIncidents:
        return incidents

    componentIDs = getCachetComponents("group: {component: id}")

    for rawIncident in rawIncidents:
        provider = providerName
        name = rawIncident.select("b")[0].text
        link = statusURL
        verbalComponents = "Allgemein"
        description = "Leistungsprobleme"
        updates = scrapIncidentUpdates(rawIncident)
        providerCreatedAt = updates[0]['date']
        status = updates[-1]['status']
        componentID = componentIDs.get(providerName).get('Allgemein')
        componentStatus = convertDomainfactoryComponentStatus(status)
        locations = None
        message = buildIncidentMessage(**locals())

        incident = {
            'name': name,
            'message': message,
            'description': description,
            'status': status,
            'verbalComponents': verbalComponents,
            'component_id': componentID,
            'component_status': componentStatus,
            'provider_created_at': providerCreatedAt,
            'locations': locations,
            'updates': updates,
            'provider': provider,
            'link': link
        }

        if isRelevantIncident(providerName, incident):
            setIncidentMarker(incident)
            incidents.append(incident)

    return incidents
Пример #8
0
def CRUDIncidents():
    incidentIDs = getCachetIncident("incidentHash: id")

    # Check which incidents and update them if already there or create them otherwise.
    for providerName, getIncidents in incidentFunctions:
        for incident in getIncidents():
            componentID = incident['component_id']
            componentStatus = incident['component_status']
            currentComponentStatus = latestComponentStatuses.get(
                componentID, 0)
            latestComponentStatuses[componentID] = max(componentStatus,
                                                       currentComponentStatus)

            incidentHash = hashIncident(incident)
            if incidentHash in incidentIDs:
                numberOfNewUpdates = len(incident['updates']) - len(
                    getIncidentUpdates(incidentIDs[incidentHash]))
                if numberOfNewUpdates > 0:
                    updateIncident(incidentIDs[incidentHash], incident,
                                   numberOfNewUpdates)
                else:
                    log(
                        "Info",
                        "Incident {name} with the id {id} is up-to-date".
                        format(name=incident['name'],
                               id=incidentIDs[incidentHash]))
            else:
                createIncident(incident)

    for componentID, latestComponentStatus in latestComponentStatuses.items():
        cachetComponentStatuses = getCachetComponents("id: status")
        if latestComponentStatus != cachetComponentStatuses[componentID]:
            updateComponentStatus(componentID, latestComponentStatus)

    if debug:
        print("Incidents in Cachet before they where updated:")
        pprint(incidentIDs)
        print("\nEnabled Incidents:")
        pprint(incidentFunctions)