question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Backslash added in hostname leading to 'pattern not detected'

See original GitHub issue

I’m trying to execute a list of commands on devices from a specific inventory by using Nornir. It seems I’m facing an issue at Netmiko level. For some reasons backslash are added to the hostname of some IOS devices (not all) leading to below error:

Traceback (most recent call last):
  File "/home/administrator/venv_nornir/lib/python3.8/site-packages/nornir/core/task.py", line 99, in start
    r = self.task(self, **self.params)
  File "/home/administrator/venv_nornir/lib/python3.8/site-packages/nornir_napalm/plugins/tasks/napalm_cli.py", line 20, in napalm_cli
    result = device.cli(commands)
  File "/home/administrator/venv_nornir/lib/python3.8/site-packages/napalm/ios/ios.py", line 2372, in cli
    output = self._send_command(command)
  File "/home/administrator/venv_nornir/lib/python3.8/site-packages/napalm/ios/ios.py", line 205, in _send_command
    output = self.device.send_command(command)
  File "/home/administrator/venv_nornir/lib/python3.8/site-packages/netmiko/utilities.py", line 600, in wrapper_decorator
    return func(self, *args, **kwargs)
  File "/home/administrator/venv_nornir/lib/python3.8/site-packages/netmiko/base_connection.py", line 1694, in send_command
    raise ReadTimeout(msg)
netmiko.exceptions.ReadTimeout:
Pattern not detected: 'CPE\\-XXX\\-YYYYYY\\-ZZZZZZZZ>' in output.

Things you might try to fix this:
1. Explicitly set your pattern using the expect_string argument.
2. Increase the read_timeout to a larger value.

For exemple, device hostname ‘CPE-XXX-YYYYYY-ZZZZZZZZ>’ is converted according ReadTimeout error to: ‘CPE\-XXX\-YYYYYY\-ZZZZZZZZ>’.

To share more details you can find below inventory connection_options settings:

    "provider": {
      "name": "provider",
      "connection_options": {
        "napalm": {
          "extras": {
            "optional_args": {
              "force_no_enable": true,
              "ssh_config_file": "~/.ssh/config"
            }
          },
          "hostname": null,
          "port": null,
          "username": null,
          "password": null,
          "platform": null
        },
        "netmiko": {
          "extras": {
            "fast_cli": false,
            "global_delay_factor": 2
          },
          "hostname": null,
          "port": null,
          "username": null,
          "password": null,
          "platform": null
        }
      }

The tricky point is the issue doesn’t appear for all devices even if they are using the same plateform (ios) and same OS version. Moreover, I’m not 100% sure the issue is coming from the hostname.

I’m reaching devices through IP and I can not set the pattern cause I don’t know before to connect to devices the configured hostname.

Could you please help me to solve this issue?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JulienSSHcommented, Apr 5, 2022

Ok I don’t have any idea of the reason of the issue but for some reason we rebooted the devices and my script is working as expected now.

0reactions
ktbyerscommented, Apr 5, 2022

Okay, FWIW I pretty much never use napalm_cli.

In this case, I would probably say you should just straight Netmiko (i.e. you are just adding a layer of indirection to get at the Netmiko driver). So if it comes up again, I will probably ask if you can reproduce the issue directly using Netmiko.

Read more comments on GitHub >

github_iconTop Results From Across the Web

STRMATCH involving backslashes not working 9.5 SP1 ...
I've tested this numerous ways, still not working. The guide for 9.0 shows that when looking for a pattern matching the backslash, '\\'...
Read more >
What is the meaning of the leading slash / in Tomcat's <url ...
The empty string ("") is a special URL pattern that exactly maps to the application's context root, i.e., requests of the form http://host:port/<contextroot>/...
Read more >
Allow URIs with Slash and Backslash in Apache Tomcat
Open the Denodo Platform Control Center. Click Configure. Click JVM Options. In the Web container box, add the following to the current value...
Read more >
When its necessary to add backslash before dot when using sed
The replacement part of an s expression in sed is however not a ... and the s command delimiter ( / if using...
Read more >
CVE-2022-0011 PAN-OS: URL Category Exceptions Match ...
When the entries in these lists have a hostname pattern that does not end with a forward slash (/) or a hostname pattern...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found