Beispiel #1
0
def notification_sniffer(guhHost, guhPort):
    global commandId

    commandId = 0
    print "Connecting notification handler..."
    try:
        tn = telnetlib.Telnet(guhHost, guhPort)
    except:
        print "ERROR: notification socket could not connect the to guh-server. \n"
        return None
    print "...OK \n"

    #enable_notification(notificationSocket)
    enable_notification(tn.get_socket())

    try:
        x = None
        while (x != ord('\n') and x != 27):
            socket_list = [sys.stdin, tn.get_socket()]
            read_sockets, write_sockets, error_sockets = select.select(
                socket_list, [], [])
            for sock in read_sockets:
                # notification messages:
                if sock == tn.get_socket():
                    packet = tn.read_until("}\n")
                    packet = json.loads(packet)
                    guh.print_json_format(packet)
                elif sock == sys.stdin:
                    x = sys.stdin.readline()
                    return None
    finally:
        tn.close()
        print "Notification socket closed."
Beispiel #2
0
def list_rule_details():
    ruleDescription = select_rule()
    if ruleDescription == None:
        print "\n    No rules found"
        return None
    params = {}
    params['ruleId'] = ruleDescription['id']
    rule = guh.send_command("Rules.GetRuleDetails", params)['params']['rule']
    print guh.print_json_format(rule)
    print "========================================================"
    print "-> Details for rule \"%s\" (%s):\n" % (rule['name'], rule['id'])
    print "Rule is %s" % (print_rule_enabled_status(bool(rule['enabled'])))
    print "Rule is %s" % (print_rule_active_status(bool(rule['active'])))
    print "Rule is %s" % (print_rule_executable_status(bool(
        rule['executable'])))

    print "\nTimeDescriptor:\n"
    timedescriptor.printTimeDescriptor(rule['timeDescriptor'])

    if len(rule['eventDescriptors']) > 0:
        print "\nEvents:\n"
        events.print_eventDescriptors(rule['eventDescriptors'])
    if rule['stateEvaluator']:
        print "\nStates:\n",
        states.print_stateEvaluator(rule['stateEvaluator'])
    print "\nActions:\n"
    ruleactions.print_ruleActionList(rule['actions'])
    if len(rule['exitActions']) > 0:
        print "\nExit actions:\n"
        ruleactions.print_ruleActionList(rule['exitActions'])
Beispiel #3
0
def show_network_status():
    params = {}
    response = guh.send_command("NetworkManager.GetNetworkStatus", params)
    if 'status' in response['params']:
        guh.print_json_format(response['params']['status'])
    else:
        guh.print_networkmanager_error_code(
            response['params']['networkManagerError'])
Beispiel #4
0
def method_last_72_hours():
    global guhHost
    global guhPort
    params = logs.create_last_time_logfilter(72 * 60)
    print "\nThe filter:\n"
    guh.print_json_format(params)
    guh.debug_stop()
    if params:
        logs.log_window(guhHost, guhPort, params)
Beispiel #5
0
def method_rule_logs():
    global guhHost
    global guhPort
    params = logs.create_rule_logfilter()
    print "\nThe filter:\n"
    guh.print_json_format(params)
    guh.debug_stop()
    if params:
        logs.log_window(guhHost, guhPort, params)
Beispiel #6
0
def print_stateType():
    deviceId = devices.select_configured_device()
    device = devices.get_device(deviceId)
    if device == None:
        return None
    stateType = select_stateType(device['deviceClassId'])
    if stateType == None:
        return None
    guh.print_json_format(stateType)
Beispiel #7
0
def print_eventType():
    deviceId = devices.select_configured_device()
    device = devices.get_device(deviceId)
    if not device:
        return None
    eventType = select_eventType(device['deviceClassId'])
    if not eventType:
        print "\n    This device has no events"
        return None
    guh.print_json_format(eventType)
Beispiel #8
0
def set_language():
    params = {}
    languages = get_languages()
    selection = guh.get_selection(
        "Please select one of following allowed values:", languages)
    if selection == None:
        return None

    params['language'] = languages[selection]
    response = guh.send_command("Configuration.SetLanguage", params)
    guh.print_json_format(response['params'])
