ifconfig ok

This commit is contained in:
Adrien Beudin 2013-10-04 12:23:25 +02:00
parent 164e571a97
commit f10f6dcbb0

View file

@ -38,11 +38,22 @@ except ImportError:
sys.stderr.write('apt-get install python-yaml\n')
sys.exit(1)
import json
import socket
import fcntl
import struct
if not __debug__:
import traceback
s = xmlrpclib.ServerProxy('http://127.0.0.1:61209')
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
def bytes2human(n):
symbols = ('K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
prefix = {}
@ -126,8 +137,13 @@ def monitor_info(memory=False, cpu=False, disk=False, ifconfig=False, uptime=Fal
result = {}
for k, fs in enumerate(json.loads(s.getNetwork())):
interface = fs['interface_name']
del fs['interface_name']
result[interface] = fs
if interface != "lo":
ip = get_ip_address(str(interface))
del fs['interface_name']
result[ip] = fs
else:
del fs['interface_name']
result[interface] = fs
return result
elif disk: