ytti / oxidized

Oxidized is a network device configuration backup tool. It's a RANCID replacement!
Apache License 2.0
2.79k stars 922 forks source link

Execution of ssh_proxy if block when the configuration variable is empty #2267

Closed jameskirsop closed 2 years ago

jameskirsop commented 3 years ago

This is similar to #1936, but slightly different.

Take the following config extract:

source:
  default: sql
  sql:
    adapter: mysql2
...
    map:
      name: hostname
      ip: name
      model: model
      group: group
      username: username
      password: password
    vars_map:
      ssh_proxy: ssh_proxy
      enable: enable

and the following mysql table row:

hostid  |hostname   |name       |model      |group      |username   |password   |ssh_proxy  |enable |comware_cmdline
11505   |myhost     |192.168.20.1   |netscaler  |<GROUPNAME>    |<USER>     |<redacted> |       |   |512900

Currently, even though I've not set a value for ssh_proxy, the code block in this if statement is executed, presumably because "" in Ruby considered true:

Feb 23 12:29:14 nms oxidized[146462]: 192.168.20.1 raised Net::SSH::Proxy::ConnectError (rescued RuntimeError) with msg "command failed: ssh -o StrictHostKeyChecking=no  -W 192.168.20.1:22"

The linked if statement should be modified to grab the variable and check that it's not nil or empty before executing the corresponding code block.

mortzu commented 2 years ago

There is a PR fixing this. Please update the CHANGELOG in the PR and I'll happy to merge