예제 #1
0
def delete(isamAppliance,
           server,
           port,
           protocol,
           name,
           check_mode=False,
           force=False):
    """
    Delete a remote syslog forwarding source
    """
    ret_obj = forwarder.get_all(isamAppliance=isamAppliance,
                                check_mode=check_mode,
                                force=force)
    json_to_post = ret_obj['data']

    existing_forwarder, i, existing_forwarder_source, j = _find_forwarder_source(
        ret_obj, server, port, protocol, name)
    if existing_forwarder is not None and existing_forwarder_source is not None:
        if check_mode:
            return isamAppliance.create_return_object(changed=True)
        else:
            del json_to_post[i]['sources'][j]
            return forwarder._update_forwarder_policy(isamAppliance,
                                                      json_to_post)

    return isamAppliance.create_return_object()
예제 #2
0
def set(isamAppliance,
        server,
        port,
        protocol,
        name,
        tag,
        facility,
        severity,
        check_mode=False,
        force=False):
    """
    Set a remote syslog forwarding source
    """
    ret_obj = forwarder.get_all(isamAppliance=isamAppliance,
                                check_mode=check_mode,
                                force=force)

    existing_forwarder, i, existing_forwarder_source, j = _find_forwarder_source(
        ret_obj, server, port, protocol, name)

    json_data = {
        'name': name,
        'tag': tag,
        'facility': facility,
        'severity': severity
    }

    warnings = []
    update_required = False
    if existing_forwarder is None:
        warnings.append("Unable to find forwarder for {} {} {}".format(
            server, port, protocol))
    else:
        if existing_forwarder_source is None:
            json_to_post = ret_obj['data']
            json_to_post[i]['sources'].append(json_data)
            update_required = True
        else:
            sorted_json_data = tools.json_sort(json_data)
            logger.debug("Sorted input: {0}".format(sorted_json_data))
            sorted_ret_obj = tools.json_sort(existing_forwarder_source)
            logger.debug("Sorted existing data: {0}".format(sorted_ret_obj))
            if sorted_ret_obj != sorted_json_data:
                logger.info("Changes detected, update needed.")
                ret_obj['data'][i]['sources'][j] = json_data
                json_to_post = ret_obj['data']
                update_required = True

    if update_required:
        if check_mode:
            return isamAppliance.create_return_object(changed=True,
                                                      warnings=warnings)
        else:
            return forwarder._update_forwarder_policy(isamAppliance,
                                                      json_to_post,
                                                      warnings=warnings)

    return isamAppliance.create_return_object(warnings=warnings)
예제 #3
0
def get(isamAppliance, server, port, protocol, name, check_mode=False, force=False):
    """
    Retrieve the remote syslog forwarding source
    """
    ret_obj = forwarder.get_all(isamAppliance=isamAppliance, check_mode=check_mode, force=force)

    if isinstance(port, basestring):
        port = int(port)

    existing_forwarder, i, existing_forwarder_source, j = _find_forwarder_source(ret_obj, server, port, protocol, name)

    return_obj = isamAppliance.create_return_object()
    return_obj['data'] = existing_forwarder_source

    return return_obj