Fibre Channel (SAN)

Reply
N/A
Posts: 1
Registered: ‎10-25-2011

Scripting 'portstatsshow' from CLI (FoS 7.0.0c)

Hello group,

I am trying to write a script that will go out and check the er_bad_os log from the portstatsshow command on my DCX 8510 SAN switches.  Does anyone have any ideas on how to write a "for" loop to increment the blade and port number in the command "portstatsshow X/Y | grep er_bad_os" and have that out put printed to the screen? (where X=blade and Y=port), from the CLI.

Thanks,

Victor Simon

Regular Contributor
Posts: 226
Registered: ‎01-08-2011

Re: Scripting 'portstatsshow' from CLI (FoS 7.0.0c)

Howdy,

if you connect to the switch from a server (one that for example has ruby installed) you could create a "for" loop in ruby (perhaps somehow based on the output of switchshow?)

Scripting in the CLI of the Brocade might prove difficult, but if you connect from a server/machine you can use an account with read_only priviliges.

I've played a bit with expect/perl as well, personally I liked ruby more because of speed and ease.

Contributor
Posts: 25
Registered: ‎01-20-2010

Re: Scripting 'portstatsshow' from CLI (FoS 7.0.0c)

Hi,

i would second the idea using some script language, python here, and the expect library. I use switchshow to get a list of all ports on the portblades and run a portstats(64)show on them.

Some code pointers, cut from a larger script. This is done for v6.4.x so might need some changes. Instead of putting it into a database table you could use xml, csv or whatever you prefer in your use case and sort/filter before returning it.:

        self.child.sendline ('switchshow')
        self.child.expect(self.term)
        self.data=self.child.before.decode("iso-8859-1").decode('unicode-escape')
        self.temp=re.split('\n',self.data)
        for self.i in self.temp:
            if re.search(r"^ *(\d+) +(\d+) +(\d+) +({6}) +({2}) +({2}) +(+) +(\w+) +(*) *(*) *(.*)",self.i):
                self.temp2=re.search(r"^ *(\d+) +(\d+) +(\d+) +({6}) +({2}) +({2}) +(+) +(\w+) +(*) *(*) *(.*)",self.i)
                self.cursor.execute("""REPLACE INTO port(switchdomain, `index`, timestamp, slot, number, address, media, speed, state, proto, type, rwwn, comment, name)
                    VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')
                ;""" % (self.switchdomain, self.temp2.group(1), date.today(), self.temp2.group(2), self.temp2.group(3), self.temp2.group(4), self.temp2.group(5), self.temp2.group(6), self.temp2.group(7), self.temp2.group(8), self.temp2.group(9), self.temp2.group(10).replace(":","").upper(), self.temp2.group(11), ''))
                # Getting details per port
                self.child.sendline("portstats64show %s/%s" % (self.temp2.group(2),self.temp2.group(3)))
                self.child.expect(self.term)
                self.portstats64show=self.child.before.decode("iso-8859-1").decode('unicode-escape')
                self.child.sendline("portshow %s/%s" % (self.temp2.group(2), self.temp2.group(3)))
                self.child.expect(self.term)
                self.portshow=self.child.before.decode("iso-8859-1").decode('unicode-escape')
                self.child.sendline("portcfgshow %s/%s" % (self.temp2.group(2),self.temp2.group(3)))
                self.child.expect(self.term)
                self.portcfgshow=self.child.before.decode("iso-8859-1").decode('unicode-escape')
                self.cursor.execute("""REPLACE INTO port_data(switchdomain, `index`, timestamp, slot, number, portstats64show, portshow, portcfgshow) VALUES('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');""" % (self.switchdomain, self.temp2.group(1), date.today(), self.temp2.group(2), self.temp2.group(3), self.portstats64show, self.portshow, self.portcfgshow))
Valued Contributor
Posts: 931
Registered: ‎12-30-2009

Re: Scripting 'portstatsshow' from CLI (FoS 7.0.0c)

If its a script you want, better log in as root because you have more standard unix commands at your disposal.

Create a script, save it and call it thru ssh.

But I prefer using SNMP to get those statistics.

OID .1.3.6.1.3.94.4.5.1.45 from FCMGMT mib or

.1.3.6.1.4.1.1588.2.1.1.1.6.2.1.27 from SW mib should give you those figures.

Yoy can get them from a firmware download or @ http://community.brocade.com/docs/DOC-1733 (pre FOS7)

Join the Community

Get quick and easy access to valuable resource designed to help you manage your Brocade Network.