From 98c7fc45c983b9e424e32bc2f426e395e1ec98bc Mon Sep 17 00:00:00 2001 From: root Date: Tue, 7 Feb 2017 16:38:47 +0100 Subject: added tplink model --- lib/oxidized/model/tplink.rb | 65 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 lib/oxidized/model/tplink.rb (limited to 'lib/oxidized/model/tplink.rb') diff --git a/lib/oxidized/model/tplink.rb b/lib/oxidized/model/tplink.rb new file mode 100644 index 0000000..9286ea4 --- /dev/null +++ b/lib/oxidized/model/tplink.rb @@ -0,0 +1,65 @@ +class TPLink < Oxidized::Model + + # tp-link prompt + prompt /^\r?([\w.@()-]+[#>]\s?)$/ + comment '! ' + + # handle paging + # workaround for sometimes missing whitespaces with "\s?" + expect /Press\s?any\s?key\s?to\s?continue\s?\(Q\s?to\s?quit\)/ do |data, re| + send ' ' + data.sub re, '' + end + + # send carriage return because \n with the command is not enough + # checks if line ends with prompt >,# or \r,\nm otherwise send \r + expect /[^>#\r\n]$/ do |data, re| + send "\r" + data.sub re, '' + end + + cmd :all do |cfg| + # normalize linefeeds + cfg.gsub! /(\r|\r\n|\n\r)/,"\n" + # remove empty lines + cfg.each_line.reject { |line| line.match /^[\r\n\s\u0000#]+$/ }.join + end + + cmd :secret do |cfg| + cfg.gsub! /^(snmp-server community).*/, '\\1 ' + cfg.gsub! /secret (\d+) (\S+).*/, '