aboutsummaryrefslogtreecommitdiffstats
path: root/sos/plugins/networking.py
diff options
context:
space:
mode:
Diffstat (limited to 'sos/plugins/networking.py')
-rw-r--r--sos/plugins/networking.py75
1 files changed, 40 insertions, 35 deletions
diff --git a/sos/plugins/networking.py b/sos/plugins/networking.py
index 4bf67526..c083b8bd 100644
--- a/sos/plugins/networking.py
+++ b/sos/plugins/networking.py
@@ -1,37 +1,35 @@
-### This program is free software; you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 2 of the License, or
-## (at your option) any later version.
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
-## This program is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-## GNU General Public License for more details.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
-## You should have received a copy of the GNU General Public License
-## along with this program; if not, write to the Free Software
-## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-from sos.plugins import Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin
+from sos.plugins import Plugin, RedHatPlugin, UbuntuPlugin
import os
import re
+
class Networking(Plugin):
"""network related information
"""
plugin_name = "networking"
trace_host = "www.example.com"
option_list = [("traceroute", "collects a traceroute to %s" % trace_host,
- "slow", False)]
-
- def setup(self):
- super(Networking, self).setup()
+ "slow", False)]
- def get_bridge_name(self,brctl_file):
+ def get_bridge_name(self, brctl_file):
"""Return a list for which items are bridge name according to the
output of brctl show stored in brctl_file.
"""
- out=[]
+ out = []
try:
brctl_out = open(brctl_file).read()
except:
@@ -45,31 +43,31 @@ class Networking(Plugin):
out.append(br_name)
return out
- def get_eth_interfaces(self,ip_link_out):
+ def get_eth_interfaces(self, ip_link_out):
"""Return a dictionary for which keys are ethernet interface
names taken from the output of "ip -o link".
"""
- out={}
+ out = {}
for line in ip_link_out.splitlines():
- match=re.match('.*link/ether', line)
+ match = re.match('.*link/ether', line)
if match:
- iface=match.string.split(':')[1].lstrip()
- out[iface]=True
+ iface = match.string.split(':')[1].lstrip()
+ out[iface] = True
return out
- def collect_iptable(self,tablename):
+ def collect_iptable(self, tablename):
""" When running the iptables command, it unfortunately auto-loads
the modules before trying to get output. Some people explicitly
don't want this, so check if the modules are loaded before running
the command. If they aren't loaded, there can't possibly be any
relevant rules in that table """
-
if self.check_ext_prog("grep -q %s /proc/modules" % tablename):
cmd = "iptables -t "+tablename+" -nvL"
self.add_cmd_output(cmd)
def setup(self):
+ super(Networking, self).setup()
self.add_copy_specs([
"/proc/net/",
"/etc/nsswitch.conf",
@@ -89,12 +87,11 @@ class Networking(Plugin):
self.add_forbidden_path("/proc/net/rpc/*/channel")
self.add_forbidden_path("/proc/net/rpc/*/flush")
- ip_addr_file=self.get_cmd_output_now("ip -o addr", root_symlink = "ip_addr")
- self.add_cmd_output("route -n", root_symlink = "route")
+ self.add_cmd_output("route -n", root_symlink="route")
self.collect_iptable("filter")
self.collect_iptable("nat")
self.collect_iptable("mangle")
- self.add_cmd_output("netstat -neopa", root_symlink = "netstat")
+ self.add_cmd_output("netstat -neopa", root_symlink="netstat")
self.add_cmd_outputs([
"netstat -s",
"netstat -agn",
@@ -111,7 +108,7 @@ class Networking(Plugin):
"nmcli device status",
"biosdevname -d"
])
- ip_link_result=self.call_ext_prog("ip -o link")
+ ip_link_result = self.call_ext_prog("ip -o link")
if ip_link_result['status'] == 0:
for eth in self.get_eth_interfaces(ip_link_result['output']):
self.add_cmd_outputs([
@@ -124,17 +121,19 @@ class Networking(Plugin):
"ethtool -g "+eth
])
- brctl_file=self.get_cmd_output_now("brctl show")
+ brctl_file = self.get_cmd_output_now("brctl show")
if brctl_file:
for br_name in self.get_bridge_name(brctl_file):
self.add_cmd_output("brctl showstp "+br_name)
-
- nmcli_con_show_result=self.call_ext_prog("nmcli --terse --fields NAME con show")
+
+ nmcli_con_show_result = self.call_ext_prog(
+ "nmcli --terse --fields NAME con show")
if nmcli_con_show_result:
for con in nmcli_con_show_result['output'].splitlines():
self.add_cmd_output("nmcli connection show "+con)
- nmcli_dev_status_result=self.call_ext_prog("nmcli --terse --fields DEVICE dev status")
+ nmcli_dev_status_result = self.call_ext_prog(
+ "nmcli --terse --fields DEVICE dev status")
if nmcli_dev_status_result:
for dev in nmcli_dev_status_result['output'].splitlines():
self.add_cmd_output("nmcli device show "+dev)
@@ -145,17 +144,23 @@ class Networking(Plugin):
return
def postproc(self):
- for root, dirs, files in os.walk("/etc/NetworkManager/system-connections"):
+ for root, dirs, files in os.walk(
+ "/etc/NetworkManager/system-connections"):
for net_conf in files:
- self.do_file_sub("/etc/NetworkManager/system-connections/"+net_conf, r"psk=(.*)",r"psk=***")
+ self.do_file_sub(
+ "/etc/NetworkManager/system-connections/"+net_conf,
+ r"psk=(.*)", r"psk=***")
+
class RedHatNetworking(Networking, RedHatPlugin):
"""network related information for RedHat based distribution
"""
trace_host = "rhn.redhat.com"
+
def setup(self):
super(RedHatNetworking, self).setup()
+
class UbuntuNetworking(Networking, UbuntuPlugin):
"""network related information for Ubuntu based distribution
"""