def print_config(): print("graph_title AVM Fritz!Box SmartHome temperature") print("graph_vlabel degrees Celsius") print("graph_category sensors") print("graph_scale no") server = os.environ['fritzbox_ip'] user = os.environ['fritzbox_user'] password = os.environ['fritzbox_password'] session_id = fh.get_session_id() data = fh.get_page_content(session_id, PAGE) root = etree.fromstring(data) for d in root: id = d.xpath("@id")[0] identifier = d.xpath("@identifier")[0] name = d.xpath("name/text()")[0] name = unidecode(unicode(name)) pname = d.xpath("@productname")[0] print("t{}.label {}".format(id, name)) print("t{}.type GAUGE".format(id)) print("t{}.graph LINE".format(id)) print("t{}.info Temperature [{} - {}]".format(id, pname, identifier)) if os.environ.get('host_name'): print("host_name " + os.environ['host_name'])
def get_connected_wifi_devices(): """gets the numbrer of currently connected wifi devices""" session_id = fh.get_session_id() data = fh.get_page_content(session_id, PAGE) m = re.search(pattern, data) if m: connected_devices = int(m.group(1)) print('wifi.value %d' % connected_devices)
def get_cpu_temperature(): """get the current cpu temperature""" session_id = fh.get_session_id() data = fh.get_page_content(session_id, PAGE) m = re.search(pattern, data) if m: print('temp.value %d' % (int(m.group(1))))
def get_memory_usage(): """get the current memory usage""" session_id = fh.get_session_id() data = fh.get_page_content(session_id, PAGE) matches = re.finditer(pattern, data) if matches: data = zip(USAGE, [m.group(1) for m in matches]) for d in data: print('%s.value %s' % (d[0], d[1]))
def get_power_consumption(): """get the current power consumption usage""" session_id = fh.get_session_id() data = fh.get_page_content(session_id, PAGE) matches = re.finditer(pattern, data) if matches: data = zip(DEVICES, [m.group(4) for m in matches]) for d in data: print('%s.value %s' % (d[0], d[1]))
def get_smart_home_temperature(debug=False): """get the current cpu temperature""" session_id = fh.get_session_id() data = fh.get_page_content(session_id, PAGE) root = etree.fromstring(data) if debug: print(etree.tostring(root, pretty_print=True)) for d in root: id = d.xpath("@id")[0] present = int(d.xpath("present/text()")[0]) if present: temp = float(d.xpath("temperature/celsius/text()")[0]) / 10 print("t{}.value {}".format(id, temp))
def get_uptime(): """get the current uptime""" session_id = fh.get_session_id() data = fh.get_page_content(session_id, PAGE) matches = re.finditer(pattern, data) if matches: hours = 0.0 for m in matches: if m.group(2) == dayLoc[locale]: hours += 24 * int(m.group(1)) if m.group(2) == hourLoc[locale]: hours += int(m.group(1)) if m.group(2) == minutesLoc[locale]: hours += int(m.group(1)) / 60.0 uptime = hours / 24 print "uptime.value %.2f" % uptime