Check the record in known_hosts file, either by its value or by fingerprint
    (it's enough to set up either key or fingerprint, you don't need to set up
    both).

    If provided key or fingerprint doesn't match with stored value, return
    "update", if no value is found for a given host, return "add", otherwise
    return "exists".

    If neither key, nor fingerprint is defined, then additional validation is
    not performed.

    CLI Example:

    .. code-block:: bash

        salt '*' ssh.check_known_host <user> <hostname> key='AAAA...FAaQ=='

def check_known_host(user=None, hostname=None, key=None, fingerprint=None,
                     config=None, port=None, fingerprint_hash_type=None):
    '''
    Check the record in known_hosts file, either by its value or by fingerprint
    (it's enough to set up either key or fingerprint, you don't need to set up
    both).

    If provided key or fingerprint doesn't match with stored value, return
    "update", if no value is found for a given host, return "add", otherwise
    return "exists".

    If neither key, nor fingerprint is defined, then additional validation is
    not performed.

    CLI Example:

    .. code-block:: bash

        salt '*' ssh.check_known_host <user> <hostname> key='AAAA...FAaQ=='
    '''
    if not hostname:
        return {'status': 'error',
                'error': 'hostname argument required'}
    if not user:
        config = config or '/etc/ssh/ssh_known_hosts'
    else:
        config = config or '.ssh/known_hosts'

    known_host_entries = get_known_host_entries(user,
                                hostname,
                                config=config,
                                port=port,
                                fingerprint_hash_type=fingerprint_hash_type)
    known_keys = [h['key'] for h in known_host_entries] if known_host_entries else []
    known_fingerprints = [h['fingerprint'] for h in known_host_entries] if known_host_entries else []

    if not known_host_entries:
        return 'add'
    if key:
        return 'exists' if key in known_keys else 'update'
    elif fingerprint:
        return ('exists' if fingerprint in known_fingerprints
                else 'update')
    else:
        return 'exists'