KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17
System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64
User : nobody ( 99)
PHP Version : 5.2.17
Disable Function : NONE
Directory :  /proc/21573/root/usr/lib/python2.4/site-packages/sos/plugins/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/21573/root/usr/lib/python2.4/site-packages/sos/plugins/networking.py
### 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.

## 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.

import sos.plugintools
import os,re,commands

class networking(sos.plugintools.PluginBase):
    """network related information
    """
    optionList = [("traceroute", "collects a traceroute to rhn.redhat.com", "slow", False)]

    def get_bridge_name(self,brctlFile):
        """Return a dictionary for which key are bridge name according to the
        output of brctl show stored in brctlFile.
        """
        out=[]
        fp = open(brctlFile, 'r')
        for line in fp.readlines():
            if line.startswith("bridge name") or line.isspace() or line[:1].isspace():
                continue
            brName, brRest = line.split(None, 1)
            out.append(brName)
        fp.close()
        return out

    def get_eth_interfaces(self,ip_link_out):
        """Return a dictionary for which key are interface name according to the
        output of ipaddr -o link stored in ipaddrFile.
        """
        out={}
        for line in ip_link_out.splitlines():
            match=re.match(r'.*link/ether.*', line)
            if match:
                iface=match.string.split(':')[1].lstrip()
                out[iface]=True
        return out

    def collectIPTable(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 """

        cmd = "/sbin/iptables -t "+tablename+" -nvL"

        (status, output) = commands.getstatusoutput("/sbin/lsmod | grep -q "+tablename)
        if status == 0:
            self.collectExtOutput(cmd)
        else:
            self.writeTextToCommand(cmd,"IPTables module "+tablename+" not loaded\n")

    def setup(self):
        self.addCopySpec("/proc/net")
        self.addCopySpec("/etc/nsswitch.conf")
        self.addCopySpec("/etc/yp.conf")
        self.addCopySpec("/etc/inetd.conf")
        self.addCopySpec("/etc/xinetd.conf")
        self.addCopySpec("/etc/xinetd.d")
        self.addCopySpec("/etc/host*")
        self.addCopySpec("/etc/resolv.conf")
        self.collectExtOutput("/sbin/ifconfig -a", symlink = "ifconfig")
        ipaddrFile=self.collectOutputNow("/sbin/ip -o addr", symlink = "ip_addr")
        self.collectExtOutput("/sbin/route -n", symlink = "route")
        self.collectExtOutput("/sbin/ipchains -nvL")
        self.collectIPTable("filter")
        self.collectIPTable("nat")
        self.collectIPTable("mangle")
        self.collectExtOutput("/bin/netstat -s")
        self.collectExtOutput("/bin/netstat -agn")
        self.collectExtOutput("/bin/netstat -neopa", symlink = "netstat")
        self.collectExtOutput("/sbin/ip route show table all")
        self.collectExtOutput("/sbin/ip link")
        self.collectExtOutput("/sbin/ip address")
        self.collectExtOutput("/sbin/ifenslave -a")
        self.collectExtOutput("/sbin/ip mroute show")
        self.collectExtOutput("/sbin/ip maddr show")
        self.collectExtOutput("/sbin/ip neigh show")
        ip_link_out=self.callExtProgWithOutput("ip -o link")[1]
        if ip_link_out:
            for eth in self.get_eth_interfaces(ip_link_out):
                self.collectExtOutput("/sbin/ethtool "+eth)
                self.collectExtOutput("/sbin/ethtool -i "+eth)
                self.collectExtOutput("/sbin/ethtool -k "+eth)
                self.collectExtOutput("/sbin/ethtool -a "+eth)
                self.collectExtOutput("/sbin/ethtool -c "+eth)
                self.collectExtOutput("/sbin/ethtool -g "+eth)
                self.collectExtOutput("/sbin/ethtool -S "+eth)

        if self.isOptionEnabled("traceroute"):
            self.collectExtOutput("/bin/traceroute -n rhn.redhat.com")
        brctlFile=self.collectOutputNow("/usr/sbin/brctl show")
        if brctlFile:
            for brName in self.get_bridge_name(brctlFile):
                self.collectExtOutput("/usr/sbin/brctl showstp "+brName)            
        return


Anon7 - 2021