ktbyers / netmiko

Multi-vendor library to simplify Paramiko SSH connections to network devices
MIT License
3.62k stars 1.31k forks source link

Add A10 SSHDetect : Pattern not detected: 'A10DEVICE\\-Active\\-affinity\\-def\\-vMaster\\[1/1\\]' in output. #3431

Open romio28 opened 6 months ago

romio28 commented 6 months ago

Hello, I'm trying to add the ssh auto detect for A10 device:

"a10": {
    "cmd": "show version",
    "search_patterns": [r"Advanced Core OS \(ACOS\)"],
    "priority": 99,
    "dispatch": "_autodetect_std",
}

Command output:

A10DEVICE-Active-affinity-def-vMaster[1/1]>show version Thunder Series Unified Application Service Gateway TH3030S Copyright 2007-2017 by A10 Networks, Inc. All A10 Networks products are
protected by one or more of the following US patents:
.... 64-bit Advanced Core OS (ACOS) version 4.1.1-P5, build 20 (Sep-12-2017,18:18) Booted from Hard Disk primary image Serial Number: ......................... aFleX version: 2.0.0 aXAPI version: 3.0 Hard Disk primary image (default) version 4.1.1-P5, build 20 Hard Disk secondary image version 4.1.1-P5, build 20 Last configuration saved at May-2-2024, 17:05 Hardware: 8 CPUs(Stepping 9), Single 74G Hard disk Memory 16373 Mbyte, Free Memory 7376 Mbyte Hardware Manufacturing Code: ................. Current time is May-6-2024, 14:26 The system has been up 39 days, 14 hours, 35 minutes A10DEVICE-Active-affinity-def-vMaster[1/1]>

But i recive this error:

192.168.25.15 An exception occurred:

Pattern not detected: 'A10DEVICE\-Active\-affinity\-def\-vMaster\[1/1\]' in output.

Things you might try to fix this:

  1. Adjust the regex pattern to better identify the terminating string. Note, in many situations the pattern is automatically based on the network device's prompt.
  2. Increase the read_timeout to a larger value.

You can also look at the Netmiko session_log or debug log for more information.

Any help please?

ktbyers commented 6 months ago

@romio28 Can you turn on Netmiko logging and see what it shows?

https://github.com/ktbyers/netmiko/blob/develop/COMMON_ISSUES.md#enable-netmiko-logging-of-all-reads-and-writes-of-the-communications-channel

romio28 commented 6 months ago

Bellow the debug log:

