mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-23 05:35:01 +02:00
(plugin) apps::pvx::restapi - add default-value parameter (#3485)
* add default-value parameter * + fix after review
This commit is contained in:
parent
63029b9585
commit
c3e073409b
@ -44,18 +44,19 @@ sub new {
|
||||
|
||||
if (!defined($options{noptions})) {
|
||||
$options{options}->add_options(arguments => {
|
||||
'api-key:s' => { name => 'api_key' },
|
||||
'hostname:s' => { name => 'hostname' },
|
||||
'url-path:s' => { name => 'url_path' },
|
||||
'port:s' => { name => 'port' },
|
||||
'proto:s' => { name => 'proto' },
|
||||
'credentials' => { name => 'credentials' },
|
||||
'basic' => { name => 'basic' },
|
||||
'username:s' => { name => 'username' },
|
||||
'password:s' => { name => 'password' },
|
||||
'timeout:s' => { name => 'timeout', default => 10 },
|
||||
'timeframe:s' => { name => 'timeframe' },
|
||||
'timezone:s' => { name => 'timezone', default => 'UTC' }
|
||||
'api-key:s' => { name => 'api_key' },
|
||||
'default-value:s' => { name => 'default_value' },
|
||||
'hostname:s' => { name => 'hostname' },
|
||||
'url-path:s' => { name => 'url_path' },
|
||||
'port:s' => { name => 'port' },
|
||||
'proto:s' => { name => 'proto' },
|
||||
'credentials' => { name => 'credentials' },
|
||||
'basic' => { name => 'basic' },
|
||||
'username:s' => { name => 'username' },
|
||||
'password:s' => { name => 'password' },
|
||||
'timeout:s' => { name => 'timeout', default => 10 },
|
||||
'timeframe:s' => { name => 'timeframe' },
|
||||
'timezone:s' => { name => 'timezone', default => 'UTC' }
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
|
||||
@ -166,6 +167,12 @@ sub query_range {
|
||||
|
||||
my $result = $self->get_endpoint(url_path => '/query?expr=' . $uri->encode($query));
|
||||
|
||||
if (defined( $self->{option_results}->{default_value} ) && $options{filter} ne '' && !exists( $result->{data} )) {
|
||||
$options{filter} =~ /([^\s\\]+) = \"([^\s\\]+)\"/;
|
||||
push @{$result->{data}->{key}}, { value => $2 };
|
||||
push @{$result->{data}->{values}}, { value => $self->{option_results}->{default_value} };
|
||||
}
|
||||
|
||||
return $result->{data};
|
||||
}
|
||||
|
||||
@ -208,6 +215,10 @@ PVX Rest API custom mode
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--default-value>
|
||||
|
||||
Set a default value when nothing returned by PVX API
|
||||
|
||||
=item B<--timeframe>
|
||||
|
||||
Set timeframe in seconds (i.e. 3600 to check last hour).
|
||||
|
Loading…
x
Reference in New Issue
Block a user