ytti / oxidized

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

Source no implicit conversion of string into integer #235

Closed danbaugher closed 8 years ago

danbaugher commented 8 years ago

I'm new to ruby so I probably can't offer much help with this one. I ran into a problem trying to set this up using CSV as a data source.

/usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/source/csv.rb:34:in []': no implicit conversion of String into Integer (TypeError) from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/source/csv.rb:34:inblock (2 levels) in load' from /usr/local/rvm/gems/ruby-2.1.2/gems/asetus-0.3.0/lib/asetus/configstruct.rb:21:in each' from /usr/local/rvm/gems/ruby-2.1.2/gems/asetus-0.3.0/lib/asetus/configstruct.rb:21:ineach' from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/source/csv.rb:34:in block in load' from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/source/csv.rb:21:ineach_line' from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/source/csv.rb:21:in load' from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/nodes.rb:14:inblock in load' from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/nodes.rb:110:in synchronize' from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/nodes.rb:110:inwith_lock' from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/nodes.rb:10:in load' from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/nodes.rb:105:ininitialize' from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/core.rb:22:in new' from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/core.rb:22:ininitialize' from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/core.rb:12:in new' from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/core.rb:12:innew' from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/cli.rb:9:in run' from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/bin/oxidized:9:in<top (required)>' from /usr/local/rvm/gems/ruby-2.1.2/bin/oxidized:23:in load' from /usr/local/rvm/gems/ruby-2.1.2/bin/oxidized:23:in

' from /usr/local/rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in eval' from /usr/local/rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in
'

From what little I've been able to figure out with Ruby using puts it looks like this is choking on the name defintion for the 1 device I'm using for testing. I've tried using IP and Hostname with the same result. I even modified the router.db file to only supply the hostname and device type.

I've been through the config and docs several times and I'm probably missing something silly but I can't determine what the issue is.

ytti commented 8 years ago

Can you show me your config file and your 'CSV' file?

What ever the fault is, we should have more robust error checking and friendlier complaint.

danbaugher commented 8 years ago

I don't have access to the device at the moment but the CSV section is standard from the documents.

source: default: csv csv: file: ~/.config/oxidized/router.db delimiter: !ruby/regexp /:/ map: name: 0 model: 1 var_map: enable: enable

I have tried different versions of the router.db

172.16.0.10:mikrotik

or

mikrotest.host.net:mikrotik

The files exist in the location and they are writeable by the application at run time. I did some printf debug and puts was outputting the line as expected split into a hash.

ytti commented 8 years ago

This config should work, provided the indentation is correct. I'd still like to see the exact files varbatim where this failure occurs.

danbaugher commented 8 years ago

config:

username: redacted
password: redacted
model: mikrotik
interval: 3600
log: /root/.config/oxidized/log
debug: false
threads: 30
timeout: 20
retries: 3
prompt: !ruby/regexp /^([\w.@-]+[#>]\s?)$/
vars: {}
groups: {}
input:
  default: ssh, telnet
  debug: false
  ssh:
    secure: false
output:
  default: file
  file:
    directory: /root/.config/oxidized/configs
source:
  default: csv
  csv:
    file: ~/.config/oxidized/router.db
    delimiter: !ruby/regexp /:/
    map:
      name: 0
      model: 1
    vars_map:
      enable: enable
model_map:
  cisco: ios
  juniper: junos

router.db

mikrotest.example.net:mikrotik

router.db

172.16.10.20:mikrotik

error message:

t@oxidized:~# oxidized -d
no implicit conversion of String into Integer
/usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/source/csv.rb:34:in `[]': no implicit conversion of String into Integer (TypeError)
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/source/csv.rb:34:in `block (2 levels) in load'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/asetus-0.3.0/lib/asetus/configstruct.rb:21:in `each'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/asetus-0.3.0/lib/asetus/configstruct.rb:21:in `each'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/source/csv.rb:34:in `block in load'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/source/csv.rb:21:in `each_line'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/source/csv.rb:21:in `load'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/nodes.rb:14:in `block in load'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/nodes.rb:110:in `synchronize'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/nodes.rb:110:in `with_lock'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/nodes.rb:10:in `load'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/nodes.rb:105:in `initialize'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/core.rb:22:in `new'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/core.rb:22:in `initialize'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/core.rb:12:in `new'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/core.rb:12:in `new'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/cli.rb:9:in `run'
        from /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/bin/oxidized:9:in `<top (required)>'
        from /usr/local/rvm/gems/ruby-2.1.2/bin/oxidized:23:in `load'
        from /usr/local/rvm/gems/ruby-2.1.2/bin/oxidized:23:in `<main>'
        from /usr/local/rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
        from /usr/local/rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
ytti commented 8 years ago

Can you remove the vars_map. Not sure if that is the cause, but you don't have field named 'enable' so mapping it to variable named 'enable' doesn't make sense. If that fixes it, I'll make more sensible error message for this issue.

danbaugher commented 8 years ago

That error has gone away. Now I get a no usable devices error which is strange because I can remote into the device from the server with or without a password. Is there a way to debug the connection between oxidized and the device?

ytti commented 8 years ago

Yeah there is

input: debug: true

it should produce session log for devices

danbaugher commented 8 years ago

Here's the output from the crash file. The log file stayed empty. As you can see there's not much to work with here.

2015-11-10 15:17:15 UTC
source returns no usable nodes [Oxidized::Core::NoNodesFound]
--------------------------------------------------
/usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/core.rb:23:in `initialize'
/usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/core.rb:12:in `new'
/usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/core.rb:12:in `new'
/usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/cli.rb:9:in `run'
/usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/bin/oxidized:9:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.1.2/bin/oxidized:23:in `load'
/usr/local/rvm/gems/ruby-2.1.2/bin/oxidized:23:in `<main>'
/usr/local/rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
--------------------------------------------------
ytti commented 8 years ago

Actually 'source returns no usable nodes' is useful.

It means the file does not contain anything we can use. Reading it more carefully, you've used 'mikrotik' as model name, we don't have such model. You either need to use correct model name or you need to add mapping to map your router.db model name to oxidized model name. Our model name is 'routeros'.

Your syslog may have more information actually.

On 10 November 2015 at 17:18, Dan Baugher notifications@github.com wrote:

Here's the output from the crash file. The log file stayed empty. As you can see there's not much to work with here.

2015-11-10 15:17:15 UTC

source returns no usable nodes [Oxidized::Core::NoNodesFound]

/usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/core.rb:23:in initialize' /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/core.rb:12:innew' /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/core.rb:12:in new' /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/lib/oxidized/cli.rb:9:inrun' /usr/local/rvm/gems/ruby-2.1.2/gems/oxidized-0.9.0/bin/oxidized:9:in <top (required)>' /usr/local/rvm/gems/ruby-2.1.2/bin/oxidized:23:inload' /usr/local/rvm/gems/ruby-2.1.2/bin/oxidized:23:in <main>' /usr/local/rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:ineval'

/usr/local/rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `
'

— Reply to this email directly or view it on GitHub https://github.com/ytti/oxidized/issues/235#issuecomment-155448904.

++ytti

danbaugher commented 8 years ago

That would be why. I pulled the mikrotik name from some router.db documentation I found on the web.

Would adding an alias for routeros be prudent based on all the rancid documentation out there?

Thanks for taking the time to look into this I really appreciate the help.

ytti commented 8 years ago

Because of rancid we have model_map.

You can do:

model_map: cisco: ios juniper: junos mikrotik: routeros

We chose to use OS name, not manufacturer name since 'juniper' and 'cisco' are ambiguous, both manufacturers have large number of operating systems which have nothing in common, so calling one 'cisco' is confusing. https://github.com/ytti/oxidized#hooks

On 11 November 2015 at 02:02, Dan Baugher notifications@github.com wrote:

That would be why. I pulled the mikrotik name from some router.db documentation I found on the web.

Would adding an alias for routeros be prudent based on all the rancid documentation out there?

Thanks for taking the time to look into this I really appreciate the help.

— Reply to this email directly or view it on GitHub https://github.com/ytti/oxidized/issues/235#issuecomment-155607716.

++ytti

danbaugher commented 8 years ago

I sent pull request #237 to update the readme to make the OS names a bit clearer. If I have some time soon I will add additional information to the readme for creating the router.db file.