123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- # -*- coding: utf-8 -*-
- from __future__ import print_function
- import willie
- def setup(bot):
- pass
- @willie.module.commands('info')
- def ffpb_peerinfo(bot, trigger):
- """Informationen zu einem Knoten abrufen"""
- # identify node or bail out
- target_name = trigger.group(2)
- node = ffpb_findnode_from_botparam(bot, target_name)
- if node is None: return
- # read node information
- info_mac = node["network"]["mac"]
- info_name = node["hostname"]
- info_hw = ""
- if "hardware" in node:
- if "model" in node["hardware"]:
- model = node["hardware"]["model"]
- info_hw = " model='" + model + "'"
- info_fw = ""
- info_update = ""
- if "software" in node:
- if "firmware" in node["software"]:
- fwinfo = str(node["software"]["firmware"]["release"]) if "release" in node["software"]["firmware"] else "unknown"
- info_fw = " firmware=" + fwinfo
- if "autoupdater" in node["software"]:
- autoupdater = node["software"]["autoupdater"]["branch"] if node["software"]["autoupdater"]["enabled"] else "off"
- info_update = " (autoupdater="+autoupdater+")"
- info_uptime = ""
- u = -1
- if "statistics" in node and "uptime" in node["statistics"]:
- u = int(float(node["statistics"]["uptime"]))
- elif 'uptime' in node:
- u = int(float(node['uptime']))
- if u > 0:
- d, r1 = divmod(u, 86400)
- h, r2 = divmod(r1, 3600)
- m, s = divmod(r2, 60)
- if d > 0:
- info_uptime = ' up {0}d {1}h'.format(d,h)
- elif h > 0:
- info_uptime = ' up {0}h {1}m'.format(h,m)
- else:
- info_uptime = ' up {0}m'.format(m)
- bot.say('[{1}]{2}{3}{4}{5}'.format(info_mac, info_name, info_hw, info_fw, info_update, info_uptime))
- @willie.module.commands('uptime')
- def ffpb_peeruptime(bot, trigger):
- """Zeige Uptime eines Knotens"""
- # identify node or bail out
- target_name = trigger.g roup(2)
- node = ffpb_findnode_from_botparam(bot, target_name)
- if node is None: return
- # get name and raw uptime from node
- info_name = node["hostname"]
- info_uptime = ''
- u_raw = None
- if 'statistics' in node and 'uptime' in node['statistics']:
- u_raw = node['statistics']['uptime']
- elif 'uptime' in node:
- u_raw = node['uptime']
- # pretty print uptime
- if not u_raw is None:
- u = int(float(u_raw))
- d, r1 = divmod(u, 86400)
- h, r2 = divmod(r1, 3600)
- m, s = divmod(r2, 60)
- if d > 0:
- info_uptime += '{0}d '.format(d)
- if h > 0:
- info_uptime += '{0}h '.format(h)
- info_uptime += '{0}m'.format(m)
- info_uptime += ' # raw: \'{0}\''.format(u_raw)
- else:
- info_uptime += '?'
- # reply to user
- bot.say('uptime(\'{0}\') = {1}'.format(info_name, info_uptime))
- @willie.module.commands('link')
- def ffpb_peerlink(bot, trigger):
- """Zeige MAC und Link zur Statusseite eines Knotens"""
- # identify node or bail out
- target_name = trigger.group(2)
- node = ffpb_findnode_from_botparam(bot, target_name)
- if node is None: return
- # get node's mac
- info_mac = node["network"]["mac"]
- info_name = node["hostname"]
- # get node's v6 address in the mesh (derived from MAC address)
- info_v6 = mac2ipv6(info_mac, 'fdca:ffee:ff12:132:')
- # reply to user
- bot.say('[{1}] mac {0} -> http://[{2}]/'.format(info_mac, info_name, info_v6))
|