ktbyers / netmiko_tools

Command line tools built on Netmiko to simplify information gathering
Apache License 2.0
94 stars 32 forks source link

No handlers could be found for logger "paramiko.transport" #35

Open opnine opened 6 years ago

opnine commented 6 years ago

Paramiko version = paramiko (2.4.1)

./netmiko-show --cmd "show ip int brief" cisco

I get the error in the subject.

ktbyers commented 6 years ago

That is just a Paramiko warning (which doesn't matter); there is likely a separate error.

Can you post the entire output of what you received?

Kirk

opnine commented 6 years ago

it stays there with that output, and I don't get any type of information. I have to manually cancel the task.

ktbyers commented 6 years ago

Can you post your code and the output you see on the screen?

How long are you waiting before break out of the task?

Kirk

opnine commented 6 years ago

I never get a any timeout , but I found that the issue starts when I have to add the static route to access that devices. If I remove the route I only get a timeout, but if I add the route to access , i get the error.

ktbyers commented 6 years ago

Okay, please post your code and the output you see when you execute your code. The paramiko logging message is an unimportant logging warning so that is a side-effect of some other issue.

Kirk

ktbyers commented 6 years ago

My bad, I thought this was a straight Netmiko issue, not netmiko_tools.

ktbyers commented 6 years ago

@opnine How long are you waiting for the timeout. You probably have to wait at least two minutes (in certain contexts).

opnine commented 6 years ago

I neve get the time out . No handlers could be found for logger "paramiko.transport" ^CTraceback (most recent call last): File "./maxson-show", line 181, in sys.exit(main(sys.argv[1:])) File "./maxson-show", line 164, in main grepx(my_files, pattern, grep_options) File "./maxson-show", line 48, in grepx proc.communicate() File "/usr/lib/python2.7/subprocess.py", line 480, in communicate self.wait() File "/usr/lib/python2.7/subprocess.py", line 1099, in wait pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0) File "/usr/lib/python2.7/subprocess.py", line 125, in _eintr_retry_call return func(*args) KeyboardInterrupt

ktbyers commented 6 years ago

What operating system are you on?

What is the path to grep?

Did files get created in ~/.netmiko/tmp?

Kirk

collin-clark commented 5 years ago

I get this same error. I've tried both installs (git and download tar), doesn't seem to make a difference. I've tried it on Ubuntu 16.04, Ubuntu 18.04 and CentOS 7.4. The files do get created, however all they have in them is %%%failed%%%. I have let it run for ~45 minutes and the only way out is to CTRL-C.

Command: ./netmiko-grep 'zone' all

I have verified that Paramiko, Netmiko, grep and netmiko-grep are all in my PATH.

On the hosts I've installed the full netmiko toolset, I've tried netmiko-show and netmiko-cfg with the same results.

My inventory file [.netmiko.yml] is in the same directory as netmiko-grep and it is below. I also tried it in my home dir and get the same results.


test: device_type: cisco_ios ip: 10.0.0.63 username: mmessier password: LeTsGoRaNgErS port: 22

ktbyers commented 5 years ago

@collin-clark What does the output of this show:

$ netmiko-grep --list-devices
collin-clark commented 5 years ago

root@srvnet01 netmiko_tools]# ./netmiko-grep --list-devices

Devices:
----------------------------------------
test                         (cisco_ios)

Groups:
----------------------------------------
all
ktbyers commented 5 years ago

@collin-clark FYI, you can wrap it in triple backtick:

my output
ktbyers commented 5 years ago

@collin-clark Does this user:

mmessier

Have privilege level 15 (i.e. it needs to be able to do 'show run')?

collin-clark commented 5 years ago

Yes, he does.

collin-clark commented 5 years ago

The router (10.0.0.63) never shows a login attempt.

ktbyers commented 5 years ago

Okay, I would take it out of netmiko-tools and try it directly in Netmiko:

from netmiko import ConnectHandler

my_device = { 
    "device_type" : "cisco_ios",
    "ip": "10.0.0.63",
    "username": "mmessier",
    "password": "password",
    "port": 22, 
}

net_connect = ConnectHandler(**my_device)
output = net_connect.send_command("show run")
print(output)

And see what happens (note, I changed the password, but everything else should be identical).

ktbyers commented 5 years ago

Try to execute that with the correct password and see what occurs.

collin-clark commented 5 years ago

That works. I see the 'show run'.

ktbyers commented 5 years ago

Okay, it would be interesting if in the netmiko-grep executable, you commented these two lines out:

def ssh_conn(device_name, a_device, cli_command, output_q):
    # try:
        net_connect = ConnectHandler(**a_device)
        net_connect.enable()
        output = net_connect.send_command_expect(cli_command)
        net_connect.disconnect()
    # except Exception:
    #    output = ERROR_PATTERN
    output_q.put({device_name: output})

