From dc832594fde18d49c9ffd5c2331ab448a0f49d8d Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 1 Aug 2016 15:49:30 +0200 Subject: [PATCH] + Add option for scenario telnet --- apps/protocols/telnet/mode/scenario.pm | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/apps/protocols/telnet/mode/scenario.pm b/apps/protocols/telnet/mode/scenario.pm index b3cd7f201..09e34a43a 100644 --- a/apps/protocols/telnet/mode/scenario.pm +++ b/apps/protocols/telnet/mode/scenario.pm @@ -39,6 +39,8 @@ sub new { "scenario:s" => { name => 'scenario' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port', default => 23 }, }); return $self; @@ -94,10 +96,18 @@ sub read_scenario { sub execute_scenario { my ($self, %options) = @_; + my $timing0 = [gettimeofday]; my $session = new Net::Telnet(); $session->errmode('return'); - my $timing0 = [gettimeofday]; + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + if (!$session->open(Host => $self->{option_results}->{hostname}, Port => $self->{option_results}->{port}, Timeout => 30)) { + $self->{output}->output_add(severity => 'critical', + short_msg => sprintf("cannot open session: %s", $session->errmsg())); + return ; + } + } + my ($step_ok, $exit1) = (0, 'OK'); my $step_total = scalar(@{$self->{json_scenario}}); foreach my $cmd (@{$self->{json_scenario}}) { @@ -161,12 +171,22 @@ Check telnet scenario execution =item B<--scenario> -Scenario used +Scenario used (Required) =item B<--timeout> Set global execution timeout (Default: 50) +=item B<--hostname> + +Set telnet hostname. +Could be used if you want to use the same scenario for X hosts. + +=item B<--port> + +Set telnet port. +Could be used if you want to use the same scenario for X hosts. + =item B<--warning> Threshold warning in seconds (Scenario execution time)