Beispiel #9
0
def enable_cloud_connection():
    params = {}
    options = ["enable", "disable"]
    selection = guh.get_selection(
        "Do you want to do with the cloud connection: ", options)
    if selection == 0:
        params['enable'] = True
    else:
        params['enable'] = False

    response = guh.send_command("Cloud.Enable", params)
    guh.print_json_format(response['params'])
Beispiel #10
0
def set_timezone():
    params = {}
    timeZones = []
    timeZones = get_timezones()
    selection = guh.get_selection(
        "Please select one of following allowed values:", timeZones)
    if selection == None:
        return None

    params['timeZone'] = timeZones[selection]
    response = guh.send_command("Configuration.SetTimeZone", params)
    guh.print_json_format(response['params'])
Beispiel #11
0
def print_actionType():
    deviceId = devices.select_configured_device()
    if deviceId == None:
        return None
    device = devices.get_device(deviceId)
    actionType = select_actionType(device['deviceClassId'])
    #print guh.print_json_format(actionType)
    if actionType == None:
        print "\n    This device has no actions"
        return None
    actionType = get_actionType(actionType['id'])
    guh.print_json_format(actionType)
Beispiel #12
0
def add_rule():
    params = {}
    params['name'] = raw_input("Please enter the name of the rule: ")

    print "\n========================================================"
    if selector.getYesNoSelection("Do you want to create a TimeDescriptor"):
        params['timeDescriptor'] = timedescriptor.createTimeDescriptor()

    if selector.getYesNoSelection(
            "Do you want to define \"Events\" for this rule?"):
        eventDescriptors = events.create_eventDescriptors()
        print guh.print_json_format(eventDescriptors)
        params['eventDescriptors'] = eventDescriptors

        if selector.getYesNoSelection(
                "Do you want to add conditions (\"States\") for the events?"):
            print "\n========================================================"
            raw_input("-> Create a state descriptor!  ")
            stateEvaluator = states.create_stateEvaluator()
            params['stateEvaluator'] = stateEvaluator

        params['actions'] = ruleactions.create_rule_actions(eventDescriptors)

    else:

        if selector.getYesNoSelection(
                "Do you want to define \"States\" for this rule?"):
            print "\n========================================================"
            raw_input("-> Press \"enter\" to create a state descriptor!  ")
            params['stateEvaluator'] = states.create_stateEvaluator()

        params['actions'] = ruleactions.create_rule_actions()

        if selector.getYesNoSelection(
                "Do you want to add (\"ExitActions\") for this rule?"):
            params['exitActions'] = ruleactions.create_rule_actions()

    params['enabled'] = selector.getBoolSelection(
        "-> Should the rule initially be enabled?")
    params['executable'] = selector.getBoolSelection(
        "-> Should the rule be executable?")

    print "\n========================================================\n"
    print "Adding rule with params:\n", guh.print_json_format(params)
    response = guh.send_command("Rules.AddRule", params)
    guh.print_rule_error_code(response['params']['ruleError'])
Beispiel #13
0
def add_configured_device(deviceClassId):
    deviceClass = get_deviceClass(deviceClassId)
    params = {}
    params['deviceClassId'] = deviceClassId
    params['name'] = raw_input("\nEnter the \"name\" of the device: ")
    deviceParams = parameters.read_params(deviceClass['paramTypes'])
    if deviceParams:
        params['deviceParams'] = deviceParams
    print "\nAdding device with params:", guh.print_json_format(params)
    response = guh.send_command("Devices.AddConfiguredDevice", params)
    guh.print_device_error_code(response['params']['deviceError'])
