ytti / oxidized

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

Issue with group configuration #651

Closed arturs0 closed 7 years ago

arturs0 commented 7 years ago

Hello,

I have an issue with group configurations.

If I have only one group configured then the backup of configuration will suceed for that group. If I configure a second group both groups will fail.

Here is my configuration:

username: admin
password: ##########
model: fortigate
interval: 3600
use_syslog: false
debug: false
threads: 30
timeout: 20
retries: 3
prompt: !ruby/regexp /^([\w.@-]+[#>]\s?)$/
rest: xx.xxx.xxx.xxx:8888
vars: {}
groups: {}
Group1:
username: admin
password: ########
#Group2:
#username: admin
#password: ########
pid: /home/ox/.config/oxidized/pid
input:
  default: ssh
  debug: false
  ssh:
    secure: true
output:
  default: file
  file:
    directory: /home/ox/.config/oxidized/configs
source:
  default: csv
  csv:
    file: /home/ox/.config/oxidized/router.db
    delimiter: !ruby/regexp /:/
    map:
      name: 0
      model: 1
      groups: 2

vars_map:
  enable: 4
model_map:
fortigate: fortios

Here is my router.db file:

x.xxxx.xxxx:fortios:Group1
xxxxx.xxxxx.xxxxxxx:fortios:Group2

What could be the cause of this issue?

What would be the correct way to use groups?

Best Regards, Artur

ytti commented 7 years ago

If that config is truthful, then the config is missing indents in groups and model_map.

You group config does nothing. You specify empty groups then just add keys in config named Group1, username and password, essentially overwriting last value of username password, and introducing unknown/unused keys Group1, Group2.

arturs0 commented 7 years ago

Thank you for the fast reply.

Even If I added the missing indents like so:

groups:
  Group1:
    username: admin
    password: ###########
  Group2:
    username: admin
    password: ###########

The group configuration does not seem to work.

What would be the correct way to add the indents?

Best Regards, Arturs0

ytti commented 7 years ago

Did you still have groups: {} as well? Did you also fix the model_map indent? What is the full config right now?

The new indentation you show is correct, but unsure what the other config is. Also which Oxidized version are you running?

arturs0 commented 7 years ago

Yes I still have groups: {} aswell.

I have installed: oxidized-0.18.0, oxidized-script-0.3.1 and oxidized-web-0.7.1.

With this configuration I am getting an error:

Error loading config: (<unknown>): did not find expected key while parsing a block mapping at line 2 column 1
/usr/local/share/gems/gems/oxidized-0.18.0/lib/oxidized/config.rb:50:in `rescue in load': Error loading config: (<unknown>): did not find expected key while parsing a block mapping at line 2 column 1 (Oxidized::InvalidConfig)

Without the brackets the configuration runs but seems to ignore the groups.

---
username: admin
password: ##########
model: fortigate
interval: 3600
use_syslog: false
debug: false
threads: 30
timeout: 20
retries: 3
prompt: !ruby/regexp /^([\w.@-]+[#>]\s?)$/
rest: xxx.xxx.xxx.xxx:8888
vars: {}
groups: {}
  Group1:
    username: admin
    password: ##########
  Group2:
    username: admin
    password: ##########
pid: /home/ox/.config/oxidized/pid
input:
  default: ssh
  debug: true
  ssh:
    secure: true
output:
  default: file
  file:
    directory: /home/ox/.config/oxidized/configs
source:
  default: csv
  csv:
    file: /home/ox/.config/oxidized/router.db
    delimiter: !ruby/regexp /:/
    map:
      name: 0
      model: 1
      group: 2

vars_map:
  enable: 4
model_map:
  fortigate: fortios
ytti commented 7 years ago

Remove the {} it makes the groups hash empty.

arturs0 commented 7 years ago

If I remove the {} it still seems to ignore the group config.

ytti commented 7 years ago

And on your router.db 3rd field is Group1 or Group2? You're not getting in output directory Group1 and Group2?

This is not related, but vars_map should be under csv same level as map

laf commented 7 years ago

@arturs0 Any response to this?

kiq-moraes commented 7 years ago

Hi, How do I configure the groups correctly? Could you pass some configuration examples? In the scenario of my oxidized I will use 5 different groups. Thanks

laf commented 7 years ago

@kiq-moraes have you tried https://github.com/ytti/oxidized#advanced-group-configuration

kiq-moraes commented 7 years ago

Hi, Thanks for help me and sorry for my bad english. It is currently running without groups, manually entered all information on router.db I'd like to use with groups to stay more dynamic since we already have about a hundred monitored hosts. Here are examples of how I tried to configure with groups.

In the 'config' file of oxidized:

groups:
  mikrotik:
    username: admin
    password: admin
  ubiquiti:
    username: admin
    password: admin
models:
  routeros:
    username: admin
    password: admin
  airos:
    username: admin
    password: admin
  edgeswitch:
    username: admin
    password: admin
map:
    name: 0
    ip: 1
    model: 2
    group: 3
vars_map
    ssh_port: 4

And in the 'router.db':

sw1:192.168.1.10:routeros::: sw2:192.168.1.20:airos::: sw3:192.168.1.30:edgeswitch::22000

But still don´t work. Regards, Caíque

laf commented 7 years ago

The map needs to be under source. Post your entire config.

danilopopeye commented 7 years ago

@arturs0 have you managed to make the group config work?

kiq-moraes commented 7 years ago

Hi, Here follows the entire configuration file. Sorry for the delay. The commented lines are because they did not work... Again, thank you very much, guys.

---
username: usuario
password: abobrinha
model: 
interval: 3600 
use_syslog: true
log: /home/oxidized/.config/oxidized/logs/
debug: true
threads: 30
timeout: 20
retries: 2
prompt: !ruby/regexp /^([\w.@-]+[#>]\s?)$/
rest: ip:port
next_adds_job: false
vars:
  enable: abobrinha
groups: {}
//   datacom:
//  username: admin
//  password: abobrinha
//   mikrotik:
//  username: admin
//  password: abobrinha
//    hp:
//  username: admin
//  password: abobrinha
//    huawei:
//  username: admin
//  password: abobrinha
//    ubiquiti
//  username: admin
//  password: abobrinha
models: {}
//    airos:
//  username: admin
//  password: abobrinha
//   edgeswitch:
//  username: admin
//  password: abobrinha
//    datacom:
//  username: admin
//  password: abobrinha
//   comware:
//  username: admin
//  password: abobrinha
//   procurve:
//  username: admin
//  password: abobrinha
//    routeros:
//  username: admin
//  password: abobrinha
//   vrp:
//  username: admin
//  password: abobrinha
pid: /home/oxidized/.config/oxidized/pid
input:
  default: ssh, telnet
  debug: true
  ssh:
    secure: false
output:
//  default: file
//  file:
//   directory: /home/oxidized/.config/oxidized/configs
output:
  default: git
  git:
    user: usuario
    email: o@example.com
//  repo: "/var/lib/oxidized/devices.git"
    repo: "/home/oxidized/lib/oxidized/output/git.rb"
source:
  default: csv
  csv:
    file: /home/oxidized/.config/oxidized/router.db
    delimiter: !ruby/regexp /:/
    map:
      name: 0
      ip: 1
      model: 2
      username: 3
      password: 4
    vars_map:
      ssh_port: 5
// map:
//   name: 0
//   ip: 1
//    model: 2
//    group: 3
// vars_map
//    ssh_port: 4
model_map:
  mikrotik: routeros
  cisco: ios
  juniper: junos
  hp: procurve, comware
  datacom: datacom
  huawei: vrp
  ubiquiti: airos, edgeswitch
laf commented 7 years ago

You look to have a few issues with the config, I've tried to tidy it up (I've not included all your models and groups, you can re-populate those:

---
username: usuario
password: abobrinha
model: 
interval: 3600 
use_syslog: true
log: /home/oxidized/.config/oxidized/logs/
debug: true
threads: 30
timeout: 20
retries: 2
prompt: !ruby/regexp /^([\w.@-]+[#>]\s?)$/
rest: ip:port
next_adds_job: false
vars:
  enable: abobrinha
groups:
    datacom:
        username: admin
        password: abobrinha
models:
    airos:
        username: admin
        password: abobrinha
pid: /home/oxidized/.config/oxidized/pid
input:
  default: ssh, telnet
  debug: true
  ssh:
    secure: false
output:
  default: git
  git:
    user: usuario
    email: o@example.com
    repo: "/home/oxidized/lib/oxidized/output/git.rb"
source:
  default: csv
  csv:
    file: /home/oxidized/.config/oxidized/router.db
    delimiter: !ruby/regexp /:/
    map:
      name: 0
      ip: 1
      model: 2
      username: 3
      password: 4
    vars_map:
      ssh_port: 5
model_map:
  mikrotik: routeros
  cisco: ios
  juniper: junos
  hp: comware
  datacom: datacom
  huawei: vrp
  ubiquiti: airos
danilopopeye commented 7 years ago

@arturs0 can you try the config @laf posted and see if your problem still persists?

laf commented 7 years ago

@arturs0 If you are still having issues please feel free to reply and we can re-open this issue.