Closed kalamchi75 closed 4 years ago
Oct 04 09:48:06 oxidized oxidized[21215]: W, [2019-10-04T09:48:06.645771 #21215] WARN -- : XX.XX.XX.XX raised Oxidized::PromptUndetect with msg "unable to detect prompt: (?-mix:[\w+@\s+(\s?\s+)*]\s?>\s?$)"
How does your device prompt look? Compared to: https://github.com/ytti/oxidized/blob/a6a6597dbbd019914806e4f13231b097909cd2dc/lib/oxidized/model/routeros.rb#L2
You can test here: https://rubular.com/
Hi Dave,
Honestly, not sure what that prompt means. I have copied the code in routeros.rb from your reply (I guess that's the default one with Oxidized) and my test Mikrotiks now one shows timeout and the second still complains about the prompt:
Oct 07 14:45:56 oxidized oxidized[6700]: W, [2019-10-07T14:45:56.429367 #6700] WARN -- : xx.xx.xx.xx raised Net::ReadTimeout (rescued Timeout::Error) with msg "timed out while waiting for more data" Oct 07 14:45:57 oxidized oxidized[6700]: W, [2019-10-07T14:45:57.133427 #6700] WARN -- : /router28.xx.xx.xx status no_connection, retry attempt 2 Oct 07 14:50:06 oxidized oxidized[6700]: W, [2019-10-07T14:50:06.218399 #6700] WARN -- : xx.xx.xx.xx raised Oxidized::PromptUndetect with msg "unable to detect prompt: (?-mix:\[\w+@\S+(\s+\S+)*\]\s?>\s?$)" Oct 07 14:50:07 oxidized oxidized[6700]: W, [2019-10-07T14:50:07.179948 #6700] WARN -- : /router03.xx.xx.xx status no_connection, retry attempt 3
However, if I test with: prompt /((config >))*/
Oxidized seems to connect to the routers, but no configs are shown. It just shows an empty page.
Is this prompt something I can find in the Mikrotik themselves ? Not sure where to look.
Do you have any tested/working routeros.rb please ?
Thanks
@kalamchi75 the prompt
is the string you see when you ssh/telnet into a device.
myroutername# <humantypingstartshere>
the prompt here in the model https://github.com/ytti/oxidized/blob/a6a6597dbbd019914806e4f13231b097909cd2dc/lib/oxidized/model/routeros.rb#L2
should match the prompt you see on your device. If it does not match, then oxidized will not continue.
So when you access the device from the command line, how does it look?
Do you have any tested/working routeros.rb please ?
no, dont use that oxidized model
Hi,
That's how it looks when I telnet :
`
MMMM MMMM KKK TTTTTTTTTTT KKK MMM MMMM MMM III KKK KKK RRRRRR OOOOOO TTT III KKK KKK MMM MM MMM III KKKKK RRR RRR OOO OOO TTT III KKKKK MMM MMM III KKK KKK RRRRRR OOO OOO TTT III KKK KKK MMM MMM III KKK KKK RRR RRR OOOOOO TTT III KKK KKK
MikroTik RouterOS 6.18 (c) 1999-2014 http://www.mikrotik.com/
[?] Gives the list of available commands command [?] Gives help on the command and list of arguments
[Tab] Completes the command/word. If the input is ambiguous, a second [Tab] gives possible options
/ Move up to base level .. Move up one level /command Use command at the base level `
where's the prompt?
something like <string>#
or string>
Where you type your commands?
[network@RAI-RTR-ROUTERxx] >
It seems that regex matches the prompt. Not sure why the nodes won't connect with it.
It could be all that other stuff that precedes your prompt that is causing "unable to detect prompt" log...
Run oxidized in debug mode, see if any interesting logs.
Maybe a way to remove all those remarks at login?
Hi Dave,
I think those remarks are Mikrotik default. Not sure if they can be removed, but I can check with our network guys if they know how to remove them. However, what I noticed was if I change that prompt matching in the script to smth like /\w+/ oxidized seem to connect to the routers and their status become green, and it reports some details about the version and so, but no actual configs are being retrieved, and the config tab shows an empty page. Can't really figure out why this is happening as I have zero experience in Ruby :)
Hi Guys,
Any solution for this please ? i'm still getting prompt issue with Mikrotik, and not sure how to solve it:
The two INFO lines are for two Cisco routers that are backed up successfully. The WARN lines are for two Mikrotik routers which still cannot pass the prompt.
If anybody has a tested/working Mikrotik routersos.rb file, kindly share.
thanks
Alright, after some fiddling with routeros.rb code, my colleague was able to get the Mikrotik configs retrieved into Oxidized. Below is the running code, sharing it if anybody faces the same issue:
class RouterOS < Oxidized::Model
prompt /\[\w+@\S+(\s+\S+)*\]\s?>\s?$/
comment "# "
cmd :all do |cfg|
cfg.gsub! /\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[m|K]/, '' # strip ANSI colours
if screenscrape
cfg = cfg.cut_both
cfg.gsub! /^\r+(.+)/, '\1'
cfg.gsub! /([^\r]*)\r+$/, '\1'
end
cfg
end
cmd 'system routerboard print' do |cfg|
comment cfg
end
post do
run_cmd = vars(:remove_secret) ? 'export hide-sensitive' : 'export'
cmd run_cmd do |cfg|
cfg.gsub! /\\\r?\n\s+/, '' # strip new line
cfg = cfg.split("\n").reject { |line| line[/^#\s\w{3}\/\d{2}\/\d{4}.*$/] }
cfg.join("\n") + "\n"
end
end
cfg :telnet do
username /^Login:/
password /^Password:/
end
cfg :telnet, :ssh do
pre_logout 'quit'
end
cfg :ssh do
exec true
end
end
Attached is the .rb file routeros.zip
Hi Guys,
I have installed an oxidized server on Ubuntu 18.04 LTS, and integrated it in LibreNMS. Cisco routers/switches are working fine, backing up configs, and showing versions when changes are made. However, i'm hitting an issue with Mikrotik routers.
Below is the error i'm getting regarding the prompt:
`oxidized.service - Oxidized - Network Device Configuration Backup Tool Loaded: loaded (/lib/systemd/system/oxidized.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2019-10-04 09:47:42 CEST; 28s ago Main PID: 21215 (oxidized) Tasks: 9 (limit: 4915) CGroup: /system.slice/oxidized.service └─21215 puma 3.11.4 (tcp://0.0.0.0:8888) [/]
Oct 04 09:47:42 oxidized oxidized[21215]: I, [2019-10-04T09:47:42.337382 #21215] INFO -- : lib/oxidized/nodes.rb: Loading nodes Oct 04 09:47:42 oxidized oxidized[21215]: I, [2019-10-04T09:47:42.364530 #21215] INFO -- : lib/oxidized/nodes.rb: Loaded 4 nodes Oct 04 09:47:42 oxidized oxidized[21215]: Puma starting in single mode... Oct 04 09:47:42 oxidized oxidized[21215]: Version 3.11.4 (ruby 2.5.1-p57), codename: Love Song Oct 04 09:47:42 oxidized oxidized[21215]: Min threads: 0, max threads: 16 Oct 04 09:47:42 oxidized oxidized[21215]: Environment: development Oct 04 09:47:42 oxidized oxidized[21215]: Listening on tcp://0.0.0.0:8888 Oct 04 09:47:42 oxidized oxidized[21215]: Use Ctrl-C to stop Oct 04 09:48:06 oxidized oxidized[21215]: W, [2019-10-04T09:48:06.645771 #21215] WARN -- : XX.XX.XX.XX raised *Oxidized::PromptUndetect with msg "unable to detect prompt: (?-mix:[\w+@\s+(\s?\s+)]\s?>\s?$)"** Oct 04 09:48:07 oxidized oxidized[21215]: W, [2019-10-04T09:48:07.567792 #21215] WARN -- : /router28.xx.xx status no_connection, retry attempt 1`
And below is my routeros.rb file (hashed prompts were added when I was trying different solutions I could find on forums):
`class RouterOS < Oxidized::Model prompt /[\w+@\s+(\s?\s+)*]\s?>\s?$/
prompt /^[\w.@-]+> ((enable) )?$/
prompt /((config >))*/
comment "# "
cmd '/system routerboard print' do |cfg| comment cfg end
cmd '/system package update print' do |cfg| comment cfg end
cmd '/system history print' do |cfg| comment cfg end
post do run_cmd = vars(:remove_secret) ? '/export hide-sensitive' : '/export' cmd run_cmd do |cfg| cfg.gsub! /\x1B[([0-9]{1,3}((;[0-9]{1,3}))?)?[m|K]/, '' # strip ANSI colours cfg.gsub! /\\r\n\s+/, '' # strip new line cfg.gsub! /# inactive time\r\n/, '' # Remove time based system comment cfg = cfg.split("\n").reject { |line| line[/^#\s\w{3}\/\d{2}\/\d{4}.$/] } cfg.join("\n") + "\n" end end
cfg :telnet do username /^Login:/ password /^Password:/ end
cfg :telnet, :ssh do pre_logout 'quit' end
cfg :ssh do exec true end end`
If I change the prompt to *prompt /((config >))/** , oxidized seems to connect to the router and show its status as up, but the config is not retrieved and shows empty page.
I was wondering if anybody has a working/tested routeros.rb file that can be shared.
Below is my oxidized version: oxidized -v 0.26.3
Below is my config file:
`--- username: someUSER password: "somePASSWORD" model: junos resolve_dns: true interval: 300 use_syslog: false debug: false threads: 30 timeout: 20 retries: 3 prompt: !ruby/regexp /^([\w.@-]+[#>]\s?)$/ rest: 0.0.0.0:8888 next_adds_job: false vars: {} groups: {} models: {} pid: "/home/oxidized/.config/oxidized/pid" crash: directory: "/home/oxidized/.config/oxidized/crashes" hostnames: false stats: history_size: 10 input: default: telnet debug: false
ssh:
secure: false
ftp:
passive: true
utf8_encoded: true
output:
default: file
file:
directory: "/home/oxidized/.config/oxidized/configs"
output: default: git git: user: oxidized email: o@example.com repo: "/home/oxidized/.config/oxidized/configs/devices.git" source: default: csv csv: file: "/home/oxidized/.config/oxidized/router.db" delimiter: !ruby/regexp /:/ map: name: 0 model: 1 gpg: false model_map: juniper: junos cisco: ios mikrotik: routeros`
Kindly advise how to get Mikrotik configs.
Thanks