import urllib.request, json

def run():
    url = "http://10.240.240.56:8080/api/table.json?&content=sensors&columns=downtimesince%2Cdevice%2Csensor%2Cstatus%2Cmessage&sortby=priority&filter_status=13&tabletitle=AUTO&filter_status=14&id=3831&filter_status=5&filter_status=4&filter_status=10&username=prtgadmin&password=<PASSWORD>!"

    def convertTime(time):
        day = time // (24 * 3600)
        time = time % (24 * 3600)
        hour = time // 3600
        time %= 3600
        minutes = time // 60
        time %= 60
        seconds = time
        if day > 1:
            if hour > 1:
                return(str(day) + " Days, " + str(hour) + " Hours")
            else:
                return(str(day) + " Days, " + str(hour) + " Hour")
        else:
            if hour > 1:
                return(str(day) + " Day, " + str(hour) + " Hours")
            else:
                return(str(day) + " Day, " + str(hour) + " Hour")

    json_data = []

    with urllib.request.urlopen(url) as url:
        data = json.loads(url.read().decode())
        sensor_data = data["sensors"]
        for item in sensor_data:
            if item["downtimesince"] != "":
                downtime = int(item["downtimesince_raw"])
                row = {"sensor": item["sensor"], "downtime": convertTime(downtime)}
                json_data.append(row)

    return json_data


import urllib.request, json

def run():
    url = "http://10.240.240.56:8080/api/table.json?&content=sensors&columns=downtimesince%2Cdevice%2Csensor%2Cstatus%2Cmessage&sortby=priority&filter_status=13&tabletitle=AUTO&filter_status=14&id=3831&filter_status=5&filter_status=4&filter_status=10&username=prtgadmin&password=<PASSWORD>!"

    def convertTime(time):
        day = time // (24 * 3600)
        time = time % (24 * 3600)
        hour = time // 3600
        time %= 3600
        minutes = time // 60
        time %= 60
        seconds = time
        if day > 1:
            if hour > 1:
                return(str(day) + " Days, " + str(hour) + " Hours")
            else:
                return(str(day) + " Days, " + str(hour) + " Hour")
        else:
            if hour > 1:
                return(str(day) + " Day, " + str(hour) + " Hours")
            else:
                return(str(day) + " Day, " + str(hour) + " Hour")

    json_data = []

    with urllib.request.urlopen(url) as url:
        data = json.loads(url.read().decode())
        sensor_data = data["sensors"]
        for item in sensor_data:
            if item["downtimesince"] != "":
                downtime = int(item["downtimesince_raw"])
                row = {"sensor": item["sensor"], "downtime": convertTime(downtime)}
                json_data.append(row)

    return json_data

