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

device2yaml.rb starts commands to quick #3300

Closed systeembeheerder closed 2 weeks ago

systeembeheerder commented 2 weeks ago

Thanks @robertcheramy for all your work to create device2yaml.rb

I tried it to a MikroTik router but it seems the scripts starts way to early with sending commands, even before the prompt is complete.

me@computer:~/oxidized/examples/device-simulation$ ./device2yaml.rb user@router -c cmdsets/routeros -o yaml/routeros_L009UiGS_7.15.2.yaml -t 20

gives:

---
init_prompt: |-
  \r\e[9999B\r\e[9999B\eZ  \e[6n
commands:
  /system resource print: |-
  /system package update print: |-
    \e[9999B
    \r  MMM      MMM       KKK                          TTTTTTTTTTT      KKK
    \r  MMMM    MMMM       KKK                          TTTTTTTTTTT      KKK
    \r  MMM MMMM MMM  III  KKK  KKK  RRRRRR     OOOOOO      TTT     III  KKK  KKK
    \r  MMM  MM  MMM  III  KKKKK     RRR  RRR  OOO  OOO     TTT     III  KKKKK
    \r  MMM      MMM  III  KKK KKK   RRRRRR    OOO  OOO     TTT     III  KKK KKK
    \r  MMM      MMM  III  KKK  KKK  RRR  RRR   OOOOOO      TTT     III  KKK  KKK

    \r  MikroTik RouterOS 7.15.2 (c) 1999-2024       https://www.mikrotik.com/

    Press F1 for help

    \r\r\r\r[user@router] >                                               \r[user@router] >\x20
  /system history print without-paging: |-
    /system history print without-paging
  /export: |-
    /export
  quit: |-
    qui\r[user@router] > /system history print without-paging/exportqu>\r< history print without-paging/exportquit                                      \r< history print without-paging/exportquit
oxidized_output: |
  !! needs to be written by hand or copy & paste from model output

maybe start with an idle timeout before the first command?

See https://github.com/ytti/oxidized/compare/master...systeembeheerder:oxidized:test_d2y

robertcheramy commented 2 weeks ago

I can reproduce this, and I'll need to have a deeper look into this, I haven't found a good way to solve it for now.

device2yaml.rb has an idle timeout before the first command, but mikrotik seams to wildly interact with the terminal session (for example sending make 999x cursor down), which confuses device2yaml.rb.

robertcheramy commented 2 weeks ago

Update - routeros uses exec mode (so no interactive session an no ANSI-Escape-Code garbage). I'll add an option to device2yaml to run in exec mode.

robertcheramy commented 2 weeks ago

@systeembeheerder you need to run device2yaml in exec moded (added with commit d47248d04a6ecc2ccd36b2f6da141047d4519b06):

./device2yaml.rb admin@r7 -c cmdsets/routeros -e -o yaml/routeros_CHR_7.10.1.yaml

I've looked inside the netmiko driver for routeros - same ANSI-Escape-nightmare. I'm relived oxidized works in exec mode and that we need no tty with routeros.