Beispiel #14
0
def read_params(paramTypes):
    params = []
    for paramType in paramTypes:
        print "\nThe ParamType looks like this:\n", guh.print_json_format(
            paramType)
        if any("allowedValues" in item for item in paramType):
            # has to be a string (for sorting list)
            allowedValues = []
            for value in paramType['allowedValues']:
                allowedValues.append(str(value))
            selection = guh.get_selection(
                "Please select one of following allowed values:",
                allowedValues)
            if selection == None:
                return None
            paramValue = paramType['allowedValues'][selection]
            param = {}
            param['paramTypeId'] = paramType['id']
            param['value'] = paramValue
        else:
            # make bool selectable to make shore they are "true" or "false"
            if paramType['type'] == "Bool":
                boolTypes = ["true", "false"]
                selectionString = "Please enter value for parameter \"%s\" (type: %s): " % (
                    paramType['name'], paramType['type'])
                selection = guh.get_selection(selectionString, boolTypes)
                if selection == None:
                    return None
                paramValue = boolTypes[selection]
            elif paramType['type'] == "Int":
                paramValue = int(
                    raw_input(
                        "Please enter value for parameter \"%s\" (type: %s): "
                        % (paramType['name'], paramType['type'])))
            elif paramType['type'] == "Double":
                paramValue = float(
                    raw_input(
                        "Please enter value for parameter \"%s\" (type: %s): "
                        % (paramType['name'], paramType['type'])))
            elif paramType['type'] == "Uint":
                paramValue = int(
                    raw_input(
                        "Please enter value for parameter \"%s\" (type: %s): "
                        % (paramType['name'], paramType['type'])))
            else:
                paramValue = raw_input(
                    "Please enter value for parameter \"%s\" (type: %s): " %
                    (paramType['name'], paramType['type']))
            param = {}
            param['paramTypeId'] = paramType['id']
            param['value'] = paramValue
        params.append(param)
    return params
Beispiel #15
0
def edit_params(currentDeviceParams, paramTypes):
    params = []
    for paramType in paramTypes:
        print "\nThe ParamType looks like this:\n", guh.print_json_format(
            paramType)
        if 'readOnly' in paramType:
            if paramType['readOnly'] == True:
                print "--------------------------------------------------------"
                print "\nThe param \"%s\" is not writable! (current = \"%s\")\n" % (
                    paramType['name'],
                    get_param_value(paramType['name'], currentDeviceParams))
                raw_input("\nPress \"enter\" to continue...\n")
                print "--------------------------------------------------------"
                continue
        param = {}
        if any("allowedValues" in item for item in paramType):
            title = "Please select one of following allowed values: (current = \"%s\")" % (
                get_param_value(paramType['name'], currentDeviceParams))
            selection = guh.get_selection(title, paramType['allowedValues'])
            if selection == None:
                return None
            paramValue = paramType['allowedValues'][selection]
            param['paramTypeId'] = paramType['id']
            param['value'] = paramValue
            params.append(param)
        else:
            # make bool selectable to make shore they are "true" or "false"
            if paramType['type'] == "Bool":
                boolTypes = ["true", "false"]
                selectionString = "Please enter value (currently: \"%s\") for parameter \"%s\" (type: %s): " % (
                    get_param_value(paramType['name'], currentDeviceParams),
                    paramType['name'], paramType['type'])
                selection = guh.get_selection(selectionString, boolTypes)
                if selection == None:
                    return None
                paramValue = boolTypes[selection]
                param['paramTypeId'] = paramType['id']
                param['value'] = paramValue
            else:
                paramValue = raw_input(
                    "Please enter value (currently: \"%s\") for parameter \"%s\" (type: %s): "
                    % (get_param_value(paramType['name'], currentDeviceParams),
                       paramType['name'], paramType['type']))
                param['paramTypeId'] = paramType['id']
                param['value'] = paramValue
        params.append(param)
    return params
