Mailing List Archive

DLink and End of Run Found
I have a bunch of old DLinks and have been working to find a way to monitor changes. I saw some past mail list notes on DLInk's, and I see the DLLOGIN and Dell.pm modules, that have some support.

I could not get them to work in any straightforward way, so I spent a bit of time changing them, ending up splitting into two variations (e.g. " show running-config" (I used the type "mydlink" for those) vs "show config current_config" (I used dell) seemed a good dividing line). Lots of little stuff, disabling paging had different commands, even exit vs logout.

I got them to work with a ton of kludges, and feel like I may have just missed something, as there are enough old DLinks out there I would expect a lot more chatter if they did not work.

Was I missing something?

For context, I'm attaching the patches I did. Caveat -- I have ONLY old DLINk's, so I may well have broken it for newer ones, and I am not suggesting these as corrections to the real rancid, but rather in case someone notices the issues and tells me the "right" way to fix it, or where the better support may already be in there.

What bothered me about these most were minor things that were hard to fathom, like anchors at line end that wouldn't work as prompts almost all had a trailing space, or some prompts with escape sequences in them (I just hard coded removal of one such). It made me think there was no way these routines could work with these switches, so either there are other modules, or... well, as I said these are really old.

I think spacing is a bit confused in these from tab expansion. This is against 3.7.

Anyway... some code if it's ever useful to anyone, and I would welcome if there are better ways. I'm an awful perl programmer, in addition.

Linwood


$ diff -u /home/lferguson/rancid-3.7/lib/dell.pm lib/rancid/dell.pm
--- /home/lferguson/rancid-3.7/lib/dell.pm 2018-03-03 20:30:16.689052000 -0600
+++ lib/rancid/dell.pm 2018-04-08 19:37:44.435813129 -0500
@@ -108,8 +108,9 @@

TOP: while(<$INPUT>) {
tr/\015//d;
- # XXX this match is not correct for DELL
- if (/[>#]\s?exit$/) {
+ # XXX this match is not correct for DELL
+ ### LEF Patch add logout, and add colon
+ if ( (/[:>#]\s?(exit|logout)/) || (scalar(keys %commands) == 0) ) { ### LEF Patch - sometims logout doesn't show the final prompt+command, so just quit if all commands done
$clean_run = 1;
last;
}
@@ -119,12 +120,10 @@
$clean_run = 0;
last;
}
- while (/^.+(#|\$)\s*($cmds_regexp)\s*$/) {
- $cmd = $2;
- # - D-Link prompts end with '#'.
- if ($_ =~ m/^.+#/) {
- $prompt = '.+#.*';
- }
+ while (/^(.+(#|\$)\s*)($cmds_regexp)\s*$/) { ## LEF patch grab full prompt at same time (next two lines differ also) and get rid of garbage some switches add
+ $cmd = $3;
+ $prompt = $1;
+ $prompt =~ s/\x1b\x5b\x4b//d;
print STDERR ("HIT COMMAND:$_") if ($debug);
if (! defined($commands{$cmd})) {
print STDERR "$host: found unexpected command - \"$cmd\"\n";
@@ -145,6 +144,7 @@
}
}
}
+ return 0; ## LEF Patch - there were cases where this exited and caused an error and failure of the file, added 0 return
}

# This routine parses "get system"
@@ -156,8 +156,9 @@
tr/\015//d;
next if /^\s*$/;
last if (/$prompt/);
-
- next if (/^system up time:/i);
+ ## LEF Patch - don't require it be tied to start of line (some have # prefi), and do two differet spelling of up/time.
+ next if (/system up time/i);
+ next if (/system uptime/i);
#next if (/^\s*Virus-DB: .*/);
#next if (/^\s*Extended DB: .*/);
#next if (/^\s*IPS-DB: .*/);
@@ -188,7 +189,7 @@
tr/\015//d;
next if /^\s*$/;
last if (/$prompt/);
-
+ last if (/Connection\ closed/);
# filter variabilities between configurations. password encryption
# upon each display of the configuration.
#if (/^\s*(set [^\s]*)\s(Enc\s[^\s]+)(.*)/i && $filter_pwds > 0 ) {

$ diff -u /home/lferguson/rancid-3.7/bin/dllogin bin/dllogin --ignore-all-space
--- /home/lferguson/rancid-3.7/bin/dllogin 2018-03-03 20:30:08.365052000 -0600
+++ bin/dllogin 2018-04-08 18:47:44.971940858 -0500
@@ -550,7 +550,7 @@
send_user "\nError: Check your passwd for $router\n";
catch {close}; catch {wait}; return 1
}
- -re "\[Uu]ser\[nN]ame:" {
+ -re "\[Uu]ser\[ ]?\[nN]ame:" {
sleep 1;
send -- "$user\r"
set uprompt_seen 1
@@ -585,7 +585,9 @@
# Disable output paging.
send -- "disable clipaging\r"
expect -re $prompt;
-
+ ### LEF patch - older DLinks use this instead (errors just get ignored in this section so just send both)
+ send -- "terminal datadump\n"
+ expect -re $prompt;
# handle escaped ;s in commands, and ;; and ^;
regsub -all {([^\\]);;} $command "\\1;\u002;" esccommand
regsub {^;} $esccommand "\u002;" command
@@ -594,6 +596,7 @@
set sep "\u001"
set commands [split $esccommand $sep]
set num_commands [llength $commands]
+
for {set i 0} {$i < $num_commands} { incr i} {
send -- "[subst [lindex $commands $i]]\r"
# send_user "**************** [subst [lindex $commands $i]] ************\n"
@@ -609,9 +612,11 @@
}
# send_user "******* fuori da ciclo for *******\n"
expect {
- -re "$prompt$" {
+ -re "$prompt" { ## LEF Patch - this was previously just logout but some dlinks require exit (or maybe it was vice versa), just send both in case
send "logout\r"
sleep 0.5
+ send "exit\r"
+ sleep 0.5
exp_continue
}
-re "\[\n\r]+" { exp_continue }

$ diff -u /home/lferguson/rancid-3.7/etc/rancid.types.conf etc/rancid.types.conf
--- /home/lferguson/rancid-3.7/etc/rancid.types.conf 2016-10-31 12:42:00.000000000 -0500
+++ etc/rancid.types.conf 2018-04-07 20:34:11.284974936 -0500
@@ -35,6 +35,15 @@
# save copies in rancid of configs from /tftpboot
tftpcopy;script;rtftpcopy
#
+#based on DELL (which kind of works for DLink) but for some older DLinks
+mydlink;script;rancid -t mydlink
+mydlink;login;dllogin
+mydlink;timeout;300
+mydlink;module;dell
+mydlink;inloop;dell::inloop
+mydlink;command;dell::GetSystem;show system
+mydlink;command;dell::GetConf;show running-config
+#