Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traceback in format_ios_ver #11

Open
J4bber opened this issue Mar 9, 2016 · 18 comments
Open

Traceback in format_ios_ver #11

J4bber opened this issue Mar 9, 2016 · 18 comments

Comments

@J4bber
Copy link

J4bber commented Mar 9, 2016

This is seen when used against a Cisco Nexus 7000

$ mnet.py graph -r 10.108.18.4 -f test.png -d 2 -c mnet.conf
MNet Suite v0.8
Written by Michael Laforest mjlaforest@gmail.com

 Config file: mnet.conf
   Root node: 10.108.18.4
 Output file: test.png
 Crawl depth: 2

Diagram title: MNet Network Diagram
Out Catalog file: None

  +l3n7k_76ad_ru34 (10.108.18.4)
  >l3n7k_76ad_ru34 (10.108.18.4)

Traceback (most recent call last):
File "/usr/local/bin/mnet.py", line 198, in
main(sys.argv[1:])
File "/usr/local/bin/mnet.py", line 67, in main
graph(argv[1:])
File "/usr/local/bin/mnet.py", line 129, in graph
graph.crawl(opt_root_ip)
File "/usr/local/lib/python2.7/dist-packages/mnetsuite/graph.py", line 92, in crawl
n.query_node()
File "/usr/local/lib/python2.7/dist-packages/mnetsuite/node.py", line 485, in query_node
self._get_chassis_info()
File "/usr/local/lib/python2.7/dist-packages/mnetsuite/node.py", line 809, in _get_chassis_info
self.ios = self._format_ios_ver(self.ios)
File "/usr/local/lib/python2.7/dist-packages/mnetsuite/node.py", line 831, in _format_ios_ver
img_s = re.search('(Version:? |CCM:)([^ ,$]*)', img)
File "/usr/lib/python2.7/re.py", line 142, in search
return _compile(pattern, flags).search(string)
TypeError: expected string or buffer

@MJL85
Copy link
Owner

MJL85 commented Mar 11, 2016

Good morning,

Can you try editing node.py? I will try to update to a new version with this fix soon, but this should work for now.

def _format_ios_ver(self, img):

                            img_s = re.search('(Version:? |CCM:)([^ ,$]*)', img)

                            if (img_s):

                                            if (img_s.group(1) == 'CCM:'):

                                                            return 'CCM %s' % img_s.group(2)

                                            return img_s.group(2)



                            return img

to

def _format_ios_ver(self, img):

                            if not img:

                                            return img



                            img_s = re.search('(Version:? |CCM:)([^ ,$]*)', img)

                            if (img_s):

                                            if (img_s.group(1) == 'CCM:'):

                                                            return 'CCM %s' % img_s.group(2)

                                            return img_s.group(2)



                            return img

Give that a try and let me know. Thanks.

Michael Laforest

