(plugin) apps::proxmox::ve::restapi - add filtering capabilities to s… (#3665)
This commit is contained in:
parent
4d9e3a8dfe
commit
a20e81ae00
|
@ -233,7 +233,7 @@ sub api_list_vms {
|
|||
Type => $type,
|
||||
Vmid => $vmid,
|
||||
Node => $vm->{node},
|
||||
Name => $vm->{name},
|
||||
Name => $vm->{name}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -255,7 +255,7 @@ sub api_list_nodes {
|
|||
foreach my $node (@{$list_nodes}) {
|
||||
$nodes->{$node->{id}} = {
|
||||
State => $node->{status},
|
||||
Name => $node->{node},
|
||||
Name => $node->{node}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -278,7 +278,7 @@ sub api_list_storages {
|
|||
$storages->{$storage->{id}} = {
|
||||
State => $storage->{status},
|
||||
Node => $storage->{node},
|
||||
Name => $storage->{storage},
|
||||
Name => $storage->{storage}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -310,16 +310,16 @@ sub cache_vms {
|
|||
sub cache_nodes {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $has_cache_file = $options{statefile}->read(statefile => 'cache_proxmox_node_'.$self->{hostname} . '_' . $self->{port});
|
||||
my $has_cache_file = $options{statefile}->read(statefile => 'cache_proxmox_node_' . $self->{hostname} . '_' . $self->{port});
|
||||
my $timestamp_cache = $options{statefile}->get(name => 'last_timestamp');
|
||||
my $nodes = $options{statefile}->get(name => 'nodes');
|
||||
if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($options{reload_cache_time})))) {
|
||||
$nodes = {};
|
||||
my $list_nodes = $self->internal_api_list_nodes();
|
||||
foreach my $node (@{$list_nodes}) {
|
||||
$nodes->{$node->{id}} = {
|
||||
$nodes->{ $node->{id} } = {
|
||||
State => $node->{status},
|
||||
Name => $node->{node},
|
||||
Name => $node->{node}
|
||||
};
|
||||
}
|
||||
$options{statefile}->write(data => $nodes);
|
||||
|
@ -331,7 +331,7 @@ sub cache_nodes {
|
|||
sub cache_storages {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $has_cache_file = $options{statefile}->read(statefile => 'cache_proxmox_storage_'.$self->{hostname} . '_' . $self->{port});
|
||||
my $has_cache_file = $options{statefile}->read(statefile => 'cache_proxmox_storage_' . $self->{hostname} . '_' . $self->{port});
|
||||
my $timestamp_cache = $options{statefile}->get(name => 'last_timestamp');
|
||||
my $storages = $options{statefile}->get(name => 'storages');
|
||||
if ($has_cache_file == 0 || !defined($timestamp_cache) || ((time() - $timestamp_cache) > (($options{reload_cache_time})))) {
|
||||
|
@ -340,7 +340,8 @@ sub cache_storages {
|
|||
foreach my $storage (@{$list_storages}) {
|
||||
$storages->{$storage->{id}} = {
|
||||
State => $storage->{status},
|
||||
Name => $storage->{storage},
|
||||
Node => $storage->{node},
|
||||
Name => $storage->{storage}
|
||||
};
|
||||
}
|
||||
$options{statefile}->write(data => $storages);
|
||||
|
@ -452,30 +453,42 @@ sub api_get_nodes {
|
|||
sub api_get_storages {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $content_total = $self->cache_storages(statefile => $options{statefile});
|
||||
my $storages = $self->cache_storages(statefile => $options{statefile});
|
||||
|
||||
if (defined($options{storage_id}) && $options{storage_id} ne '') {
|
||||
if (defined($content_total->{$options{storage_id}})) {
|
||||
$content_total->{$options{storage_id}}->{Stats} = $self->internal_api_get_storage_stats(storage_id => $options{storage_id});
|
||||
if (defined($storages->{ $options{storage_id} })) {
|
||||
$storages->{ $options{storage_id} }->{Stats} = $self->internal_api_get_storage_stats(storage_id => $options{storage_id});
|
||||
}
|
||||
} elsif (defined($options{storage_name}) && $options{storage_name} ne '') {
|
||||
my $storage_id;
|
||||
foreach (keys %{$content_total}) {
|
||||
if ($content_total->{$_}->{Name} eq $options{storage_name}) {
|
||||
$storage_id = $_;
|
||||
last;
|
||||
} elsif (defined($options{node_id}) && $options{node_id} ne '') {
|
||||
my $nodes = $self->cache_nodes(statefile => $options{statefile});
|
||||
foreach my $node_id (keys %$nodes) {
|
||||
if ($node_id eq $options{node_id}) {
|
||||
foreach my $storage_id (keys %$storages) {
|
||||
if ($storages->{$storage_id}->{Node} eq $nodes->{$node_id}->{Name}) {
|
||||
$storages->{$storage_id}->{Stats} = $self->internal_api_get_storage_stats(storage_id => $storage_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (defined($storage_id)) {
|
||||
$content_total->{$storage_id}->{Stats} = $self->internal_api_get_storage_stats(storage_id => $storage_id);
|
||||
} elsif (defined($options{node_name}) && $options{node_name} ne '') {
|
||||
foreach my $storage_id (keys %$storages) {
|
||||
if ($storages->{$storage_id}->{Node} eq $options{node_name}) {
|
||||
$storages->{$storage_id}->{Stats} = $self->internal_api_get_storage_stats(storage_id => $storage_id);
|
||||
}
|
||||
}
|
||||
} elsif (defined($options{storage_name}) && $options{storage_name} ne '') {
|
||||
foreach my $storage_id (keys %$storages) {
|
||||
if ($storages->{$storage_id}->{Name} eq $options{storage_name}) {
|
||||
$storages->{$storage_id}->{Stats} = $self->internal_api_get_storage_stats(storage_id => $storage_id);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach my $storage_id (keys %{$content_total}) {
|
||||
$content_total->{$storage_id}->{Stats} = $self->internal_api_get_storage_stats(storage_id => $storage_id);
|
||||
foreach my $storage_id (keys %$storages) {
|
||||
$storages->{$storage_id}->{Stats} = $self->internal_api_get_storage_stats(storage_id => $storage_id);
|
||||
}
|
||||
}
|
||||
|
||||
return $content_total;
|
||||
return $storages;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -25,7 +25,7 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -33,14 +33,6 @@ sub custom_status_output {
|
|||
return 'state : ' . $self->{result_values}->{state};
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
|
||||
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub custom_cpu_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -82,7 +74,7 @@ sub custom_memory_output {
|
|||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
|
||||
return sprintf(
|
||||
'Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
|
||||
'memory total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
|
||||
|
@ -132,7 +124,7 @@ sub custom_swap_output {
|
|||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
|
||||
return sprintf(
|
||||
'Swap Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
|
||||
'swap total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
|
||||
|
@ -182,7 +174,7 @@ sub custom_fs_output {
|
|||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
|
||||
return sprintf(
|
||||
'Root Filesystem Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
|
||||
'root filesystem total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
|
||||
|
@ -201,30 +193,35 @@ sub custom_fs_calc {
|
|||
return 0;
|
||||
}
|
||||
|
||||
sub prefix_nodes_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Node '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_nodes_output', message_multiple => 'All nodes are ok', skipped_code => { -10 => 1, -11 => 1 } },
|
||||
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_nodes_output', message_multiple => 'All nodes are ok', skipped_code => { -10 => 1, -11 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{nodes} = [
|
||||
{ label => 'node-status', threshold => 0, set => {
|
||||
{ label => 'node-status', type => 2, set => {
|
||||
key_values => [ { name => 'state' }, { name => 'name' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
{ label => 'cpu', set => {
|
||||
key_values => [ { name => 'cpu_total_usage', diff => 1 }, { name => 'cpu_number' }, { name => 'display' } ],
|
||||
output_template => 'CPU Usage : %.2f %%',
|
||||
output_template => 'cpu usage: %.2f %%',
|
||||
closure_custom_calc => $self->can('custom_cpu_calc'),
|
||||
output_use => 'prct_cpu', threshold_use => 'prct_cpu',
|
||||
perfdatas => [
|
||||
{ label => 'cpu', value => 'prct_cpu', template => '%.2f',
|
||||
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
|
||||
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
|
||||
],
|
||||
}
|
||||
},
|
||||
|
@ -233,7 +230,7 @@ sub set_counters {
|
|||
closure_custom_calc => $self->can('custom_memory_calc'),
|
||||
closure_custom_output => $self->can('custom_memory_output'),
|
||||
closure_custom_perfdata => $self->can('custom_memory_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_memory_threshold'),
|
||||
closure_custom_threshold_check => $self->can('custom_memory_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'fs', set => {
|
||||
|
@ -241,7 +238,7 @@ sub set_counters {
|
|||
closure_custom_calc => $self->can('custom_fs_calc'),
|
||||
closure_custom_output => $self->can('custom_fs_output'),
|
||||
closure_custom_perfdata => $self->can('custom_fs_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_fs_threshold'),
|
||||
closure_custom_threshold_check => $self->can('custom_fs_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'swap', set => {
|
||||
|
@ -249,9 +246,9 @@ sub set_counters {
|
|||
closure_custom_calc => $self->can('custom_swap_calc'),
|
||||
closure_custom_output => $self->can('custom_swap_output'),
|
||||
closure_custom_perfdata => $self->can('custom_swap_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_swap_threshold'),
|
||||
closure_custom_threshold_check => $self->can('custom_swap_threshold')
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -261,12 +258,10 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'node-id:s' => { name => 'node_id' },
|
||||
'node-name:s' => { name => 'node_name' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'use-name' => { name => 'use_name' },
|
||||
'warning-node-status:s' => { name => 'warning_node_status', default => '' },
|
||||
'critical-node-status:s' => { name => 'critical_node_status', default => '' },
|
||||
'node-id:s' => { name => 'node_id' },
|
||||
'node-name:s' => { name => 'node_name' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'use-name' => { name => 'use_name' }
|
||||
});
|
||||
|
||||
$self->{statefile_cache_nodes} = centreon::plugins::statefile->new(%options);
|
||||
|
@ -277,16 +272,9 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_node_status', 'critical_node_status']);
|
||||
$self->{statefile_cache_nodes}->check_options(%options);
|
||||
}
|
||||
|
||||
sub prefix_nodes_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Node '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
@ -307,6 +295,7 @@ sub manage_selection {
|
|||
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{nodes}->{$node_id} = {
|
||||
display => defined($self->{option_results}->{use_name}) ? $name : $node_id,
|
||||
name => $name,
|
||||
|
@ -319,7 +308,7 @@ sub manage_selection {
|
|||
swap_total =>
|
||||
defined($result->{$node_id}->{Stats}->{swap}->{total}) && $result->{$node_id}->{Stats}->{swap}->{total} > 0 ? $result->{$node_id}->{Stats}->{swap}->{total} : undef,
|
||||
fs_usage => $result->{$node_id}->{Stats}->{rootfs}->{used},
|
||||
fs_total => $result->{$node_id}->{Stats}->{rootfs}->{total},
|
||||
fs_total => $result->{$node_id}->{Stats}->{rootfs}->{total}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -329,11 +318,13 @@ sub manage_selection {
|
|||
}
|
||||
|
||||
my $hostnames = $options{custom}->get_hostnames();
|
||||
$self->{cache_name} = "proxmox_" . $self->{mode} . '_' .$hostnames . '_' . $options{custom}->get_port() . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{node_id}) ? md5_hex($self->{option_results}->{node_id}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{node_name}) ? md5_hex($self->{option_results}->{node_name}) : md5_hex('all'));
|
||||
$self->{cache_name} = 'proxmox_' . $self->{mode} . '_' .$hostnames . '_' . $options{custom}->get_port() . '_' .
|
||||
md5_hex(
|
||||
(defined($self->{option_results}->{filter_counters}) ? $self->{option_results}->{filter_counters} : '') . '_' .
|
||||
(defined($self->{option_results}->{filter_name}) ? $self->{option_results}->{filter_name} : '') . '_' .
|
||||
(defined($self->{option_results}->{node_id}) ? $self->{option_results}->{node_id} : '') . '_' .
|
||||
(defined($self->{option_results}->{node_name}) ? $self->{option_results}->{node_name} : '')
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -379,12 +370,12 @@ Can be: 'cpu' (%), 'memory' (%), 'swap' (%), 'fs' (%).
|
|||
|
||||
=item B<--warning-node-status>
|
||||
|
||||
Set warning threshold for status (Default: -)
|
||||
Set warning threshold for status.
|
||||
Can used special variables like: %{name}, %{state}.
|
||||
|
||||
=item B<--critical-node-status>
|
||||
|
||||
Set critical threshold for status (Default: -).
|
||||
Set critical threshold for status.
|
||||
Can used special variables like: %{name}, %{state}.
|
||||
|
||||
=back
|
||||
|
|
|
@ -25,22 +25,12 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
my $msg = 'state : ' . $self->{result_values}->{state};
|
||||
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
|
||||
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
|
||||
|
||||
return 0;
|
||||
return 'state : ' . $self->{result_values}->{state};
|
||||
}
|
||||
|
||||
sub custom_storage_perfdata {
|
||||
|
@ -59,8 +49,10 @@ sub custom_storage_perfdata {
|
|||
sub custom_storage_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used},
|
||||
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
|
||||
my $exit = $self->{perfdata}->threshold_check(
|
||||
value => $self->{result_values}->{prct_used},
|
||||
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]
|
||||
);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
|
@ -71,11 +63,12 @@ sub custom_storage_output {
|
|||
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
|
||||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
|
||||
my $msg = sprintf("Storage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
||||
return sprintf(
|
||||
"storage total: %s used: %s (%.2f%%) free: %s (%.2f%%)",
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
|
||||
return $msg;
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_storage_calc {
|
||||
|
@ -87,24 +80,30 @@ sub custom_storage_calc {
|
|||
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
|
||||
$self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
|
||||
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub prefix_storages_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Storage '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'storages', type => 1, cb_prefix_output => 'prefix_storages_output',
|
||||
message_multiple => 'All storages are ok', skipped_code => { -11 => 1 } },
|
||||
message_multiple => 'All storages are ok', skipped_code => { -11 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{storages} = [
|
||||
{ label => 'storage-status', threshold => 0, set => {
|
||||
{ label => 'storage-status', type => 2, set => {
|
||||
key_values => [ { name => 'state' }, { name => 'name' } ],
|
||||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold_ng
|
||||
}
|
||||
},
|
||||
{ label => 'storage', set => {
|
||||
|
@ -123,15 +122,14 @@ sub new {
|
|||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$options{options}->add_options(arguments =>
|
||||
{
|
||||
"storage-id:s" => { name => 'storage_id' },
|
||||
"storage-name:s" => { name => 'storage_name' },
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
"use-name" => { name => 'use_name' },
|
||||
"warning-storage-status:s" => { name => 'warning_storage_status', default => '' },
|
||||
"critical-storage-status:s" => { name => 'critical_storage_status', default => '' },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
'storage-id:s' => { name => 'storage_id' },
|
||||
'storage-name:s' => { name => 'storage_name' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'use-name' => { name => 'use_name' },
|
||||
'node-id:s' => { name => 'node_id' },
|
||||
'node-name:s' => { name => 'node_name' }
|
||||
});
|
||||
|
||||
$self->{statefile_cache_storages} = centreon::plugins::statefile->new(%options);
|
||||
return $self;
|
||||
|
@ -141,27 +139,21 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_storage_status', 'critical_storage_status']);
|
||||
$self->{statefile_cache_storages}->check_options(%options);
|
||||
}
|
||||
|
||||
sub prefix_storages_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Storage '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{storages} = {};
|
||||
|
||||
my $result = $options{custom}->api_get_storages(
|
||||
storage_id => $self->{option_results}->{storage_id},
|
||||
storage_name => $self->{option_results}->{storage_name},
|
||||
node_id => $self->{option_results}->{node_id},
|
||||
node_name => $self->{option_results}->{node_name},
|
||||
statefile => $self->{statefile_cache_storages}
|
||||
);
|
||||
|
||||
$self->{storages} = {};
|
||||
foreach my $storage_id (keys %{$result}) {
|
||||
next if (!defined($result->{$storage_id}->{Stats}));
|
||||
|
||||
|
@ -171,12 +163,13 @@ sub manage_selection {
|
|||
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{storages}->{$storage_id} = {
|
||||
display => defined($self->{option_results}->{use_name}) ? $name : $storage_id,
|
||||
name => $name,
|
||||
state => $result->{$storage_id}->{State},
|
||||
storage_usage => $result->{$storage_id}->{Stats}->{used},
|
||||
storage_total => $result->{$storage_id}->{Stats}->{total},
|
||||
storage_total => $result->{$storage_id}->{Stats}->{total}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -186,11 +179,16 @@ sub manage_selection {
|
|||
}
|
||||
|
||||
my $hostnames = $options{custom}->get_hostnames();
|
||||
$self->{cache_name} = "proxmox_" . $self->{mode} . '_' .$hostnames . '_' . $options{custom}->get_port() . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{storage_id}) ? md5_hex($self->{option_results}->{storage_id}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{storage_name}) ? md5_hex($self->{option_results}->{storage_name}) : md5_hex('all'));
|
||||
$self->{cache_name} = 'proxmox_' . $self->{mode} . '_' . $hostnames . '_' . $options{custom}->get_port() . '_' .
|
||||
md5_hex(
|
||||
(defined($self->{option_results}->{filter_counters}) ? $self->{option_results}->{filter_counters} : '') . '_' .
|
||||
(defined($self->{option_results}->{filter_name}) ? $self->{option_results}->{filter_name} : '') . '_' .
|
||||
(defined($self->{option_results}->{storage_id}) ? $self->{option_results}->{storage_id} : '') . '_' .
|
||||
(defined($self->{option_results}->{storage_name}) ? $self->{option_results}->{storage_name} : '') . '_' .
|
||||
(defined($self->{option_results}->{node_id}) ? $self->{option_results}->{node_id} : '') . '_' .
|
||||
(defined($self->{option_results}->{node_name}) ? $self->{option_results}->{node_name} : '')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -203,6 +201,11 @@ Check storage usage.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-counters>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
Example: --filter-counters='^storage-status$'
|
||||
|
||||
=item B<--storage-id>
|
||||
|
||||
Exact storage ID.
|
||||
|
@ -219,31 +222,29 @@ Use storage name for perfdata and display.
|
|||
|
||||
Filter by storage name (can be a regexp).
|
||||
|
||||
=item B<--filter-counters>
|
||||
=item B<--node-id>
|
||||
|
||||
Only display some counters (regexp can be used).
|
||||
Example: --filter-counters='^storage-status$'
|
||||
Exact node ID.
|
||||
|
||||
=item B<--warning-*>
|
||||
=item B<--node-name>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'storage' (%).
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'storage' (%).
|
||||
Exact node name.
|
||||
|
||||
=item B<--warning-storage-status>
|
||||
|
||||
Set warning threshold for status (Default: -)
|
||||
Set warning threshold for status.
|
||||
Can used special variables like: %{name}, %{state}.
|
||||
|
||||
=item B<--critical-storage-status>
|
||||
|
||||
Set critical threshold for status (Default: -).
|
||||
Set critical threshold for status.
|
||||
Can used special variables like: %{name}, %{state}.
|
||||
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
Thresholds.
|
||||
Can be: 'storage' (%).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -44,10 +44,13 @@ sub check_options {
|
|||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
my $result = $options{custom}->get_version();
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "Version is '" . $result . "'");
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => "Version is '" . $result . "'"
|
||||
);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -73,7 +73,7 @@ sub custom_memory_output {
|
|||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
|
||||
return sprintf(
|
||||
'Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
|
||||
'memory total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
|
||||
|
@ -108,8 +108,10 @@ sub custom_swap_perfdata {
|
|||
sub custom_swap_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used},
|
||||
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]);
|
||||
my $exit = $self->{perfdata}->threshold_check(
|
||||
value => $self->{result_values}->{prct_used},
|
||||
threshold => [ { label => 'critical-' . $self->{thlabel}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{thlabel}, exit_litteral => 'warning' } ]
|
||||
);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
|
@ -121,7 +123,7 @@ sub custom_swap_output {
|
|||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
|
||||
return sprintf(
|
||||
'Swap Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
|
||||
'swap total: %s used: %s (%.2f%%) free: %s (%.2f%%)',
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
|
||||
|
@ -140,12 +142,17 @@ sub custom_swap_calc {
|
|||
return 0;
|
||||
}
|
||||
|
||||
sub prefix_vms_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "VM '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'vms', type => 1, cb_prefix_output => 'prefix_vms_output', message_multiple => 'All vms are ok', skipped_code => { -11 => 1 } },
|
||||
{ name => 'vms_traffic', type => 1, cb_prefix_output => 'prefix_vms_traffic_output', message_multiple => 'All vm traffics are ok', skipped_code => { -11 => 1 } },
|
||||
{ name => 'vms', type => 1, cb_prefix_output => 'prefix_vms_output', message_multiple => 'All vms are ok', skipped_code => { -10 => 1, -11 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{vms} = [
|
||||
|
@ -158,7 +165,7 @@ sub set_counters {
|
|||
},
|
||||
{ label => 'cpu', set => {
|
||||
key_values => [ { name => 'cpu_total_usage', diff => 1 }, { name => 'cpu_number' }, { name => 'display' } ],
|
||||
output_template => 'CPU Usage : %.2f %%',
|
||||
output_template => 'cpu usage: %.2f %%',
|
||||
closure_custom_calc => $self->can('custom_cpu_calc'),
|
||||
output_use => 'prct_cpu', threshold_use => 'prct_cpu',
|
||||
perfdatas => [
|
||||
|
@ -177,7 +184,7 @@ sub set_counters {
|
|||
},
|
||||
{ label => 'read-iops', set => {
|
||||
key_values => [ { name => 'read_io', per_second => 1 }, { name => 'display' } ],
|
||||
output_template => 'Read IOPs : %.2f', output_error_template => "Read IOPs : %s",
|
||||
output_template => 'read iops: %.2f',
|
||||
perfdatas => [
|
||||
{ label => 'read_iops', template => '%.2f',
|
||||
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
|
@ -186,7 +193,7 @@ sub set_counters {
|
|||
},
|
||||
{ label => 'write-iops', set => {
|
||||
key_values => [ { name => 'write_io', per_second => 1 }, { name => 'display' } ],
|
||||
output_template => 'Write IOPs : %.2f', output_error_template => "Write IOPs : %s",
|
||||
output_template => 'write iops: %.2f',
|
||||
perfdatas => [
|
||||
{ label => 'write_iops', template => '%.2f',
|
||||
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
|
@ -200,14 +207,11 @@ sub set_counters {
|
|||
closure_custom_perfdata => $self->can('custom_swap_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_swap_threshold')
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{vms_traffic} = [
|
||||
},
|
||||
{ label => 'traffic-in', set => {
|
||||
key_values => [ { name => 'traffic_in', per_second => 1 }, { name => 'display' } ],
|
||||
output_change_bytes => 2,
|
||||
output_template => 'Traffic In : %s %s/s',
|
||||
output_template => 'traffic in: %s %s/s',
|
||||
perfdatas => [
|
||||
{ label => 'traffic_in', template => '%.2f',
|
||||
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
|
||||
|
@ -217,7 +221,7 @@ sub set_counters {
|
|||
{ label => 'traffic-out', set => {
|
||||
key_values => [ { name => 'traffic_out', per_second => 1 }, { name => 'display' } ],
|
||||
output_change_bytes => 2,
|
||||
output_template => 'Traffic Out : %s %s/s',
|
||||
output_template => 'traffic out: %s %s/s',
|
||||
perfdatas => [
|
||||
{ label => 'traffic_out', template => '%.2f',
|
||||
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
|
||||
|
@ -250,30 +254,17 @@ sub check_options {
|
|||
$self->{statefile_cache_vms}->check_options(%options);
|
||||
}
|
||||
|
||||
sub prefix_vms_traffic_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "VM '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub prefix_vms_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "VM '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{vms} = {};
|
||||
$self->{vms_traffic} = {};
|
||||
|
||||
my $result = $options{custom}->api_get_vms(
|
||||
vm_id => $self->{option_results}->{vm_id},
|
||||
vm_name => $self->{option_results}->{vm_name},
|
||||
statefile => $self->{statefile_cache_vms}
|
||||
);
|
||||
|
||||
$self->{vms} = {};
|
||||
$self->{vms_traffic} = {};
|
||||
foreach my $vm_id (keys %{$result}) {
|
||||
next if (!defined($result->{$vm_id}->{Stats}));
|
||||
|
||||
|
@ -295,10 +286,7 @@ sub manage_selection {
|
|||
memory_usage => $result->{$vm_id}->{Stats}->{mem},
|
||||
memory_total => $result->{$vm_id}->{Stats}->{maxmem},
|
||||
swap_usage => $result->{$vm_id}->{Stats}->{swap},
|
||||
swap_total => defined($result->{$vm_id}->{Stats}->{maxswap}) && $result->{$vm_id}->{Stats}->{maxswap} > 0 ? $result->{$vm_id}->{Stats}->{maxswap} : undef
|
||||
};
|
||||
$self->{vms_traffic}->{$name} = {
|
||||
display => $name,
|
||||
swap_total => defined($result->{$vm_id}->{Stats}->{maxswap}) && $result->{$vm_id}->{Stats}->{maxswap} > 0 ? $result->{$vm_id}->{Stats}->{maxswap} : undef,
|
||||
traffic_in => $result->{$vm_id}->{Stats}->{netin} * 8,
|
||||
traffic_out => $result->{$vm_id}->{Stats}->{netout} * 8
|
||||
};
|
||||
|
@ -310,11 +298,13 @@ sub manage_selection {
|
|||
}
|
||||
|
||||
my $hostnames = $options{custom}->get_hostnames();
|
||||
$self->{cache_name} = "proxmox_" . $self->{mode} . '_' .$hostnames . '_' . $options{custom}->get_port() . '_' .
|
||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{vm_id}) ? md5_hex($self->{option_results}->{vm_id}) : md5_hex('all')) . '_' .
|
||||
(defined($self->{option_results}->{vm_name}) ? md5_hex($self->{option_results}->{vm_name}) : md5_hex('all'));
|
||||
$self->{cache_name} = 'proxmox_' . $self->{mode} . '_' .$hostnames . '_' . $options{custom}->get_port() . '_' .
|
||||
md5_hex(
|
||||
(defined($self->{option_results}->{filter_counters}) ? $self->{option_results}->{filter_counters} : '') . '_' .
|
||||
(defined($self->{option_results}->{filter_name}) ? $self->{option_results}->{filter_name} : '') . '_' .
|
||||
(defined($self->{option_results}->{vm_id}) ? $self->{option_results}->{vm_id} : '') . '_' .
|
||||
(defined($self->{option_results}->{vm_name}) ? $self->{option_results}->{vm_name} : '')
|
||||
);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -26,11 +26,9 @@ use base qw(centreon::plugins::script_custom);
|
|||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$self->{modes} = {
|
||||
'list-nodes' => 'apps::proxmox::ve::restapi::mode::listnodes',
|
||||
'list-storages' => 'apps::proxmox::ve::restapi::mode::liststorages',
|
||||
|
|
Loading…
Reference in New Issue