In other words, comment out the try/except so that the exception just happens. You might have to fix the indentation also.

ktbyers commented 5 years ago

This way, hopefully, we can see the actual exception.

collin-clark commented 5 years ago
[root@srvnet01 netmiko_tools]# ./netmiko-grep 'zone' all
No handlers could be found for logger "paramiko.transport"
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib64/python2.7/threading.py", line 812, in __bootstrap_inner
    self.run()
  File "/usr/lib64/python2.7/threading.py", line 765, in run
    self.__target(*self.__args, **self.__kwargs)
  File "./netmiko-grep", line 55, in ssh_conn
    net_connect = ConnectHandler(**a_device)
  File "/usr/lib/python2.7/site-packages/netmiko/ssh_dispatcher.py", line 218, in ConnectHandler
    return ConnectionClass(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/netmiko/base_connection.py", line 270, in __init__
    self.establish_connection()
  File "/usr/lib/python2.7/site-packages/netmiko/base_connection.py", line 782, in establish_connection
    self.remote_conn_pre.connect(**ssh_connect_params)
  File "/usr/lib/python2.7/site-packages/paramiko/client.py", line 437, in connect
    passphrase,
  File "/usr/lib/python2.7/site-packages/paramiko/client.py", line 736, in _auth
    self._transport.auth_password(username, password)
  File "/usr/lib/python2.7/site-packages/paramiko/transport.py", line 1436, in auth_password
    return self.auth_handler.wait_for_response(my_event)
  File "/usr/lib/python2.7/site-packages/paramiko/auth_handler.py", line 236, in wait_for_response
    raise e
TypeError: object of type 'int' has no len()

It just hangs there, no more output.

ktbyers commented 5 years ago

What do you see if you add a print statement here?

def ssh_conn(device_name, a_device, cli_command, output_q):
    # try:
        print(a_device)
        net_connect = ConnectHandler(**a_device)
        net_connect.enable()
        output = net_connect.send_command_expect(cli_command)
        net_connect.disconnect()
    # except Exception:
    #    output = ERROR_PATTERN
    output_q.put({device_name: output})
collin-clark commented 5 years ago
{'username': mmessier, 'ip': '10.0.0.63', 'password': '********', 'port': 22, 'device_type': 'cisco_ios'}

That seems to look good.

ktbyers commented 5 years ago

I assume you tested the netmiko script and netmiko-tools from the same exact machine using the same exact virtual environment?

I am not really seeing any difference between those two from a code perspective, but in the netmiko_tools case it doesn't look like the traffic is exiting your machine. You don't have any firewall or or SE-linux that would be blocking it in this case?

collin-clark commented 5 years ago

I jumped over to my Ubuntu box and made the same changes as we did on the CentOS box (verified no firewall/SE). It however has a larger inventory. I ran it and I get the same results, however there is a a couple of new additional traceback that may be helpful.

Exception in thread Thread-17:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "./netmiko-grep", line 56, in ssh_conn
    net_connect = ConnectHandler(**a_device)
  File "/home/ubuntu/netmiko_tools/venv/lib/python2.7/site-packages/netmiko/ssh_dispatcher.py", line 218, in ConnectHandler
    return ConnectionClass(*args, **kwargs)
  File "/home/ubuntu/netmiko_tools/venv/lib/python2.7/site-packages/netmiko/base_connection.py", line 270, in __init__
    self.establish_connection()
  File "/home/ubuntu/netmiko_tools/venv/lib/python2.7/site-packages/netmiko/base_connection.py", line 787, in establish_connection
    raise NetMikoTimeoutException(msg)
NetMikoTimeoutException: Connection to device timed-out: cisco_ios 10.130.60.3:22
ktbyers commented 5 years ago

Okay, that would lead me to believe that it can't reach that IP address on port 22 (from that machine).

collin-clark commented 5 years ago

Ahhh, old device, sorry about that. In digging a little deeper I noticed that the info from the print statement we added, that the username is not in single-quotes. Does that matter?

{'username': mmessier, 'ip': '10.0.0.63', 'password': '********', 'port': 22, 'device_type': 'cisco_ios'}
ktbyers commented 5 years ago

Yes, the username should be quoted in the print output. I would quote it in your source YAML file and re-test:

test:
  device_type: cisco_ios
  ip: 10.0.0.63
  username: "mmessier"
  password: passw
  port: 22
collin-clark commented 5 years ago

I quoted it in my YAML file, but in the print statement, its still showing without any quotes.

collin-clark commented 5 years ago

I'm sorry, I am incorrect. When quoting in the YAML it IS working. Verified on Ubuntu 18.04 and CentOS 7.4.

ktbyers commented 5 years ago

Ugly...weird. I wonder if there is a hidden character in your YAML file.

You could try to print(repr(a_device['username']))

But it looks like you have it working.

But anyways looks like it is fixed.