some new plugins (thx to _20h_)

This commit is contained in:
ChChBot admin 2015-02-18 22:44:57 +01:00
parent 63fc042027
commit 0ba2001b62
5 changed files with 346 additions and 0 deletions

21
plugins/bandwidth.py Normal file
View file

@ -0,0 +1,21 @@
from util import hook, http, web
from subprocess import check_output, CalledProcessError
from datetime import datetime
@hook.command("bw", autohelp=False)
def bw(inp):
"""bw - list last bandwidth measurement to the outside."""
try:
o = check_output("/bin/chch-bandwidth")
except CalledProcessError as err:
return "chch-bandwidth: returned %s" % (str(err))
os = o.split(",")
upl = int(os[-1])/1024.0/1024.0
dl = int(os[-2])/1024.0/1024.0
ts = os[0]
tsd = datetime.strptime(ts, "%Y%m%d%H%M%S")
return "%s: upl = %f Mbit/s; dl = %f Mbit/s;" % (tsd, upl, dl)