[rancid] Trying to backup InfiNet Devices

heasley heas at shrubbery.net
Thu Jan 6 22:55:37 UTC 2022


Thu, Jan 06, 2022 at 10:23:44PM +0000, Daniel Thomas:
> Hi
> 
> 
> 
> I have been working on getting RANCID to collect configuration information
> from some equipment that is made by InfiNet. So far I have been unable to
> locate any similar work performed previously and so made a start on getting
> RANCID to connect to the devices.
> 
> 
> 
> Through trial and error I found that the “jlogin” login script was able to
> connect to the device but would not allow interaction once connected. I
> decided to use that script as a base for my work and so made a copy of it
> and named that copy “infilogin” I found that the reason that issues were
> being hit was that the match of the prompt string was being thrown off as
> the InfiNet device changes it’s prompt, and that there were trailing
> charaters what were causing issues.
> 
> With regards the changing prompt I saw it take the two following forms:
> basehostname>
> basehostname$1>
> 
> And the trailing characters I saw were:
> 
> \r\u001b[16C\u001b[K\r\u001b[16C
> 
> To work around this I created an “”altprompt” which took a substring of
> “$prompt” and then did some greedy matching which then gave the following
> in the “we are now logged in, figure out the full prompt”

You might look at clogin; the EXOS also has a command line counter.  Is it
a cmd-line counter?

And, look at hlogin, which uses hpuifilter to remove most of the screen
manipulation escape codes.  Sometimes a more rudimentary TERM type causes
devices no use the escape codes; like 'network' or 'dumb'.  there are at
least 2 *.pm's that do this.

I think that if you combine these two methods, it will be easier.  copy
clogin and modify for the prompt alternatives, add the hpuifilter changes
from hlogin.

if thats not attractive, debug the missed commands with rancid -d -t <type>
looking for the command matches.  I expect there will be none and the *.new
file will be empty.  Compare the prompt matchine in inloop() to whats in
the *.raw file and look for escape codes in the prompts within the *.raw file.

below, I would just alter $prompt to accept either version of the prompt.
That will make it easier (more consistent with other scripts) for -x or
-s.

> [..
> 
> 
> 
>     # we are logged in, now figure out the full prompt
> 
>     send "\r"
> 
>     expect {
> 
>         -re "(\r\n|\n)"         { exp_continue; }
> 
>         -re "^\[^ ]+$prompt"    { set prompt $expect_out(0,string);
> 
>                                   *regsub ">" $prompt ">" prompt;
>  *
>                                  <<<<
> 
>                                 }
> 
>     }
> 
>     # send $prompt
> 
>     set in_proc 0
> 
>     return 0
> 
> }
> 
> 
> 
> # Run commands given on the command line.
> 
> proc run_commands { prompt command } {
> 
>     global do_interact in_proc
> 
>     set in_proc 1
> 
> 
> 
>   *  set altprompt [string range $prompt 0 11]   *
>               <<<<
> 
>     # handle escaped ;s in commands, and ;; and ^;
> 
>     regsub -all {([^\\]);} $command \\1\u0002; esccommand
> 
>     regsub -all {([^\\]);;} $esccommand \\1;\u0002; command
> 
>     regsub {^;} $command "\u0002;" esccommand
> 
>     regsub -all {[\\];} $esccommand ";" command
> 
>     regsub -all {\u0002;} $command "\u0002" esccommand
> 
>     set sep "\u0002"
> 
>     set commands [split $esccommand $sep]
> 
>     set num_commands [llength $commands]
> 
>     for {set i 0} {$i < $num_commands} { incr i} {
> 
>         send -- "[subst -nocommands [lindex $commands $i]]\r"
> 
>         expect {
> 
>             *-re "^\[^\n\r *]*$prompt.*" {}*
>                             <<<<
> 
>          *   -re "^$altprompt.*>.*"      {} *
> <<<<
> 
>             -re "^\[^\n\r]*$prompt."    { exp_continue }
> 
>             -re "(\r\n|\n)"             { exp_continue }
> 
>            * -re "\r-- more --\r"        { send " "; exp_continue }
> *
>                        <<<<
> 
>         }
> 
>     }
> 
> 
> 
> 
> 
> ..]
> 
> 
> 
> I have marked my deviations from “jlogin” with four less than signs.
> 
> 
> 
> With these bodges applied I can successfully get connected to a device,
> execute commands and exit. I can also issue the “infilogin” with -c or -x
> and  the relevant commands will execute, and I see the output. I then went
> and updated the “rancid.types.conf” with an entry as below:
> 
> 
> 
> [..
> 
> infinet;script;rancid -t infinet
> 
> infinet;login;jlogin
> 
> infinet;module;infinet
> 
> infinet;inloop;infinet::inloop
> 
> infinet;command;infinet::ShowVersion;system version
> 
> infinet;command;infinet::ShowConfiguration;config show
> 
> ..]
> 
> 
> 
> I created an “infinet.pm” based on “mrv.pm”, made an addition to the
> “router.db” and now I can see when “rancid-run” is called that the system
> connects out 4 times to the InfiNet device (tcpdump helped here) but in the
> log file for the run I keep seeing :
> 
> 
> 
> 10.12.25.208 <http://10.126.254.208/>: missed cmd(s): all commands
> 
> 10.12.25.208 <http://10.126.254.208/>: End of run not found
> 
> 
> 
> >From what I have read it would seem that my issue lies with the “inloop”
> within my “infinet.pm” file, but cannot get to grips with what needs to be
> there, or if the “$prompt” hacks I made in “infilogin” are coming back to
> bite me now. If anyone can point me in the right direction I will be very
> grateful.
> 
> 
> 
> Thank you for taking the time to read this and for supporting this great
> tool. (By that I mean RANCID not that I am a tool . . but now I come to
> mention it)
> 
> DeeTee

> _______________________________________________
> Rancid-discuss mailing list
> Rancid-discuss at www.shrubbery.net
> https://www.shrubbery.net/mailman/listinfo/rancid-discuss



More information about the Rancid-discuss mailing list