`DEBUG:paramiko.transport:starting thread (client mode): 0xf0a55ee0 DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_3.4.0 DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_5.3 INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_5.3) DEBUG:paramiko.transport:=== Key exchange possibilities === DEBUG:paramiko.transport:kex algos: diffie-hellman-group-exchange-sha256, diffie-hellman-group14-sha1 DEBUG:paramiko.transport:server key: ssh-rsa DEBUG:paramiko.transport:client encrypt: aes128-ctr, aes192-ctr, aes256-ctr DEBUG:paramiko.transport:server encrypt: aes128-ctr, aes192-ctr, aes256-ctr DEBUG:paramiko.transport:client mac: hmac-sha1, hmac-sha2-512, hmac-sha2-256 DEBUG:paramiko.transport:server mac: hmac-sha1, hmac-sha2-512, hmac-sha2-256 DEBUG:paramiko.transport:client compress: none, zlib@openssh.com DEBUG:paramiko.transport:server compress: none, zlib@openssh.com DEBUG:paramiko.transport:client lang: DEBUG:paramiko.transport:server lang: DEBUG:paramiko.transport:kex follows: False DEBUG:paramiko.transport:=== Key exchange agreements === DEBUG:paramiko.transport:Kex: diffie-hellman-group-exchange-sha256 DEBUG:paramiko.transport:HostKey: ssh-rsa DEBUG:paramiko.transport:Cipher: aes128-ctr DEBUG:paramiko.transport:MAC: hmac-sha2-256 DEBUG:paramiko.transport:Compression: none DEBUG:paramiko.transport:=== End of kex handshake === DEBUG:paramiko.transport:Got server p (2048 bits) DEBUG:paramiko.transport:kex engine KexGexSHA256 specified hash_algo DEBUG:paramiko.transport:Switch to new keys ... DEBUG:paramiko.transport:Adding ssh-rsa host key for ..........: b'3663eaa75f80b79699f3369192473cfd' DEBUG:paramiko.transport:userauth is OK INFO:paramiko.transport:Authentication (password) successful! DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes DEBUG:paramiko.transport:[chan 0] Max packet out: 32768 bytes DEBUG:paramiko.transport:Secsh channel 0 opened. DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok DEBUG:netmiko:write_channel: b'\n' DEBUG:netmiko:read_channel: Last login: Mon May 6 16:42:23 2024 from ........

System is ready now.

[type ? for help]

A10_DEVICE_NAME-Active-affinity-def-vMaster[1/1]> DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b'show version\n' DEBUG:netmiko:read_channel: show version Thunder Series Unified Application Service Gateway TH4440S Copyright 2007-2018 by A10 Networks, Inc. All A10 Networks products are
protected by one or more of the following US patents:
.......

  64-bit Advanced Core OS (ACOS) version 4.1.1-P8, build 114 (Apr-10-2018,22:39)
    Booted from Hard Disk primary image
  Serial Number: 
  Firmware version: 12.4
  aFleX version: 2.0.0
  aXAPI version: 3.0
  Hard Disk primary image (default) version 4.1.1-P8, build 114
  Hard Disk secondary image version 4.1.1-P8, build 114
  Compact Flash primary image (default) version 4.1.1-P8, build 114
  Last configuration saved at May-2-2024, 17:09
  Hardware: 12 CPUs(Stepping 2), Single 93G Hard disk
  Memory 31846 Mbyte, Free Memory 11621 Mbyte
  Hardware Manufacturing Code: 
  Current time is May-6-2024, 21:49
  The system has been up 1251 days, 1 hour, 0 minute

A10_DEVICE_NAME-Active-affinity-def-vMaster[1/1]> DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:paramiko.transport:EOF in transport thread DEBUG:paramiko.transport:starting thread (client mode): 0xf0a5cf70 DEBUG:paramiko.transport:Local version/idstring: SSH-2.0-paramiko_3.4.0 DEBUG:paramiko.transport:Remote version/idstring: SSH-2.0-OpenSSH_5.3 INFO:paramiko.transport:Connected (version 2.0, client OpenSSH_5.3) DEBUG:paramiko.transport:=== Key exchange possibilities === DEBUG:paramiko.transport:kex algos: diffie-hellman-group-exchange-sha256, diffie-hellman-group14-sha1 DEBUG:paramiko.transport:server key: ssh-rsa DEBUG:paramiko.transport:client encrypt: aes128-ctr, aes192-ctr, aes256-ctr DEBUG:paramiko.transport:server encrypt: aes128-ctr, aes192-ctr, aes256-ctr DEBUG:paramiko.transport:client mac: hmac-sha1, hmac-sha2-512, hmac-sha2-256 DEBUG:paramiko.transport:server mac: hmac-sha1, hmac-sha2-512, hmac-sha2-256 DEBUG:paramiko.transport:client compress: none, zlib@openssh.com DEBUG:paramiko.transport:server compress: none, zlib@openssh.com DEBUG:paramiko.transport:client lang: DEBUG:paramiko.transport:server lang: DEBUG:paramiko.transport:kex follows: False DEBUG:paramiko.transport:=== Key exchange agreements === DEBUG:paramiko.transport:Kex: diffie-hellman-group-exchange-sha256 DEBUG:paramiko.transport:HostKey: ssh-rsa DEBUG:paramiko.transport:Cipher: aes128-ctr DEBUG:paramiko.transport:MAC: hmac-sha2-256 DEBUG:paramiko.transport:Compression: none DEBUG:paramiko.transport:=== End of kex handshake === DEBUG:paramiko.transport:Got server p (2048 bits) DEBUG:paramiko.transport:kex engine KexGexSHA256 specified hash_algo DEBUG:paramiko.transport:Switch to new keys ... DEBUG:paramiko.transport:Adding ssh-rsa host key for ............: b'3663eaa75f80b79699f3369192473cfd' DEBUG:paramiko.transport:userauth is OK INFO:paramiko.transport:Authentication (password) successful! DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes DEBUG:paramiko.transport:[chan 0] Max packet out: 32768 bytes DEBUG:paramiko.transport:Secsh channel 0 opened. DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok DEBUG:paramiko.transport:[chan 0] Sesch channel 0 request ok DEBUG:netmiko:write_channel: b'\n' DEBUG:netmiko:read_channel: Last login: Mon May 6 21:49:49 2024 from ...........

DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: ..... DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: System is ready now.

DEBUG:netmiko:read_channel: [type ? for help]

A10_DEVICE_NAME-Active-affinity-def-vMaster[1/1]> DEBUG:netmiko:Pattern found: ([>#]) Last login: Mon May 6 21:49:49 2024 from 172.17.248.8

System is ready now.

[type ? for help]

A10_DEVICE_NAME-Active-affinity-def-vMaster[1/1]> DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b'\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: A10_DEVICE_NAME-Active-affinity-def-vMaster[1/1]> DEBUG:netmiko: Parenthesis found in pattern.

pattern: (#|>)

This can be problemtic when used in read_until_pattern().

You should ensure that you use either non-capture groups i.e. '(?:' or that the parenthesis completely wrap the pattern '(pattern)' DEBUG:netmiko:Pattern found: (#|>) A10_DEVICE_NAME-Active-affinity-def-vMaster[1/1]> DEBUG:netmiko:read_channel: DEBUG:netmiko:[find_prompt()]: prompt is A10_DEVICE_NAME-Active-affinity-def-vMaster[1/1]> DEBUG:netmiko:write_channel: b'\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: A10_DEVICE_NAME-Active-affinity-def-vMaster[1/1]> DEBUG:netmiko:Pattern found: (A10_DEVICE_NAME-Active-affinity-def-vMaster[1/1].*) A10_DEVICE_NAME-Active-affinity-def-vMaster[1/1]> DEBUG:netmiko:write_channel: b'enable\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: enable Password: DEBUG:netmiko:Pattern found: (enable) enable DEBUG:netmiko:read_channel: DEBUG:netmiko:Pattern found: ((?:A10_DEVICE_NAME-Active-affinity-def-vMaster[1/1]|ssword)) Password DEBUG:netmiko:write_channel: b'\n' DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel:

DEBUG:netmiko:read_channel: Enter Old Password: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: .... DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b'\n' DEBUG:netmiko:read_channel: % Access denied

A10_DEVICE_NAME-Active-affinity-def-vMaster[1/1]> DEBUG:netmiko:read_channel: DEBUG:netmiko:read_channel: DEBUG:netmiko:write_channel: b'exit\n' DEBUG:paramiko.transport:EOF in transport thread `

