def validate_rh_firewall_exception():
    '''
    Validating that a firewall rule with the agents port as an exception exists
    :return: True if exception was found, False otherwise
    '''
    iptables = subprocess.Popen(["sudo", "iptables-save"], stdout=subprocess.PIPE)
    grep = subprocess.Popen(["sudo", "grep", agent_port], stdin=iptables.stdout, stdout=subprocess.PIPE)
    o, e = grep.communicate()
    if e is not None or o is None:
        # either an error running the command or no rules exist
        return False
    else:
        content = o.decode(encoding='UTF-8')
        rules = content.split('\n')
        for rule in rules:
            # reviewing all rules until a match is found
            is_exception = True
            for token in rh_firewalld_agent_exception_tokens:
                # comparing expected rule tokens with existing rule key words
                if token not in rule:
                    # not an exception- exit loop and move to next rule
                    is_exception = False
                    break
            if is_exception:
                return True
        return False

    Validating that a firewall rule with the agents port as an exception exists
    :return: True if exception was found, False otherwise
    
DataConnectors/CEF/cef_troubleshoot.py