add network info to the worlddump

This adds potentially helpful networking info to the world dump.

It also refactors some of the output mechanisms into reusable
functions for cleanliness in the code.

Change-Id: I39f95bd487c152925f8fadd1799149db35cffd52
This commit is contained in:
Sean Dague
2015-05-11 14:53:39 -04:00
parent 75bae7076a
commit 60a140571e

View File

@@ -41,12 +41,24 @@ def warn(msg):
print "WARN: %s" % msg print "WARN: %s" % msg
def _dump_cmd(cmd):
print cmd
print "-" * len(cmd)
print
print os.popen(cmd).read()
def _header(name):
print
print name
print "=" * len(name)
print
def disk_space(): def disk_space():
# the df output # the df output
print """ _header("File System Summary")
File System Summary
===================
"""
dfraw = os.popen("df -Ph").read() dfraw = os.popen("df -Ph").read()
df = [s.split() for s in dfraw.splitlines()] df = [s.split() for s in dfraw.splitlines()]
for fs in df: for fs in df:
@@ -63,22 +75,26 @@ File System Summary
def iptables_dump(): def iptables_dump():
tables = ['filter', 'nat', 'mangle'] tables = ['filter', 'nat', 'mangle']
print """ _header("IP Tables Dump")
IP Tables Dump
===============
"""
for table in tables: for table in tables:
print os.popen("sudo iptables --line-numbers -L -nv -t %s" _dump_cmd("sudo iptables --line-numbers -L -nv -t %s" % table)
% table).read()
def network_dump():
_header("Network Dump")
_dump_cmd("brctl show")
_dump_cmd("arp -n")
_dump_cmd("ip addr")
_dump_cmd("ip link")
_dump_cmd("ip route")
def process_list(): def process_list():
print """ _header("Process Listing")
Process Listing _dump_cmd("ps axo "
=============== "user,ppid,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,args")
"""
psraw = os.popen("ps axo user,ppid,pid,pcpu,pmem,vsz,rss,tty,stat,start,time,args").read()
print psraw
def main(): def main():
@@ -90,6 +106,7 @@ def main():
os.dup2(f.fileno(), sys.stdout.fileno()) os.dup2(f.fileno(), sys.stdout.fileno())
disk_space() disk_space()
process_list() process_list()
network_dump()
iptables_dump() iptables_dump()