Beispiel #16
0
def read_ruleActionParams(paramTypes, eventDescriptors=[]):
    params = []
    for paramType in paramTypes:
        print guh.print_json_format(paramType)
        if any("allowedValues" in item for item in paramType):
            selection = guh.get_selection(
                "Please select one of following allowed values:",
                paramType['allowedValues'])
            if selection == None:
                return None
            paramValue = paramType['allowedValues'][selection]
            param = {}
            param['paramTypeId'] = paramType['id']
            param['value'] = paramValue
            params.append(param)
        else:
            # check if we want normal action params or if we want to use an eventtypeid
            if eventDescriptors:
                selectionTypes = ["yes", "no"]
                selectionText = "-> Should the ruleActionParam \"%s\" depend on an event?" % (
                    paramType['name'])
                selection = guh.get_selection(selectionText, selectionTypes)
                if selection == None:
                    return None
                if selectionTypes[selection] == "yes":
                    eventTypeIds = []
                    for i in eventDescriptors:
                        eventTypeIds.append(i['eventTypeId'])
                    selection = guh.get_selection(
                        "Please select an eventTypeId", eventTypeIds)
                    eventTypeId = eventTypeIds[selection]
                    eventType = events.get_eventType(eventTypeId)
                    eventParamNames = []
                    eventParamTypeIds = []
                    for i in eventType['paramTypes']:
                        eventParamNames.append(i['name'])
                        eventParamTypeIds.append(i['id'])
                    paramSelection = guh.get_selection(
                        "Please select the name of the eventParam for the action",
                        eventParamNames)
                    param = {}
                    param['paramTypeId'] = paramType['id']
                    param['eventTypeId'] = eventTypeId
                    param['eventParamTypeId'] = eventParamTypeIds[
                        paramSelection]
                    params.append(param)
                else:
                    if paramType['type'] == "Bool":
                        boolTypes = ["true", "false"]
                        selectionString = "Please enter value for parameter %s (type: %s): " % (
                            paramType['name'], paramType['type'])
                        selection = guh.get_selection(selectionString,
                                                      boolTypes)
                        if selection == None:
                            return None
                        paramValue = boolTypes[selection]
                    elif paramType['type'] == "Int":
                        paramValue = int(
                            raw_input(
                                "Please enter value for parameter \"%s\" (type: %s): "
                                % (paramType['name'], paramType['type'])))
                    elif paramType['type'] == "Double":
                        paramValue = double(
                            raw_input(
                                "Please enter value for parameter \"%s\" (type: %s): "
                                % (paramType['name'], paramType['type'])))
                    elif paramType['type'] == "Uint":
                        paramValue = uint(
                            raw_input(
                                "Please enter value for parameter \"%s\" (type: %s): "
                                % (paramType['name'], paramType['type'])))
                    else:
                        paramValue = raw_input(
                            "Please enter value for parameter \"%s\" (type: %s): "
                            % (paramType['name'], paramType['type']))
                    param = {}
                    param['paramTypeId'] = paramType['id']
                    param['value'] = paramValue
                    params.append(param)
            else:
                # make bool selectable to make shore they are "true" or "false"
                if paramType['type'] == "Bool":
                    boolTypes = ["true", "false"]
                    selectionString = "Please enter value for parameter %s (type: %s): " % (
                        paramType['name'], paramType['type'])
                    selection = guh.get_selection(selectionString, boolTypes)
                    if selection == None:
                        return None
                    paramValue = boolTypes[selection]
                elif paramType['type'] == "Int":
                    paramValue = int(
                        raw_input(
                            "Please enter value for parameter \"%s\" (type: %s): "
                            % (paramType['name'], paramType['type'])))
                elif paramType['type'] == "Double":
                    paramValue = float(
                        raw_input(
                            "Please enter value for parameter \"%s\" (type: %s): "
                            % (paramType['name'], paramType['type'])))
                elif paramType['type'] == "Uint":
                    paramValue = int(
                        raw_input(
                            "Please enter value for parameter \"%s\" (type: %s): "
                            % (paramType['name'], paramType['type'])))
                else:
                    paramValue = raw_input(
                        "Please enter value for parameter \"%s\" (type: %s): "
                        % (paramType['name'], paramType['type']))

                param = {}
                param['paramTypeId'] = paramType['id']
                param['value'] = paramValue
                params.append(param)
    return params
Beispiel #17
0
def create_stateDescriptor():
    print "-> Creating a new stateDescriptor:\n"
    deviceId = devices.select_configured_device()
    device = devices.get_device(deviceId)
    if device == None:
        return None
    stateType = select_stateType(device['deviceClassId'])
    if stateType == None:
        return None
    valueOperator = guh.select_valueOperator(stateType['name'])

    stateDescriptor = {}

    print "\nThe StateType looks like this:\n", guh.print_json_format(
        stateType)
    print "Please enter the value for state \"%s\" (type: %s): " % (
        stateType['name'], stateType['type'])
    # make bool selectable to make shore they are "true" or "false"
    if any("possibleValues" in item for item in stateType):
        # has to be a string (for sorting list)
        possibleValues = []
        for value in stateType['possibleValues']:
            possibleValues.append(str(value))
        selection = guh.get_selection(
            "Please select one of following possible values:", possibleValues)
        if selection == None:
            return None
        stateValue = stateType['possibleValues'][selection]
    else:
        # make bool selectable to make shore they are "true" or "false"
        if stateType['type'] == "Bool":
            boolTypes = ["true", "false"]
            selectionString = "Please enter the value for state \"%s\" (type: %s): " % (
                stateType['name'], stateType['type'])
            selection = guh.get_selection(selectionString, boolTypes)
            if selection == None:
                return None
            stateValue = boolTypes[selection]
        elif stateType['type'] == "Int":
            stateValue = int(
                raw_input("%s %s " %
                          (stateType['name'],
                           guh.get_valueOperator_string(valueOperator))))
        elif stateType['type'] == "Double":
            stateValue = float(
                raw_input("%s %s " %
                          (stateType['name'],
                           guh.get_valueOperator_string(valueOperator))))
        elif stateType['type'] == "Uint":
            stateValue = int(
                raw_input("%s %s " %
                          (stateType['name'],
                           guh.get_valueOperator_string(valueOperator))))
        else:
            stateValue = raw_input(
                "%s %s " % (stateType['name'],
                            guh.get_valueOperator_string(valueOperator)))

    stateDescriptor['deviceId'] = deviceId
    stateDescriptor['stateTypeId'] = stateType['id']
    stateDescriptor['value'] = stateValue
    stateDescriptor['operator'] = valueOperator
    print guh.print_json_format(stateDescriptor)
    return stateDescriptor
