Closed Nyanyah closed 8 years ago
Hey \n
is linefeed
and \r
is carriage return
, you want either \n
or \r\n
Your method of testing 2nd model is fine. Done right that should work. You can also put custom models in ~/.config/model/file.rb.
You don't need mapping if file.rb has same class name as model you're going to use.
What exactly went wrong, is hard to say without seeing your model, your mapping and your router.db.
Thanks, I'm stupid. I did try that but with '\n' instead of "\n", that's why it wasn't working.
Now oxidized is going further in the fetching, but there is still a problem. It seems that display-current-configuration has pagers in it : it stucks at ---- More ----. I tried to add in the cmd 'display current-configuration section : expect /More ----/ do send "\n" "" end But it didn't work, an ideas ?
Edit: got it.. had to put it in the beginning of the file with the other pager. Now it still fails with execution expired error Thanks.
Is there a way to extend the execution timer maybe ? I don't think it can be a pager problem like in this thread https://github.com/ytti/oxidized/issues/158, because the last thing seen in shellopen is " ---- More ----"_ and the expect for this pager worked for the previous More . I also checked in the switch, and it wasn't any different. Also, the error always appear in a specific line in the display configuration.
For the second question (adding new models) : Thanks, it is working, I forgot to also edit the name of the class in my new file.db model file... sorry for using your time.
You need to have your expect
statements in the main level, not inside cmd
There is timeout
value in config you can change. But usually it times out because we're waiting for prompt which we don't see.
Well I really don't know then... It's really exactly the same lines as the previous ones so the pager should be working. And oxidized doesn't "freeze" (spamming 1 jobs running in parallel) like when I had undetected prompt problems with other switches, it instantly raises the timeout error.
I tried to change the timeout value in config.rb and it didn't change anything (also tried to change the timeout value I saw in exec.rb since I didn't know what it was, but same result).
Main problem is that this switch doesn't have a screen-length disable command, that would solve it actually.
I don't know... It can't be that the pager is being used too much, can it ? Sounds stupid but I don't know what to think anymore.
There is timeout value in your ~/.config/oxidized/config
file.
If you can give remote access to sanitised device, I can try to take a look. Information I need
My IP address would be 91.198.120.1. If this is acceptable, you can provide me details via email to saku@ytti.fi
Okay I didn't know it was this timeout I had to change. It was indeed the problem : the configuration was too long et all those pagers slowed it down. I had to put it to 120 for it to work (even 100 was too short ). I don't know if it will cause some problems later but at least the problem is solved for now.
Thanks a whole lot for your help.
Another problem appeared though... Now in the web interface, the configuration only shows the result from display version and display device.
Does it actually take you 120s to do manually? If not, then something is wrong in model or oxidized.
The other problem sounds like you may have desynchronisation on prompt detection. Commonly cause by not eating prompt in correct order in correct place. Can I see the model you have now?
Sorry, forgot. The model is 3com 5500G-EI
I just tried and it took me around 80s* by spamming my enter key (haven't tried with just holding it yet).
Edit : worth noting that the documentation for this model claims that the screen-length option exists, but it doesn't in my switch. Also, I would gladly give you the logins of the switch but unfortunately cannot, it is a production one.
Sorry I didn't completely understand your last reply. What do you mean by "not eating prompt in correct order in correct place" please ?
Regards.
Can I see the model you're working on, if the issue exists there, it's easier to explain after I see it.
As I said earlier, that's not possible.
Thanks anyway, appreciate the help.
Earlier I asked access to the device. Now I'm just asking to see the model you're working on, the model file.
Sorry I misunderstood. Here's the content of my model.rb (named comwaredems.rb) file (it's the default comware.rb file with the two pagers added, I didn't change anything else) :
class Comwaredems < Oxidized::Model
# HP (A-series)/H3C/3Com Comware
# sometimes the prompt might have a leading nul
prompt /^\0*(<[\w.-]+>)$/
comment '# '
# example how to handle pager
#expect /^\s*---- More ----$/ do |data, re|
# send ' '
# data.sub re, ''
#end
expect /login$/ do
send "\n"
""
end
expect /^\s*---- More ----$/ do
send "\n"
""
end
cmd :all do |cfg|
#cfg.gsub! /^.*\e\[42D/, '' # example how to handle pager
#skip rogue ^M
cfg = cfg.gsub /\r/, ''
cfg.each_line.to_a[1..-2].join
end
cfg :telnet do
username /^Username:$/
password /^Password:$/
end
cfg :telnet, :ssh do
# enable command-line mode on SMB comware switches (HP V1910, V1920)
# autodetection is hard, because the 'summary' command is paged, and
# the pager cannot be disabled before _cmdline-mode on.
if vars :comware_cmdline
post_login do
send "_cmdline-mode on\n"
send "y\n"
send vars(:comware_cmdline) + "\n"
end
end
post_login 'screen-length disable'
post_login 'undo terminal monitor'
pre_logout 'quit'
end
cmd 'display version' do |cfg|
cfg = cfg.each_line.select {|l| not l.match /uptime/i }.join
comment cfg
end
cmd 'display device' do |cfg|
comment cfg
end
cmd 'display current-configuration' do |cfg|
cfg
end
end
Here's the banner of the model :
********************************************************************************
* Copyright(c) 2004-2012 3Com Corp. and its licensors. All rights reserved. *
* Without the owner's prior written consent, *
* no decompiling or reverse-engineering shall be allowed. *
********************************************************************************
<rtr_source>
%Aug 8 14:03:09:040 2016 rtr_source SHELL/5/LOGIN:- 1 - admin(10.1.8.226) in un it1 login
rtr_source is the name of the switch. It's a 3COM 5500G-EI.
Thanks a lot.
For example this is probably broken:
if vars :comware_cmdline
post_login do
send "_cmdline-mode on\n"
send "y\n"
send vars(:comware_cmdline) + "\n"
end
end
After send vars(:compare_cmdline) + "\n"
does the device output a prompt? If so, we're not consuming it. send
does not wait for prompt, it blindly sends data. cmd
waits for prompt.
So now after that line of code has been executed, we have 'spurious' prompt left unconsumed. So then we'll move to do some cmd 'something'
, this will immediately see the prompt, without registering any data! And as it will also produce prompt, the nexdt cmd 'somethin_else'
will consume that prompt and so forth.
When making be mindful when output is producing prompt, if output is producing prompt, you must consume it. Specifically use cmd
instead of send
when output of said command will contain prompt.
Thank you for the detailed explanation. I will update when I'll get it to work (can't work on it right now).
I tried using cmd instead of send but it didn't help. The timeout problem was fixed by using the spacebar instead of \n at the pagers.
We have the same problem as before, but now it displays the result of display version, device, and then the last 3 lines of current-configuration.
It seems that this line is causing the problems :
D, [2016-08-25T13:08:11.377221 #14119] DEBUG -- : shell_open: " ---- More ----"
D, [2016-08-25T13:08:11.580831 #14119] DEBUG -- : shell_open: "\e[42D \e[42D"
We tried to uncomment the #cfg.gsub! /^.*\e\[42D/, ''
line but it didn't work : it is still here in the debug lines after each "More".
Sometimes getting model to work may be tricky, debug, troubleshoot, add debugging stuff to ssh.rb. Giving specific instructions remotely quickly becomes very inefficient if solution isn't obvious, and it is not obvious here.
I would help, but I understand that you are not able to produce sanitised version of device online. So best I can say is stick to it and add debugging information :/
Yeah I understand.Thanks a lot for the help already, I got really far thanks to you. I will keep searching to make it work.
Well this is awkward. My pager part in the file wasn't good. I didn't see the default commented one and this one works... So sorry for losing time. Can close this.
Great to hear you got it working!
Hello, I've got exactly the same issue with all the products running comware 3 (5500, 4210, etc) . I don't understand how you solve it ? Could you explain me more ? I don't understand how the "prompt command" works (prompt /^\0*(<[\w.-]+>)$/)
thank you
Hello,
It appears that some comware switches have a pager that requires to press the enter key (and not any key). I really searched hard but didn't find a way to send the enter key in the send command. Would really appreciate some help.
My second question is about adding new models in the db files. I have some switches from the same model that behaves weirdly (different banners), and have created a specfic model.db file for them, but I don't know how to impletement them in oxidized ? I tried to just put the db file in /var/lib/gems/2.1.0/gems/oxidized-0.16.2/lib/oxidized/model/ , added the model mapping in the config file and put the model in the router.db file, but it didn't work (undefined method 'new' for nil:Nilclass etc). Am I missing something here ?
Thanks.