from datetime import datetime


def get_csv_details(line):
    """Convert predefined csv format to time, user, ip_string, hostname, client"""
    line_list = line.split(",")
    time = datetime.strptime(line_list[0].strip(), '%Y-%m-%d %H:%M:%S') # ex. 2017-05-15 13:56:23
    user = line_list[1].strip()
    ip_string = line_list[2].strip()

    # Try to parse hostname and client which are optional
    try:
        hostname = line_list[3].strip()
    except IndexError:
        hostname = " "
    try:
        client = line_list[4].strip()
    except IndexError:
        client = " "
    return time, ip_string, user, hostname, client