Beispiel #18
0
def show_tcpServer_configuration():
    response = guh.send_command("Configuration.GetConfigurations")
    print "TCP server configuration\n"
    guh.print_json_format(response['params']['tcpServerConfigurations'])
Beispiel #19
0
def configure_tcpServer():
    configurations = guh.send_command("Configuration.GetConfigurations")
    tcpConfigs = configurations['params']['tcpServerConfigurations']
    configList = []
    for i in range(len(tcpConfigs)):
        configList.append("%s:%s   SSL:%s   Auth:%s" %
                          (tcpConfigs[i]['address'], tcpConfigs[i]['port'],
                           tcpConfigs[i]['sslEnabled'],
                           tcpConfigs[i]['authenticationEnabled']))
    configList.append("New entry")
    selection = guh.get_selection("Please select a configuration", configList)
    if selection == None:
        return None

    params = {}
    configuration = {}
    if selection == len(configList) - 1:
        # new config
        configuration['id'] = str(uuid.uuid4())
        configuration['address'] = raw_input(
            "\nEnter the \"address\" of the TCP server: ")
        configuration['port'] = raw_input(
            "\nEnter the \"port\" of the TCP server: ")
        configuration['sslEnabled'] = raw_input(
            "\nEnter whether SSL should be enabled or not: ")
        configuration['authenticationEnabled'] = raw_input(
            "\nEnter whether authentication should be enabled or not: ")
    else:

        selectedConfig = tcpConfigs[selection]

        editList = []
        editList.append("Modify")
        editList.append("Delete")
        editSelection = guh.get_selection(
            "Do you want to edit or delete the server interface?", editList)
        if editSelection == None:
            return None

        if editSelection == 1:  #delete
            params = {}
            params['id'] = selectedConfig['id']
            guh.send_command("Configuration.DeleteTcpServerConfiguration",
                             params)
            return None

        configuration['id'] = selectedConfig['id']
        configuration['address'] = raw_input(
            "\nEnter the \"address\" of the TCP server (current \"%s\"): " %
            (selectedConfig['address']))
        configuration['port'] = raw_input(
            "\nEnter the \"port\" of the TCP server (current %s): " %
            (selectedConfig['port']))
        configuration['sslEnabled'] = raw_input(
            "\nEnter whether SSL should be enabled or not (current \"%s\"): " %
            (selectedConfig['sslEnabled']))
        configuration['authenticationEnabled'] = raw_input(
            "\nEnter whether authentication should be enabled or not (current %s): "
            % (selectedConfig['authenticationEnabled']))
    params['configuration'] = configuration
    response = guh.send_command("Configuration.SetTcpServerConfiguration",
                                params)
    guh.print_json_format(response['params'])
Beispiel #20
0
def print_deviceClass():
    deviceClassId = select_deviceClass()
    if deviceClassId == None:
        return None
    guh.print_json_format(get_deviceClass(deviceClassId))
Beispiel #21
0
def set_serverName():
    params = {}
    params['serverName'] = raw_input("Please enter the server name:")
    response = guh.send_command("Configuration.SetServerName", params)
    guh.print_json_format(response['params'])
