aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorKnut Auvor Grythe <knut@auvor.no>2015-04-01 01:21:15 +0200
committerroot <root@einstein.tg15.gathering.org>2015-04-01 01:21:15 +0200
commit8ce0c22a42189aa9411d26d1c5a320da919e1286 (patch)
tree44773a028e2e704b433b84d95004b5750c1046b9 /include
parent2c44d754c0f7693e414bf57148772b4bc8cc023b (diff)
Add support for #require-version and %SYSNAME% in smanagrun, UI fixes
Diffstat (limited to 'include')
-rwxr-xr-xinclude/nms.pm15
1 files changed, 12 insertions, 3 deletions
diff --git a/include/nms.pm b/include/nms.pm
index e532a05..1ade743 100755
--- a/include/nms.pm
+++ b/include/nms.pm
@@ -7,10 +7,11 @@ use Net::Telnet;
use Data::Dumper;
use FixedSNMP;
use FileHandle;
+use JSON;
package nms;
use base 'Exporter';
-our @EXPORT = qw(switch_disconnect switch_connect_ssh switch_connect_dlink switch_exec switch_timeout db_connect);
+our @EXPORT = qw(switch_disconnect switch_connect_ssh switch_connect_dlink switch_exec switch_exec_json switch_timeout db_connect);
BEGIN {
require "config.pm";
@@ -61,9 +62,10 @@ sub switch_connect_ssh($) {
#$inputlog->print("\n\nConnecting to " . $ip . "\n\n");
my $telnet = Net::Telnet->new(-fhopen => $pty,
+ -timeout => $nms::config::telnet_timeout,
-dump_log => $dumplog,
-input_log => $inputlog,
- -prompt => '/.*\@e\d\d-\d> /',
+ -prompt => '/.*\@e\d+-\d+[>#] /',
-telnetmode => 0,
-cmd_remove_mode => 1,
-output_record_separator => "\r");
@@ -131,7 +133,14 @@ sub switch_exec {
}
return @data;
}
-
+
+sub switch_exec_json($$) {
+ my ($cmd, $conn) = @_;
+ my @json = switch_exec("$cmd | display json", $conn);
+ pop @json; # Remove the banner at the end of the output
+ return ::decode_json(join("", @json));
+}
+
sub switch_timeout {
my ($timeout, $conn) = @_;