haussli / rancid

RANCiD
Other
114 stars 42 forks source link

Ubiquiti devices seeing oscillating config change (config parsing error I think) #15

Closed morrowc closed 2 years ago

morrowc commented 3 years ago

I monitor 2 ubiquiti devices (edgerouters), I see the same behavior for both of them, occasionally I see diffs like:


  #RANCID-CONTENT-TYPE: edgerouter                                                                                                     
  #                                                                                                                                    
- #Version:      v2.0.8-hotfix.1                                                                                                       
+ #show hardware cpu^JVersion:      v2.0.8-hotfix.1                                                                                    
  #Build ID:     5278088                                                                                                               
  #Build on:     03/05/20 16:41                                                                                                        
  #HW model:     EdgeRouter X 5-Port                                                                                                   
  #HW S/N:       F09FC26FF449                                                                                                          
  #                       

followed by a diff like:

  #RANCID-CONTENT-TYPE: edgerouter                                                                                                     
  #                                                                                                                                    
- #show hardware cpu^JVersion:      v2.0.8-hotfix.1                                                                                    
+ #Version:      v2.0.8-hotfix.1                                                                                                       
  #Build ID:     5278088                                                                                                               
  #Build on:     03/05/20 16:41                                                                                                        
  #HW model:     EdgeRouter X 5-Port                                                                                                   
  #HW S/N:       F09FC26FF449                                                                                                          
  #                    

I take this to mean that for the first diff 'Version' and 'show hardware' got stuck together on the same 'line', and on the subsequent run that stickiness did not happen. Ctrl-J is a linefeed (I think) character, perhaps: https://github.com/haussli/rancid/blob/0d25275f5c1ac14a43cecd5a139ef899f4e5a2f5/lib/edgerouter.pm.in#L41

adding a removal of \012 helps? :)

haussli commented 3 years ago

hey, i'm just seeing this PR - not rx'g notification of them. yes, ^J is LF. but your terminal ought to understand LF - so why is it appearing as ^J? Is that actually a single char in the diff or is it expanded to two? also, have you overridden prompt in your .cloginrc? ulogin -m

morrowc commented 2 years ago

first: I suck at github PR and markdown :( I did edit the first note in this to at least make the diff look proper.

you stated that: "your terminal ought to understand LF, why is it appearing as ^J?"

I think my terminal probably does the right thing, but these diffs I see via email...(admittedly in a terminal mail application)

then you asked: "have you overridden your .cloginrc?" I don't believe I changed the .cloginrc... related to terminal stuff:

$ more .cloginrc 
add password * blahrgh
add user * rancid
add method * {ssh}
add sshcommand {"/usr/bin/ssh -4"}
add identity * {"/var/lib/rancid/.ssh/id_ec_rancid"}
add cyphertype  gw.*     aes128-cbc
add cyphertype  srx-*   aes128-cbc
add cyphertype  fios.*   aes128-cbc
add noenable gate.ops-netman.net  1

ulogin -m output for one of the devices:

$ bin/ulogin -m gate.ops-netman.net
gate.ops-netman.net
noenable:/var/lib/rancid/.cloginrc:9: gate.ops-netman.net 1 
password:/var/lib/rancid/.cloginrc:1: * blahrgh 
user:/var/lib/rancid/.cloginrc:2: * rancid 
identity:/var/lib/rancid/.cloginrc:5: * {"/var/lib/rancid/.ssh/id_ec_rancid"} 
method:/var/lib/rancid/.cloginrc:3: * ssh 
haussli commented 2 years ago

The diff implies to me that the device re-printed the command after ulogin sent it. The script read the first one and filtered it, then read the re-print + the first line of the command's output. This usually occurs when the cli ties to be cute; usually it can be avoided with a 'dumb' terminal type. eg:

diff --git a/lib/edgerouter.pm.in b/lib/edgerouter.pm.in
index 6804d3b9..19b83304 100644
--- a/lib/edgerouter.pm.in
+++ b/lib/edgerouter.pm.in
@@ -21,6 +21,9 @@ use rancid @VERSION@;

 # load-time initialization
 sub import {
+    # force a terminal type to avoid cli mangling
+    $ENV{'TERM'} = "ansi";
+
     0;
 }

I only have access to a ugs, but i'll try to replicate this.

haussli commented 2 years ago

I've not been able to reproduce this with a USG over that past week. Have you been able to test the "TERM" theory?

haussli commented 2 years ago

Tried to reproduce this for multiple weeks w/o success. We assume it is something particular to morrowc's environment that has resolved itself through upgrades. Please open another PR if it recurs.