Beispiel #22
0
def list_plugin_info():
    pluginId = select_plugin()
    if not pluginId:
        return None
    guh.print_json_format(get_plugin(pluginId))
Beispiel #23
0
def list_network_devices():
    params = {}
    response = guh.send_command("NetworkManager.GetNetworkDevices", params)
    guh.print_json_format(response['params'])
Beispiel #24
0
def edit_rule():
    ruleDescription = select_rule()
    if ruleDescription == None:
        print "\n    No rules found"
        return None

    boolTypes = ["yes", "no"]

    params = {}
    params['ruleId'] = ruleDescription['id']
    originalRule = guh.send_command("Rules.GetRuleDetails",
                                    params)['params']['rule']
    print "\n========================================================"
    print "Original rule JSON:\n"
    print guh.print_json_format(originalRule)

    if selector.getYesNoSelection(
            "Do you want to chane the name (current = \"%s\"): " %
        (originalRule['name'])):
        print "\n========================================================"
        params['name'] = raw_input(
            "Please enter the new name of the rule (current = \"%s\"): " %
            (originalRule['name']))
    else:
        params['name'] = originalRule['name']

    if len(originalRule['eventDescriptors']) > 0:
        print "\nCurrent \"Events\":\n"
        events.print_eventDescriptors(originalRule['eventDescriptors'])
        print "\n========================================================\n"

        input = raw_input("Do you want change this \"Events\" (y/N): ")
        if input == "y":
            eventDescriptors = events.create_eventDescriptors()
            print guh.print_json_format(eventDescriptors)
            params['eventDescriptors'] = eventDescriptors
        else:
            params['eventDescriptors'] = originalRule['eventDescriptors']

        if originalRule['stateEvaluator']:
            print "\nStates:\n",
            states.print_stateEvaluator(originalRule['stateEvaluator'])

        if selector.getYesNoSelection(
                "Do you want to add conditions (\"States\") for the events?"):
            print "\n========================================================"
            raw_input("-> Create a state descriptor!  ")
            stateEvaluator = states.create_stateEvaluator()
            params['stateEvaluator'] = stateEvaluator

        print "\ncurrent \"Actions\":\n"
        ruleactions.print_ruleActionList(originalRule['actions'])
        print "\n========================================================\n"
        input = raw_input("Do you want change this \"Actions\" (y/N): ")
        if input == "y":
            params['actions'] = ruleactions.create_rule_actions()
        else:
            params['actions'] = originalRule['actions']
    else:
        if selector.getYesNoSelection(
                "Do you want to define \"States\" for this rule?"):
            print "\n========================================================"
            raw_input("-> Press \"enter\" to create a state descriptor!  ")
            params['stateEvaluator'] = states.create_stateEvaluator()

        # there will always be at least one action
        print "\n========================================================\n"
        print "Current \"Actions\":\n"
        ruleactions.print_ruleActionList(originalRule['actions'])

        print "\n========================================================\n"
        input = raw_input("Do you want change this \"Actions\" (y/N): ")
        if input == "y":
            params['actions'] = ruleactions.create_rule_actions()
        else:
            params['actions'] = originalRule['actions']

        if len(originalRule['exitActions']) > 0:
            print "\n========================================================\n"
            print "Current \"Actions\":\n"
            ruleactions.print_ruleActionList(originalRule['exitActions'])
            input = raw_input("Do you want change this \"Events\" (y/N): ")
            if input == "y":
                params['exitActions'] = ruleactions.create_rule_actions()
            else:
                params['exitActions'] = originalRule['exitActions']

        else:
            if selector.getYesNoSelection(
                    "Do you want to add (\"ExitActions\") for this rule?"):
                params['exitActions'] = ruleactions.create_rule_actions()

    params['enabled'] = selector.getBoolSelection(
        "-> Should the rule initially be enabled?")
    params['executable'] = selector.getBoolSelection(
        "-> Should the rule be executable?")

    print "\n========================================================\n"
    print "Edit rule with params:\n", guh.print_json_format(params)
    response = guh.send_command("Rules.EditRule", params)
    guh.print_rule_error_code(response['params']['ruleError'])
Beispiel #25
0
def list_timezones():
    params = {}
    response = guh.send_command("Configuration.GetTimeZones", params)
    guh.print_json_format(response['params'])
