Skip to content

Commit

Permalink
fix: Use timeout not only for snmp during netscan
Browse files Browse the repository at this point in the history
Renamed 'SNMP timeout' to 'Connection timeout' in ToolBox
Add connection timeout support for ESX task, ssh & winrm RemoteInventory tasks
  • Loading branch information
g-bougard committed Oct 9, 2023
1 parent 57bdbf6 commit f288d0b
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/GLPI/Agent/HTTP/Server/ToolBox/Inventory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ sub yaml_config_specs {
timeout_options => {
category => "Network task",
type => $self->isyes($yaml_config->{'updating_support'}) ? "text" : "readonly",
value => $yaml_config->{'timeout_options'} || '1|10|30|60',
text => "Network task SNMP timeout options",
tips => "SNMP timeout options separated by pipes,\nfirst value used as default timeout\n(default=1|10|30|60)",
value => $yaml_config->{'timeout_options'} || '1|2|5|10|30|60',
text => "Network task timeout options",
tips => "Timeout options separated by pipes,\nfirst value used as default timeout\n(default=1|2|5|10|30|60)",
},
networktask_save => {
category => "Network task",
Expand Down
9 changes: 9 additions & 0 deletions lib/GLPI/Agent/Task/ESX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ sub run {
$self->{client} = GLPI::Agent::HTTP::Client::Fusion->new(
logger => $self->{logger},
config => $self->{config},
timeout => $self->timeout(),
);
die unless $self->{client};

Expand Down Expand Up @@ -332,6 +333,14 @@ sub lastError {
return $self->{lastError} || "n/a";
}

sub timeout {
my ($self, $timeout) = @_;

$self->{_timeout} = $timeout if defined($timeout);

return $self->{_timeout} || $self->{config}->{"backend-collect-timeout"} // 60;
}

1;

__END__
Expand Down
2 changes: 2 additions & 0 deletions lib/GLPI/Agent/Task/NetDiscovery.pm
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ sub _scanAddressByRemote {
GLPI::Agent::Task::ESX->require();

my $esxscan = GLPI::Agent::Task::ESX->new(%params);
$esxscan->timeout($params->{timeout});

if ($esxscan->connect(
host => $params->{ip},
Expand Down Expand Up @@ -981,6 +982,7 @@ sub _scanAddressByRemote {
my $remote = GLPI::Agent::Task::RemoteInventory::Remote->new(
logger => $self->{logger},
url => $url->as_string(),
timeout => $params->{timeout},
);
next unless $remote->supported();

Expand Down
9 changes: 9 additions & 0 deletions lib/GLPI/Agent/Task/RemoteInventory/Remote.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sub new {
_user => $ENV{USERNAME},
_pass => $ENV{PASSWORD},
_modes => {},
_timeout => $params{timeout} // 0,
logger => $params{logger},
};

Expand Down Expand Up @@ -202,6 +203,14 @@ sub protocol {
return $self->{_protocol};
}

sub timeout {
my ($self, $timeout) = @_;

$self->{_timeout} = $timeout if defined($timeout);

return $self->{_timeout} || $self->config->{"backend-collect-timeout"} // 60;
}

sub expiration {
my ($self, $timeout) = @_;

Expand Down
3 changes: 2 additions & 1 deletion lib/GLPI/Agent/Task/RemoteInventory/Remote/Ssh.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ sub _ssh {
my @command = qw(ssh -q -o BatchMode=yes);
push @command, "-p", $self->port() if $self->port() && $self->port() != 22;
push @command, "-l", $self->user() if $self->user();
push @command, "-o ConnectionTimeout=".$self->timeout() if $self->timeout();

return @command, $self->host(), "LANG=C";
}
Expand All @@ -48,7 +49,7 @@ sub _connect {
if ($EVAL_ERROR) {
$self->{logger}->debug("Can't use libssh2: $EVAL_ERROR");
} else {
my $timeout = $self->config->{"backend-collect-timeout"} // 60;
my $timeout = $self->timeout();
$self->{_ssh2} = Net::SSH2->new(timeout => $timeout * 1000);
my $version = $self->{_ssh2}->version;
$self->{logger}->debug2("Using libssh2 $version for ssh remote")
Expand Down
1 change: 1 addition & 0 deletions lib/GLPI/Agent/Task/RemoteInventory/Remote/Winrm.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ sub prepare {
url => $self->{_canonical_url},
user => $self->user(),
password => $self->pass(),
timeout => $self->timeout(),
winrm => 1,
);
}
Expand Down
2 changes: 1 addition & 1 deletion share/html/toolbox/inventory-edit.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
</div>
<div class='form-edit-row' id='netscan-options-3' style='display: {$type ne "local" ? "flex" : "none"}'>
<div class='form-edit'>
<label for='timeout'>{_"SNMP Timeout"}</label>
<label for='timeout'>{_"Connection timeout"}</label>
<select id='timeout' name='input/timeout' class='run-options'{$type ne "local" ? "" : " disabled"}>{
foreach my $opt (@timeout_options) {
$OUT .= "
Expand Down
2 changes: 1 addition & 1 deletion share/html/toolbox/inventory-language-en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Network scan:
Choose IP range:
Options:
Threads:
SNMP Timeout:
Connection timeout:
Run network scan:
Inventory tag:
Use a tag:
Expand Down
2 changes: 1 addition & 1 deletion share/html/toolbox/inventory-language-fr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Network scan: Scan réseau
Choose IP range: Sélectionner la plage IP

Threads: Nombre de processus
SNMP Timeout: Délai max de non réponse SNMP
Connection timeout: Délai d'expiration de connexion
Run network scan: Lancer un scan réseau
Inventory tag: Tag d'inventaire
Use a tag: Utiliser un tag
Expand Down

0 comments on commit f288d0b

Please sign in to comment.