From: J4bber [mailto:notifications@github.com]
Sent: Wednesday, March 09, 2016 4:19 PM
To: MJL85/mnet
Subject: [mnet] Traceback in format_ios_ver (#11)

This is seen when used against a Cisco Nexus 7000

$ mnet.py graph -r 10.108.18.4 -f test.png -d 2 -c mnet.conf

MNet Suite v0.8
Written by Michael Laforest mjlaforest@gmail.com

Config file: mnet.conf
Root node: 10.108.18.4
Output file: test.png
Crawl depth: 2

Diagram title: MNet Network Diagram
Out Catalog file: None

+l3n7k_76ad_ru34 (10.108.18.4)

l3n7k_76ad_ru34 (10.108.18.4)

Traceback (most recent call last):
File "/usr/local/bin/mnet.py", line 198, in
main(sys.argv[1:])
File "/usr/local/bin/mnet.py", line 67, in main
graph(argv[1:])
File "/usr/local/bin/mnet.py", line 129, in graph
graph.crawl(opt_root_ip)
File "/usr/local/lib/python2.7/dist-packages/mnetsuite/graph.py", line 92, in crawl
n.query_node()
File "/usr/local/lib/python2.7/dist-packages/mnetsuite/node.py", line 485, in query_node
self._get_chassis_info()
File "/usr/local/lib/python2.7/dist-packages/mnetsuite/node.py", line 809, in _get_chassis_info
self.ios = self._format_ios_ver(self.ios)
File "/usr/local/lib/python2.7/dist-packages/mnetsuite/node.py", line 831, in _format_ios_ver
img_s = re.search('(Version:? |CCM:)([^ ,$]*)', img)
File "/usr/lib/python2.7/re.py", line 142, in search
return _compile(pattern, flags).search(string)
TypeError: expected string or buffer


Reply to this email directly or view it on GitHub #11 . https://github.com/notifications/beacon/AKuwCmCWtynb0VdxMPQnLT73xNNb59Ahks5przkmgaJpZM4HtKKS.gif

@kamakazikamikaze
Copy link

Don't know if they ever got back to you, but I was having the same issue. I added the two lines as requested which allowed the script to continue. I ran this against a C6509 (R7000). Using SNMP for OID sysDescr(.0), the router responds with Cisco IOS Software, s72033_rp Software (s72033_rp-ADVIPSERVICESK9-M), Version 15.1(2)SY6, RELEASE SOFTWARE (fc4) in the first line.
itb_network

(EDIT: It also appears that the script is not visiting, or perhaps discovering, neighbors to devices I set as root, even with different -d values, but this may be an issue on my end)

@LaurentDumont
Copy link

I have the same issue with a 6509E. I modified the script but it still only discovers the first node and then exits. I've also tried with a 3750 with the same result. It discovers the first node but fails to crawl the network. I've tried changing the -dvalue but it doesn't change the output.

Couldn't import dot_parser, loading of dot files will not be possible.
MNet Suite v0.8.1
Written by Michael Laforest <mjlaforest@gmail.com>

     Config file: mnet.conf
       Root node: 10.6.66.254
     Output file: lanetsevent.png
     Crawl depth: 0
   Diagram title: MNet Network Diagram
Out Catalog file: None



      +core1.event (10.6.66.254)
-----
----- DEVICES
-----
-----------------------------------------
      Name: core1.event
        IP: 10.6.66.254
  Platform: None
   IOS Ver: None
    Serial: None
   Routing: yes
   OSPF ID: None
   BGP LAS: None
  HSRP Pri: None
  HSRP VIP: None
 Stack Cnt: 0
      Loopbacks:
        Not configured.
      SVIs:
        Not configured.
     Links:
Discovered devices: 1
Discovered links:   0
Created graph: lanetsevent.png

@dataolle
Copy link

I have the same problem:

./mnet.py graph -d4 -r 10.10.10.10 -f mnet.svg -C mnet.catalog
MNet Suite v0.8.1
Written by Michael Laforest mjlaforest@gmail.com

 Config file: ./mnet.conf
   Root node: 10.10.10.10
 Output file: mnet.svg
 Crawl depth: 4

Diagram title: MNet Network Diagram
Out Catalog file: mnet.catalog

  +coreswitch (10.10.10.10)
  >coreswitch (10.10.10.10)

----- DEVICES


  Name: coreswitch
    IP: 10.10.10.10

Platform: None
IOS Ver: None
Serial: FDOxxxxxxxx
Routing: yes
OSPF ID: 10.10.10.10
BGP LAS: None
HSRP Pri: None
HSRP VIP: None
Stack Cnt: 0
Loopbacks:
Not configured.
SVIs:
Links:
Discovered devices: 1
Discovered links: 0
Created graph: mnet.svg

I have tried on some cisco 3750, 3850, 4500 switches, same results. no links detected.
Is there any debugmode or something like that to be able to see whats going on?

@stevenscb
Copy link

Made the edit to node.py as suggested by Michael which fixed the traceback but discovery beyond the root node is broken.

I can grab info for the root device (hostname, IP, serial, routing) but the platform and IOS version from the OID_ENTPHYENTRY consistently come back across a number of different platforms as 'None' and this seems to stop the discovery process dead in it's tracks.

I can complete 'snmpwalk' commands to most of the OIDs listed in 'snmp.py' to my root node just fine. I tried to add print instructions to the various steps for the _get_chassis_info function in node.py for debugging purposes but I don't get any output (at all).

Here is the output for the graph module after making the change Michael suggested. It looks like the same behavior others are experiencing.

root@mapper-host:~/institution# mnet.py graph -r 10.1.1.1 -c ./institution.conf -f institution.png -t "Institution Network" -d 8
MNet Suite v0.8
Written by Michael Laforest <mjlaforest@gmail.com>

     Config file: ./institution.conf
       Root node: 10.1.1.1
     Output file: institution.png
     Crawl depth: 8
   Diagram title: Institution Network
Out Catalog file: None



      +root_node.domain (10.1.1.1)
      >root_node.domain (10.1.1.1)

-----
----- DEVICES
-----
-----------------------------------------
      Name: root_node.domain
        IP: 10.1.1.1
  Platform: None
   IOS Ver: None
    Serial: FXSXXXXXXX
   Routing: yes
   OSPF ID: None
   BGP LAS: None
  HSRP Pri: None
  HSRP VIP: None
 Stack Cnt: 0
      Loopbacks:
        Not configured.
      SVIs:
        Not configured.
     Links:
Discovered devices: 1
Discovered links:   0
Created graph: institution.png

@LaurentDumont
Copy link

LaurentDumont commented Apr 21, 2016

I'll try debugging it a bit more tomorrow. It would be a shame for a very small thing to prevent the entire process working.

@jbilder
Copy link

jbilder commented Aug 24, 2016

Any updates on this issue? I'm facing the same problem.

@RickTorresJr
Copy link

Got the same issue on a Cisco Catalyst 4500 running 15.0(2)SG

Traceback (most recent call last):
  File "/usr/local/bin/mnet.py", line 198, in <module>
    main(sys.argv[1:])
  File "/usr/local/bin/mnet.py", line 67, in main
    graph(argv[1:])
  File "/usr/local/bin/mnet.py", line 129, in graph
    graph.crawl(opt_root_ip)
  File "/usr/local/lib/python2.7/site-packages/mnetsuite/graph.py", line 92, in crawl
    n.query_node()
  File "/usr/local/lib/python2.7/site-packages/mnetsuite/node.py", line 485, in query_node
    self._get_chassis_info()
  File "/usr/local/lib/python2.7/site-packages/mnetsuite/node.py", line 809, in _get_chassis_info
    self.ios = self._format_ios_ver(self.ios)
  File "/usr/local/lib/python2.7/site-packages/mnetsuite/node.py", line 831, in _format_ios_ver
    img_s = re.search('(Version:? |CCM:)([^ ,$]*)', img)
  File "/usr/local/lib/python2.7/re.py", line 146, in search
    return _compile(pattern, flags).search(string)
TypeError: expected string or buffer

@refriedjello
Copy link

I am having the same issues as the people above, after making the suggested edits to node.py. It discovers the first device but none after that.

SNMP connectivity from the server to my switches is good, LLDP is enabled and shows neighbors via the CLI.

@jasonbarbee
Copy link
Contributor

jasonbarbee commented Jan 5, 2017

Actually - I forgot to update this thread - this might be fixed, at least I fixed it for me. I submitted a fix to master a couple weeks ago. The fix in this thread does not really fix it, just removes version from the discovery.
Grab the latest from the master branch, make no other revisions and try again. I fixed some pretty print() functions which were breaking the discovery process by looking up MIB numbers into titles, I just had to make sure it kept them as numeric OIDs, and it discovered and graphed about 50 nodes for me on 2950s, 2960S, and 2800 routers.
Let me know if the straight master code with no adjustments works for you,

@LaurentDumont
Copy link

Ohh shiny! Thanks for the work! I'll be able to test tomorrow with 20 or so 2960X and a 6503/04!

@refriedjello
Copy link

Different error now. I uninstalled the old version using 'sudo pip uninstall mnet' and then installed the latest master (extracted zip, uploaded to server) using 'sudo pip install -e mnet-master/' and it installs successfully.

If I leave depth at 0 is runs w/o error. But if set depth to 1 or more I get this:

Traceback (most recent call last):
File "/bin/mnet.py", line 8, in
execfile(file)
File "/home/admin/mnet-master/mnet.py", line 198, in
main(sys.argv[1:])
File "/home/admin/mnet-master/mnet.py", line 67, in main
graph(argv[1:])
File "/home/admin/mnet-master/mnet.py", line 129, in graph
graph.crawl(opt_root_ip)
File "/home/admin/mnet-master/mnetsuite/graph.py", line 84, in crawl
self._crawl_node(node, 0)
File "/home/admin/mnet-master/mnetsuite/graph.py", line 223, in _crawl_node
if (self.is_node_allowed(n.remote_ip) == 0):
File "/home/admin/mnet-master/mnetsuite/graph.py", line 263, in is_node_allowed
if (ip in IPNetwork(e)):
File "/usr/lib/python2.7/site-packages/netaddr/ip/init.py", line 726, in contains
if self.version != other.version:
AttributeError: 'str' object has no attribute 'version'

@LaurentDumont
Copy link

What devices are you running the script against? I'm wondering if the Pip version is actually updated with the current master.

@refriedjello
Copy link

My root device is a Cisco Nexus 9372. Other switches in the same network (directly connected) are Nexus 55xx, 2950, and 2960.

I uninstalled the PIP version and installed using the zip file from the master "https://github.com/MJL85/mnet/archive/master.zip"

Seems like an issue with netaddr based on that last traceback? There is a bunch of comments and suggestions on reddit here that I am sifting through at the moment.

But I am pretty new to using Python so any suggestions are welcome!

@LaurentDumont
Copy link

LaurentDumont commented Jan 5, 2017

There are definitely some differences between the different packages required/python versions. I'll take a look tomorrow too.

Check if you are running Python 2 or 3 and what is the version of your different packages. Ideally, if we can find the magical working versions I can probably cobble a Docker container from which we run everything with the correct dependencies.

@refriedjello
Copy link

I disabled using netaddr in "~/mnet-master/mnetsuite/util.py" by setting "USE_NETADDR" to 0.

It works against CDP but it looks like the code on my switches don't support LLDP info via SNMP, so I will have to look into that further.

Thanks guys for your help!

@jasonbarbee
Copy link
Contributor

Glad to hear that you found a workaround! That traceback is actually happening inside the netaddr package.
https://github.com/drkjam/netaddr/blob/rel-0.7.x/netaddr/ip/__init__.py
The line of code is in the init phase, and the code is checking IPV4 vs IPV6. It may be a defect in their library version you have for that, or a new parameter required that mnet should call into when initializing.

Glad the issue reported in the opening thread is fixed for you! If you want, you can open another issue specific to this netaddr component, and report the versions you are using too.

@HomerJaySimpson13
Copy link

Any update. i loaded the pip version. loaded the master.zip. And neither will discover any links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

12 participants