Beispiel #26
0
def create_logfilter():
    params = {}
    boolTypes = ["yes","no"]
    
    # Devices
    selection = guh.get_selection("Do you want to filter for \"Devices\"? ", boolTypes)
    if boolTypes[selection] == "yes":
        deviceIds = []
        deviceId = devices.select_configured_device()
        deviceIds.append(deviceId)
        
        
        finished = False
        while not finished:
            selection = guh.get_selection("Do you want to add an other \"Device\"? ", boolTypes)
            if boolTypes[selection] == "no":
                finished = True
                break
            deviceId = devices.select_configured_device()
            if not deviceId:
                params['deviceIds'] = deviceIds
                return params
            deviceIds.append(deviceId)
            
      
        params['deviceIds'] = deviceIds
    
    # LoggingSources
    selection = guh.get_selection("Do you want to filter for \"LoggingSource\"? ", boolTypes)
    if boolTypes[selection] == "yes":
        sources = []
        finished = False
        loggingSources = ["LoggingSourceSystem", "LoggingSourceEvents", "LoggingSourceActions", "LoggingSourceStates", "LoggingSourceRules"]
        selection = guh.get_selection("Please select a \"LoggingSource\": ", loggingSources)
        if selection:
            sources.append(loggingSources[selection])
        else:
            finished = True

        while not finished:
            selection = guh.get_selection("Do you want to add an other \"LoggingSource\"? ", boolTypes)
            if boolTypes[selection] == "no":
                finished = True
                break
            
            selection = get_selection("Please select a \"LoggingSource\": ", loggingSources)
            if selection:
                sources.append(loggingSources[selection])
            else:
                finished = True
                break
        params['loggingSources'] = sources
    
    # LoggingLevel
    selection = guh.get_selection("Do you want to filter for \"LoggingLevel\"? ", boolTypes)
    if boolTypes[selection] == "yes":
        levels = []
        loggingLevels = ["LoggingLevelInfo", "LoggingLevelAlert"]
        selection = guh.get_selection("Please select a \"LoggingLevel\": ", loggingLevels)
        if selection:
            levels.append(loggingLevels[selection])

        params['loggingLevels'] = levels
    
    # LoggingEventType
    selection = guh.get_selection("Do you want to filter for \"LoggingEventType\"? ", boolTypes)
    if boolTypes[selection] == "yes":
        types = []
        loggingEventTypes = ["LoggingEventTypeTrigger", "LoggingEventTypeActiveChange", "LoggingEventTypeEnabledChange", "LoggingEventTypeActionsExecuted", "LoggingEventTypeExitActionsExecuted"]
        selection = guh.get_selection("Please select a \"LoggingEventType\": ", loggingEventTypes)
        if selection:
            types.append(loggingEventTypes[selection])

        params['eventTypes'] = types
    
    # Value
    selection = guh.get_selection("Do you want to filter for certain log \"Values\"? ", boolTypes)
    if boolTypes[selection] == "yes":
        values = []
        finished = False
        value = raw_input("Please enter value which should be filtered out: ")
        values.append(value)
        
        while not finished:
            selection = guh.get_selection("Do you want to add an other \"Value\"? ", boolTypes)
            if boolTypes[selection] == "no":
                finished = True
                break
            value = raw_input("Please enter value which should be filtered out: ")
            values.append(value)
        
        params['values'] = values
    
    # Times
    selection = guh.get_selection("Do you want to add a \"TimeFilter\"? ", boolTypes)
    if boolTypes[selection] == "yes":
        timeFilters = []  
        finished = False
        
        timeFilters.append(create_time_filter())
        while not finished:
            selection = guh.get_selection("Do you want to add an other \"TimeFilter\"? ", boolTypes)
            if boolTypes[selection] == "no":
                finished = True
                break

            timeFilters.append(create_time_filter())
            
        params['timeFilters'] = timeFilters
        
    guh.print_json_format(params)
    guh.debug_stop()
    return params
Beispiel #27
0
def print_cloud_status():
    params = {}
    response = guh.send_command("Cloud.GetConnectionStatus", params)
    guh.print_json_format(response['params'])
Beispiel #28
0
def show_webSocketServer_configuration():
    response = guh.send_command("Configuration.GetConfigurations")
    print "Web socket server configuration\n"
    guh.print_json_format(response['params']['webSocketServerConfigurations'])