import logging
import json


def connect_and_get_output(device):
    """
    Helper function which get LLDP data from specified device

    Positional argument:
    - device -- NAPALM driver object

    Returns:
    - json_output -- LLDP device data serialized to JSON
    """
    try:
        device.open()
        output = device.get_lldp_neighbors_detail()
        device.close()
    except Exception as exception:
        logging.warning(exception)
    else:
        json_output = json.dumps(output, indent=5)
        return json_output