ktbyers commented 6 months ago

@romio28 Can you show your entire code and your entire exception stack trace (i.e. all the lines of the exception stack trace).

romio28 commented 6 months ago

debug file: test.log

Code:

`from netmiko import SSHDetect, ConnectHandler import logging logging.basicConfig(filename='test.log', level=logging.DEBUG) logger = logging.getLogger("netmiko")

device = { "device_type": "autodetect", "host": "192.168.100.87", "username": "admin", "password": "admin123", }

guesser = SSHDetect(**device) best_match = guesser.autodetect() print(best_match) # Name of the best device_type to use further print(guesser.potential_matches) # Dictionary of the whole matching result device["device_type"] = best_match

with ConnectHandler(**device) as connection: print(connection.find_prompt())`

romio28 commented 6 months ago

The problem is in the find_prmpt() function, it trying to go in enable mode, it work if I add the secret password:

"C:\Users\PycharmProjects\backup\venv\Scripts\python.exe" "C:/Users//PycharmProjects/backup/test.py" a10 {'a10': 99} Traceback (most recent call last): File "C:\Users\PycharmProjects\backup\test.py", line 20, in with ConnectHandler(*device) as connection: File "C:\Users\PycharmProjects\backup\venv\lib\site-packages\netmiko\ssh_dispatcher.py", line 399, in ConnectHandler return ConnectionClass(args, **kwargs) File "C:\Users\PycharmProjects\backup\venv\lib\site-packages\netmiko\base_connection.py", line 489, in init self._open() File "C:\Users\PycharmProjects\backup\venv\lib\site-packages\netmiko\base_connection.py", line 495, in _open self._try_session_preparation() File "C:\Users\PycharmProjects\backup\venv\lib\site-packages\netmiko\base_connection.py", line 989, in _try_session_preparation self.session_preparation() File "C:\Users\PycharmProjects\backup\venv\lib\site-packages\netmiko\a10\a10_ssh.py", line 12, in session_preparation self.enable() File "C:\Users\PycharmProjects\backup\venv\lib\site-packages\netmiko\cisco_base_connection.py", line 26, in enable return super().enable( File "C:\Users\PycharmProjects\backup\venv\lib\site-packages\netmiko\base_connection.py", line 2043, in enable output += self.read_until_prompt() File "C:\Users\PycharmProjects\backup\venv\lib\site-packages\netmiko\base_connection.py", line 838, in read_until_prompt return self.read_until_pattern( File "C:\Users\PycharmProjects\backup\venv\lib\site-packages\netmiko\base_connection.py", line 747, in read_until_pattern raise ReadTimeout(msg) netmiko.exceptions.ReadTimeout:

Pattern not detected: 'A10_DEVICE_NAME\-Active\-affinity\-def\-vMaster\[1/1\]' in output.

Things you might try to fix this:

  1. Adjust the regex pattern to better identify the terminating string. Note, in many situations the pattern is automatically based on the network device's prompt.
  2. Increase the read_timeout to a larger value.

    You can also look at the Netmiko session_log or debug log for more information.

    Process finished with exit code 1

ktbyers commented 6 months ago

The A10 driver requires enable password (as A10 requires enable mode to disable output paging and Netmiko requires this).

https://github.com/ktbyers/netmiko/blob/develop/netmiko/a10/a10_ssh.py#L9-L12