enh(plugin)metrics-v2-sample-pr (#2455)

This commit is contained in:
Simon Bomm 2020-12-28 10:23:51 +01:00 committed by GitHub
parent 9bfc7ed535
commit 553a3fc4a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 274 additions and 468 deletions

View File

@ -31,10 +31,17 @@ sub custom_memory_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{memory_total}); my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{memory_total});
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{memory_used}); my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{memory_used});
my $msg = sprintf("Memory Used: %s (%.2f%%) Total: %s" , return sprintf(
$total_used_value . " " . $total_used_unit, 100 * $self->{result_values}->{memory_used} / $self->{result_values}->{memory_total}, "Memory Used: %s (%.2f%%) Total: %s" ,
$total_size_value . " " . $total_size_unit); $total_used_value . " " . $total_used_unit, 100 * $self->{result_values}->{memory_used} / $self->{result_values}->{memory_total},
return $msg; $total_size_value . " " . $total_size_unit
);
}
sub prefix_containers_output {
my ($self, %options) = @_;
return "Container '" . $options{instance_value}->{display} . "' ";
} }
sub set_counters { sub set_counters {
@ -45,86 +52,82 @@ sub set_counters {
]; ];
$self->{maps_counters}->{containers} = [ $self->{maps_counters}->{containers} = [
{ label => 'cpu-number', set => { { label => 'cpu-number', nlabel => 'container.cpu.count', set => {
key_values => [ { name => 'cpu_number'}, { name => 'display' } ], key_values => [ { name => 'cpu_number'}, { name => 'display' } ],
output_template => 'CPU: %d core(s)', output_template => 'CPU: %d core(s)',
output_use => 'cpu_number',
perfdatas => [ perfdatas => [
{ label => 'cpu_number', value => 'cpu_number', template => '%d', { label => 'cpu_number', template => '%d',
min => 0, label_extra_instance => 1, instance_use => 'display' }, min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'cpu-total', set => { { label => 'cpu-total', nlabel => 'container.cpu.utilization.percentage', set => {
key_values => [ { name => 'cpu_total'}, { name => 'display' } ], key_values => [ { name => 'cpu_total'}, { name => 'display' } ],
output_template => 'CPU Usage: %.2f %%', output_template => 'CPU Usage: %.2f %%',
output_use => 'cpu_total',
perfdatas => [ perfdatas => [
{ label => 'cpu_total', value => 'cpu_total', template => '%.2f', { label => 'cpu_total', 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' }
], ]
} }
}, },
{ label => 'cpu-user', set => { { label => 'cpu-user', nlabel => 'container.cpu.user.utilization.percentage', set => {
key_values => [ { name => 'cpu_user'}, { name => 'display' } ], key_values => [ { name => 'cpu_user'}, { name => 'display' } ],
output_template => 'CPU User: %.2f %%', output_template => 'CPU User: %.2f %%',
output_use => 'cpu_user',
perfdatas => [ perfdatas => [
{ label => 'cpu_user', value => 'cpu_user', template => '%.2f', { label => 'cpu_user', 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' }
], ]
} }
}, },
{ label => 'cpu-system', set => { { label => 'cpu-system', nlabel => 'container.cpu.system.utilization.percentage', set => {
key_values => [ { name => 'cpu_system' }, { name => 'display' } ], key_values => [ { name => 'cpu_system' }, { name => 'display' } ],
output_template => 'CPU System: %.2f %%', output_template => 'CPU System: %.2f %%',
output_use => 'cpu_system',
perfdatas => [ perfdatas => [
{ label => 'cpu_system', value => 'cpu_system', template => '%.2f', { label => 'cpu_system', 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' }
], ]
} }
}, },
{ label => 'memory', set => { { label => 'memory', nlabel => 'container.memory.usage.bytes', set => {
key_values => [ { name => 'memory_used' }, { name => 'memory_total' }, { name => 'display' } ], key_values => [ { name => 'memory_used' }, { name => 'memory_total' }, { name => 'display' } ],
output_change_bytes => 1,
closure_custom_output => $self->can('custom_memory_output'), closure_custom_output => $self->can('custom_memory_output'),
output_change_bytes => 1,
perfdatas => [ perfdatas => [
{ label => 'memory_used', value => 'memory_used', template => '%s', { label => 'memory_used', template => '%s',
min => 0, max => 'memory_total',unit => 'B', label_extra_instance => 1, instance_use => 'display' }, min => 0, max => 'memory_total',unit => 'B', label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'memory-cache', set => { { label => 'memory-cache', nlabel => 'container.memory.cache.usage.bytes', set => {
key_values => [ { name => 'memory_cache' }, { name => 'display' } ], key_values => [ { name => 'memory_cache' }, { name => 'display' } ],
output_change_bytes => 1,
output_template => 'Memory Cache: %s %s', output_template => 'Memory Cache: %s %s',
output_change_bytes => 1,
perfdatas => [ perfdatas => [
{ label => 'memory_cache', value => 'memory_cache', template => '%s', { label => 'memory_cache', template => '%s',
min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' }, min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'memory-rss', set => { { label => 'memory-rss', nlabel => 'container.memory.rss.usage.bytes', set => {
key_values => [ { name => 'memory_rss' }, { name => 'display' } ], key_values => [ { name => 'memory_rss' }, { name => 'display' } ],
output_change_bytes => 1,
output_template => 'Memory RSS: %s %s', output_template => 'Memory RSS: %s %s',
perfdatas => [
{ label => 'memory_rss', value => 'memory_rss', template => '%s',
min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' },
],
}
},
{ label => 'swap', set => {
key_values => [ { name => 'swap' }, { name => 'display' } ],
output_change_bytes => 1, output_change_bytes => 1,
output_template => 'Swap: %s %s',
perfdatas => [ perfdatas => [
{ label => 'swap', value => 'swap', template => '%s', { label => 'memory_rss', template => '%s',
min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' }, min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'swap', nlabel => 'container.swap.usage.bytes', set => {
key_values => [ { name => 'swap' }, { name => 'display' } ],
output_template => 'Swap: %s %s',
output_change_bytes => 1,
perfdatas => [
{ label => 'swap', template => '%s',
min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display' }
]
}
}
]; ];
} }
@ -134,29 +137,15 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"container-id:s" => { name => 'container_id' }, 'container-id:s' => { name => 'container_id' },
"container-name:s" => { name => 'container_name' }, 'container-name:s' => { name => 'container_name' },
"filter-name:s" => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' },
"use-name" => { name => 'use_name' }, 'use-name' => { name => 'use_name' }
"warning-container-status:s" => { name => 'warning_container_status', default => '' },
"critical-container-status:s" => { name => 'critical_container_status', default => '' },
}); });
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_container_status', 'critical_container_status']);
}
sub prefix_containers_output {
my ($self, %options) = @_;
return "Container '" . $options{instance_value}->{display} . "' ";
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -265,7 +254,7 @@ Filter by container name (can be a regexp).
=item B<--filter-counters> =item B<--filter-counters>
Only display some counters (regexp can be used). Only display some counters (regexp can be used).
Example: --filter-counters='^container-status$' Example: --filter-counters='cpu'
=item B<--warning-*> =item B<--warning-*>
@ -279,16 +268,6 @@ Threshold critical.
Can be: 'read-iops', 'write-iops', 'traffic-in', 'traffic-out', Can be: 'read-iops', 'write-iops', 'traffic-in', 'traffic-out',
'cpu' (%), 'memory' (%). 'cpu' (%), 'memory' (%).
=item B<--warning-container-status>
Set warning threshold for status (Default: -)
Can used special variables like: %{name}, %{state}.
=item B<--critical-container-status>
Set critical threshold for status (Default: -).
Can used special variables like: %{name}, %{state}.
=back =back
=cut =cut

View File

@ -34,26 +34,26 @@ sub set_counters {
]; ];
$self->{maps_counters}->{containers_diskio} = [ $self->{maps_counters}->{containers_diskio} = [
{ label => 'diskio-read', set => { { label => 'diskio-read', nlabel => 'disk.io.read.bytespersecond', set => {
key_values => [ { name => 'diskio_read' }, { name => 'display' } ], key_values => [ { name => 'diskio_read' }, { name => 'display' } ],
output_change_bytes => 1, output_change_bytes => 1,
output_template => 'Disk IO Read: %s %s/s', output_template => 'Disk IO Read: %s %s/s',
perfdatas => [ perfdatas => [
{ label => 'diskio_read', value => 'diskio_read', template => '%.2f', { label => 'diskio_read', template => '%.2f',
min => 0, unit => 'B/s', label_extra_instance => 1, instance_use => 'display' }, min => 0, unit => 'B/s', label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'diskio-write', set => { { label => 'diskio-write', nlabel => 'disk.io.write.bytespersecond', set => {
key_values => [ { name => 'diskio_write' }, { name => 'display' } ], key_values => [ { name => 'diskio_write' }, { name => 'display' } ],
output_change_bytes => 1, output_change_bytes => 1,
output_template => 'Disk IO Write: %s %s/s', output_template => 'Disk IO Write: %s %s/s',
perfdatas => [ perfdatas => [
{ label => 'diskio_write', value => 'diskio_write', template => '%.2f', { label => 'diskio_write', template => '%.2f',
min => 0, unit => 'B/s', label_extra_instance => 1, instance_use => 'display' }, min => 0, unit => 'B/s', label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, }
]; ];
} }
@ -62,19 +62,19 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'container-id:s' => { name => 'container_id' },
"container-id:s" => { name => 'container_id' }, 'container-name:s' => { name => 'container_name' },
"container-name:s" => { name => 'container_name' }, 'filter-name:s' => { name => 'filter_name' },
"filter-name:s" => { name => 'filter_name' }, 'use-name' => { name => 'use_name' }
"use-name" => { name => 'use_name' }, });
});
return $self; return $self;
} }
sub prefix_containers_diskio_output { sub prefix_containers_diskio_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Container '" . $options{instance_value}->{display} . "' "; return "Container '" . $options{instance_value}->{display} . "' ";
} }

View File

@ -25,60 +25,56 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
sub prefix_node_output {
my ($self, %options) = @_;
return "Node '" . $options{instance_value}->{display} . "' ";
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All node informations are ok', skipped_code => { -11 => 1 } }, { name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All node informations are ok', skipped_code => { -11 => 1 } }
];
$self->{maps_counters}->{nodes} = [
{ label => 'node-status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'manager_status' }, { name => 'display' } ],
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 => $self->can('custom_status_threshold'),
}
},
]; ];
$self->{maps_counters}->{node} = [ $self->{maps_counters}->{node} = [
{ label => 'containers-running', set => { { label => 'containers-running', nlabel => 'node.containers.running.count', set => {
key_values => [ { name => 'containers_running' }, { name => 'display' } ], key_values => [ { name => 'containers_running' }, { name => 'display' } ],
output_template => 'Containers Running : %s', output_template => 'Containers running: %s',
perfdatas => [ perfdatas => [
{ label => 'containers_running', value => 'containers_running', template => '%s', { label => 'containers_running', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }, min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'num-cores', set => { { label => 'num-cores', nlabel => 'node.core.count', set => {
key_values => [ { name => 'num_cores' }, { name => 'display' } ], key_values => [ { name => 'num_cores' }, { name => 'display' } ],
output_template => 'CPU cores: %s', output_template => 'CPU cores: %s',
perfdatas => [ perfdatas => [
{ label => 'num_cores', value => 'num_cores', template => '%s', { label => 'num_cores', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }, min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'memory-capacity', set => { { label => 'memory-capacity', nlabel => 'node.memory.bytes', set => {
key_values => [ { name => 'memory_capacity' }, { name => 'display' } ], key_values => [ { name => 'memory_capacity' }, { name => 'display' } ],
output_template => 'Mem capacity %s %s', output_template => 'Mem capacity %s %s',
perfdatas => [ perfdatas => [
{ label => 'memory_capacity', value => 'memory_capacity', unit => 'B', output_change_bytes => 1, template => '%s', { label => 'memory_capacity', unit => 'B', output_change_bytes => 1, template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }, min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'cpu-frequency', set => { { label => 'cpu-frequency', nlabel => 'node.cpu.frequency.hertz', set => {
key_values => [ { name => 'cpu_frequency' }, { name => 'display' } ], key_values => [ { name => 'cpu_frequency' }, { name => 'display' } ],
output_template => 'CPU frequency %s %s', output_template => 'CPU frequency %s %s',
perfdatas => [ perfdatas => [
{ label => 'cpu_frequency', value => 'cpu_frequency', unit => 'Hz', output_change_bytes => 1, template => '%s', { label => 'cpu_frequency', unit => 'Hz', output_change_bytes => 1, template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display' }, min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, }
]; ];
} }
@ -86,18 +82,11 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments =>
{
});
return $self;
}
sub prefix_node_output { $options{options}->add_options(arguments => {
my ($self, %options) = @_; });
return "Node '" . $options{instance_value}->{display} . "' "; return $self;
} }
sub manage_selection { sub manage_selection {
@ -114,7 +103,7 @@ sub manage_selection {
containers_running => scalar(@{$result->{$node_name}->{nodes}}), containers_running => scalar(@{$result->{$node_name}->{nodes}}),
}; };
} }
if (scalar(keys %{$self->{node}}) <= 0) { if (scalar(keys %{$self->{node}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No node found."); $self->{output}->add_option_msg(short_msg => "No node found.");
$self->{output}->option_exit(); $self->{output}->option_exit();
@ -131,14 +120,9 @@ Check node status.
=over 8 =over 8
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold warning. Thresholds.
Can be: 'containers-running', 'num-cores', 'memory-capacity', 'cpu-frequency'.
=item B<--critical-*>
Threshold critical.
Can be: 'containers-running', 'num-cores', 'memory-capacity', 'cpu-frequency'. Can be: 'containers-running', 'num-cores', 'memory-capacity', 'cpu-frequency'.
=back =back

View File

@ -27,34 +27,40 @@ use warnings;
use Digest::MD5 qw(md5_hex); use Digest::MD5 qw(md5_hex);
use DateTime; use DateTime;
sub prefix_containers_traffic_output {
my ($self, %options) = @_;
return "Container '" . $options{instance_value}->{display} . "' ";
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'containers_traffic', type => 1, cb_prefix_output => 'prefix_containers_traffic_output', message_multiple => 'All container traffics are ok', skipped_code => { -11 => 1 } }, { name => 'containers_traffic', type => 1, cb_prefix_output => 'prefix_containers_traffic_output', message_multiple => 'All container traffics are ok', skipped_code => { -11 => 1 } }
]; ];
$self->{maps_counters}->{containers_traffic} = [ $self->{maps_counters}->{containers_traffic} = [
{ label => 'traffic-in', set => { { label => 'traffic-in', nlabel => 'container.traffic.in.bitspersecond', set => {
key_values => [ { name => 'traffic_in' }, { name => 'display' } ], key_values => [ { name => 'traffic_in' }, { name => 'display' } ],
output_change_bytes => 2,
output_template => 'Traffic In: %s %s/s', output_template => 'Traffic In: %s %s/s',
perfdatas => [
{ label => 'traffic_in', value => 'traffic_in', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' },
],
}
},
{ label => 'traffic-out', set => {
key_values => [ { name => 'traffic_out' }, { name => 'display' } ],
output_change_bytes => 2, output_change_bytes => 2,
output_template => 'Traffic Out: %s %s/s',
perfdatas => [ perfdatas => [
{ label => 'traffic_out', value => 'traffic_out', template => '%.2f', { label => 'traffic_in', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'traffic-out', nlabel => 'container.traffic.out.bitspersecond', set => {
key_values => [ { name => 'traffic_out' }, { name => 'display' } ],
output_template => 'Traffic Out: %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_out', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
]
}
}
]; ];
} }
@ -64,19 +70,13 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"container-id:s" => { name => 'container_id' }, 'container-id:s' => { name => 'container_id' },
"container-name:s" => { name => 'container_name' }, 'container-name:s' => { name => 'container_name' },
"filter-name:s" => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' },
"use-name" => { name => 'use_name' }, 'use-name' => { name => 'use_name' }
}); });
return $self;
}
sub prefix_containers_traffic_output {
my ($self, %options) = @_;
return "Container '" . $options{instance_value}->{display} . "' "; return $self;
} }
sub manage_selection { sub manage_selection {

View File

@ -30,15 +30,15 @@ sub new {
bless $self, $class; bless $self, $class;
$self->{version} = '0.3'; $self->{version} = '0.3';
%{$self->{modes}} = ( $self->{modes} = {
'container-usage' => 'cloud::cadvisor::restapi::mode::containerusage', 'container-usage' => 'cloud::cadvisor::restapi::mode::containerusage',
'disk-io' => 'cloud::cadvisor::restapi::mode::diskio', 'disk-io' => 'cloud::cadvisor::restapi::mode::diskio',
'traffic' => 'cloud::cadvisor::restapi::mode::traffic', 'traffic' => 'cloud::cadvisor::restapi::mode::traffic',
'list-containers' => 'cloud::cadvisor::restapi::mode::listcontainers', 'list-containers' => 'cloud::cadvisor::restapi::mode::listcontainers',
'node-status' => 'cloud::cadvisor::restapi::mode::nodestatus', 'node-status' => 'cloud::cadvisor::restapi::mode::nodestatus'
); };
$self->{custom_modes}{api} = 'cloud::cadvisor::restapi::custom::api'; $self->{custom_modes}->{api} = 'cloud::cadvisor::restapi::custom::api';
return $self; return $self;
} }

View File

@ -24,22 +24,12 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_state_output { sub custom_state_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("state is '%s'", $self->{result_values}->{state}); return sprintf("state is '%s'", $self->{result_values}->{state});
return $msg;
}
sub custom_state_calc {
my ($self, %options) = @_;
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
return 0;
} }
sub prefix_output { sub prefix_output {
@ -53,39 +43,36 @@ sub set_counters {
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0 }, { name => 'global', type => 0 },
{ name => 'apps', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All apps state are ok' }, { name => 'apps', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All apps state are ok' }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'started', set => { { label => 'started', nlabel => 'applications.started.count', set => {
key_values => [ { name => 'started' } ], key_values => [ { name => 'started' } ],
output_template => 'Started : %d', output_template => 'Started : %d',
perfdatas => [ perfdatas => [
{ label => 'started', value => 'started', template => '%d', { label => 'started', template => '%d', min => 0 }
min => 0 }, ]
],
} }
}, },
{ label => 'stopped', set => { { label => 'stopped', nlabel => 'applications.stopped.count', set => {
key_values => [ { name => 'stopped' } ], key_values => [ { name => 'stopped' } ],
output_template => 'Stopped : %d', output_template => 'Stopped : %d',
perfdatas => [ perfdatas => [
{ label => 'stopped', value => 'stopped', template => '%d', { label => 'stopped', template => '%d', min => 0 }
min => 0 }, ]
],
} }
}, }
]; ];
$self->{maps_counters}->{apps} = [ $self->{maps_counters}->{apps} = [
{ label => 'state', set => { { label => 'state', type => 2, critical_default => '%{state} !~ /STARTED/i', set => {
key_values => [ { name => 'state' }, { name => 'name' } ], key_values => [ { name => 'state' }, { name => 'name' } ],
closure_custom_calc => $self->can('custom_state_calc'),
closure_custom_output => $self->can('custom_state_output'), closure_custom_output => $self->can('custom_state_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, }
]; ];
} }
@ -94,25 +81,15 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'organization-guid:s' => { name => 'organization_guid' },
"organization-guid:s" => { name => 'organization_guid' }, 'space-guid:s' => { name => 'space_guid' },
"space-guid:s" => { name => 'space_guid' }, 'filter-name:s' => { name => 'filter_name' }
"filter-name:s" => { name => 'filter_name' }, });
"warning-state:s" => { name => 'warning_state' },
"critical-state:s" => { name => 'critical_state', default => '%{state} !~ /STARTED/i' },
});
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_state', 'critical_state']);
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;

View File

@ -24,86 +24,21 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_app_state_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($self->{instance_mode}->{option_results}->{critical_app_state}) && $self->{instance_mode}->{option_results}->{critical_app_state} ne '' &&
eval "$self->{instance_mode}->{option_results}->{critical_app_state}") {
$status = 'critical';
} elsif (defined($self->{instance_mode}->{option_results}->{warning_app_state}) && $self->{instance_mode}->{option_results}->{warning_app_state} ne '' &&
eval "$self->{instance_mode}->{option_results}->{warning_app_state}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
}
sub custom_app_state_output { sub custom_app_state_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("App '%s' state is '%s'", return sprintf(
$self->{result_values}->{name}, $self->{result_values}->{state}); "App '%s' state is '%s'",
return $msg; $self->{result_values}->{name}, $self->{result_values}->{state}
} );
sub custom_app_state_calc {
my ($self, %options) = @_;
$self->{result_values}->{name} = $options{new_datas}->{$self->{instance} . '_name'};
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
return 0;
}
sub custom_inst_state_threshold {
my ($self, %options) = @_;
my $status = 'ok';
my $message;
eval {
local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($self->{instance_mode}->{option_results}->{critical_instance_state}) && $self->{instance_mode}->{option_results}->{critical_instance_state} ne '' &&
eval "$self->{instance_mode}->{option_results}->{critical_instance_state}") {
$status = 'critical';
} elsif (defined($self->{instance_mode}->{option_results}->{warning_instance_state}) && $self->{instance_mode}->{option_results}->{warning_instance_state} ne '' &&
eval "$self->{instance_mode}->{option_results}->{warning_instance_state}") {
$status = 'warning';
}
};
if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
}
return $status;
} }
sub custom_inst_state_output { sub custom_inst_state_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("state is '%s'", $self->{result_values}->{state}); return sprintf("state is '%s'", $self->{result_values}->{state});
return $msg;
}
sub custom_inst_state_calc {
my ($self, %options) = @_;
$self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'};
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
return 0;
} }
sub prefix_output { sub prefix_output {
@ -122,55 +57,50 @@ sub set_counters {
]; ];
$self->{maps_counters}->{app} = [ $self->{maps_counters}->{app} = [
{ label => 'state', set => { { label => 'app-state', type => 2, critical_default => '%{state} !~ /STARTED/i', set => {
key_values => [ { name => 'state' }, { name => 'name' } ], key_values => [ { name => 'state' }, { name => 'name' } ],
closure_custom_calc => $self->can('custom_app_state_calc'),
closure_custom_output => $self->can('custom_app_state_output'), closure_custom_output => $self->can('custom_app_state_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_app_state_threshold'), closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'running', set => { { label => 'running', nlabel => 'instances.running.count', set => {
key_values => [ { name => 'running' } ], key_values => [ { name => 'running' } ],
output_template => 'Running : %d', output_template => 'Running : %d',
perfdatas => [ perfdatas => [
{ label => 'running', value => 'running', template => '%d', { label => 'running', template => '%d', min => 0 }
min => 0 }, ]
],
} }
}, },
{ label => 'stopped', set => { { label => 'stopped', nlabel => 'instances.stopped.count', set => {
key_values => [ { name => 'stopped' } ], key_values => [ { name => 'stopped' } ],
output_template => 'Stopped : %d', output_template => 'Stopped : %d',
perfdatas => [ perfdatas => [
{ label => 'stopped', value => 'stopped', template => '%d', { label => 'stopped', template => '%d', min => 0 }
min => 0 }, ]
],
} }
}, },
{ label => 'crashed', set => { { label => 'crashed', nlabel => 'instances.crashed.count', set => {
key_values => [ { name => 'crashed' } ], key_values => [ { name => 'crashed' } ],
output_template => 'Crashed : %d', output_template => 'Crashed : %d',
perfdatas => [ perfdatas => [
{ label => 'crashed', value => 'crashed', template => '%d', { label => 'crashed', template => '%d', min => 0 }
min => 0 }, ]
],
} }
}, }
]; ];
$self->{maps_counters}->{instances} = [ $self->{maps_counters}->{instances} = [
{ label => 'state', set => { { label => 'instance-state', type => 2, critical_default => '%{state} !~ /RUNNING/i', set => {
key_values => [ { name => 'state' }, { name => 'id' } ], key_values => [ { name => 'state' }, { name => 'id' } ],
closure_custom_calc => $self->can('custom_inst_state_calc'),
closure_custom_output => $self->can('custom_inst_state_output'), closure_custom_output => $self->can('custom_inst_state_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_inst_state_threshold'), closure_custom_threshold_check => $self->can('custom_inst_state_threshold'),
} }
}, }
]; ];
} }
@ -180,11 +110,7 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"app-guid:s" => { name => 'app_guid' }, 'app-guid:s' => { name => 'app_guid' }
"warning-app-state:s" => { name => 'warning_app_state' },
"critical-app-state:s" => { name => 'critical_app_state', default => '%{state} !~ /STARTED/i' },
"warning-instance-state:s" => { name => 'warning_instance_state' },
"critical-instance-state:s" => { name => 'critical_instance_state', default => '%{state} !~ /RUNNING/i' },
}); });
return $self; return $self;
@ -198,8 +124,6 @@ sub check_options {
$self->{output}->add_option_msg(short_msg => "Need to specify app-guid option."); $self->{output}->add_option_msg(short_msg => "Need to specify app-guid option.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->change_macros(macros => ['warning_app_state', 'critical_app_state', 'warning_instance_state', 'critical_instance_state']);
} }
sub manage_selection { sub manage_selection {

View File

@ -30,15 +30,15 @@ sub new {
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
%{$self->{modes}} = ( $self->{modes} = {
'apps-state' => 'cloud::cloudfoundry::restapi::mode::appsstate', 'apps-state' => 'cloud::cloudfoundry::restapi::mode::appsstate',
'instances-state' => 'cloud::cloudfoundry::restapi::mode::instancesstate', 'instances-state' => 'cloud::cloudfoundry::restapi::mode::instancesstate',
'list-apps' => 'cloud::cloudfoundry::restapi::mode::listapps', 'list-apps' => 'cloud::cloudfoundry::restapi::mode::listapps',
'list-organizations' => 'cloud::cloudfoundry::restapi::mode::listorganizations', 'list-organizations' => 'cloud::cloudfoundry::restapi::mode::listorganizations',
'list-spaces' => 'cloud::cloudfoundry::restapi::mode::listspaces', 'list-spaces' => 'cloud::cloudfoundry::restapi::mode::listspaces'
); };
$self->{custom_modes}{restapi} = 'cloud::cloudfoundry::restapi::custom::api'; $self->{custom_modes}->{restapi} = 'cloud::cloudfoundry::restapi::custom::api';
return $self; return $self;
} }

View File

@ -25,24 +25,15 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use Digest::MD5 qw(md5_hex); 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 { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'state : ' . $self->{result_values}->{state}; my $msg = 'state : ' . $self->{result_values}->{state};
return $msg; 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;
}
sub custom_cpu_calc { sub custom_cpu_calc {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -57,15 +48,17 @@ sub custom_cpu_calc {
sub custom_memory_perfdata { sub custom_memory_perfdata {
my ($self, %options) = @_; my ($self, %options) = @_;
my $extra_label = ''; $self->{output}->perfdata_add(
if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { label => 'memory_used',
$extra_label .= '_' . $self->{result_values}->{display}; nlabel => 'container.memory.usage.bytes',
} unit => 'B',
$self->{output}->perfdata_add(label => 'memory_used' . $extra_label, unit => 'B', instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef,
value => $self->{result_values}->{used}, value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total}); min => 0,
max => $self->{result_values}->{total}
);
} }
sub custom_memory_threshold { sub custom_memory_threshold {
@ -82,11 +75,12 @@ sub custom_memory_output {
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); 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 ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
my $msg = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", return sprintf(
$total_size_value . " " . $total_size_unit, "Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, $total_size_value . " " . $total_size_unit,
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
return $msg; $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
);
} }
sub custom_memory_calc { sub custom_memory_calc {
@ -110,55 +104,54 @@ sub set_counters {
]; ];
$self->{maps_counters}->{containers} = [ $self->{maps_counters}->{containers} = [
{ label => 'container-status', threshold => 0, set => { { label => 'container-status', type => 2, set => {
key_values => [ { name => 'state' }, { name => 'name' } ], key_values => [ { name => 'state' }, { name => 'name' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, },
{ label => 'cpu', set => { { label => 'cpu', nlabel => 'container.cpu.utilization.percentage', set => {
key_values => [ { name => 'cpu_total_usage', diff => 1 }, { name => 'cpu_system_usage', diff => 1 }, { name => 'cpu_number' }, { name => 'display' } ], key_values => [ { name => 'cpu_total_usage', diff => 1 }, { name => 'cpu_system_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'), closure_custom_calc => $self->can('custom_cpu_calc'),
output_use => 'prct_cpu', threshold_use => 'prct_cpu', output_use => 'prct_cpu', threshold_use => 'prct_cpu',
perfdatas => [ perfdatas => [
{ label => 'cpu', value => 'prct_cpu', template => '%.2f', { 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' }
], ]
} }
}, },
{ label => 'memory', set => { { label => 'memory', nlabel => 'container.memory.usage.bytes', set => {
key_values => [ { name => 'memory_usage' }, { name => 'memory_total' }, { name => 'display' } ], key_values => [ { name => 'memory_usage' }, { name => 'memory_total' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_memory_calc'), closure_custom_calc => $self->can('custom_memory_calc'),
closure_custom_output => $self->can('custom_memory_output'), closure_custom_output => $self->can('custom_memory_output'),
closure_custom_perfdata => $self->can('custom_memory_perfdata'), 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 => 'read-iops', set => { { label => 'read-iops', nlabel => 'container.disk.io.read.usage.iops', set => {
key_values => [ { name => 'read_io', per_second => 1 }, { name => 'display' } ], 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', output_error_template => "Read IOPs : %s",
perfdatas => [ perfdatas => [
{ label => 'read_iops', template => '%.2f', { label => 'read_iops', template => '%.2f',
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display' }, unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, },
{ label => 'write-iops', set => { { label => 'write-iops', nlabel => 'container.disk.io.write.usage.iops', set => {
key_values => [ { name => 'write_io', per_second => 1 }, { name => 'display' } ], 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', output_error_template => "Write IOPs : %s",
perfdatas => [ perfdatas => [
{ label => 'write_iops', template => '%.2f', { label => 'write_iops', template => '%.2f',
unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display' }, unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, }
]; ];
$self->{maps_counters}->{containers_traffic} = [ $self->{maps_counters}->{containers_traffic} = [
{ label => 'traffic-in', set => { { label => 'traffic-in', nlabel => 'container.traffic.in.bitspersecond', set => {
key_values => [ { name => 'traffic_in', per_second => 1 }, { name => 'display' } ], key_values => [ { name => 'traffic_in', per_second => 1 }, { name => 'display' } ],
output_change_bytes => 2, output_change_bytes => 2,
output_template => 'Traffic In : %s %s/s', output_template => 'Traffic In : %s %s/s',
@ -168,16 +161,16 @@ sub set_counters {
], ],
} }
}, },
{ label => 'traffic-out', set => { { label => 'traffic-out', nlabel => 'container.traffic.out.bitspersecond', set => {
key_values => [ { name => 'traffic_out', per_second => 1 }, { name => 'display' } ], key_values => [ { name => 'traffic_out', per_second => 1 }, { name => 'display' } ],
output_change_bytes => 2, output_change_bytes => 2,
output_template => 'Traffic Out : %s %s/s', output_template => 'Traffic Out : %s %s/s',
perfdatas => [ perfdatas => [
{ label => 'traffic_out', template => '%.2f', { label => 'traffic_out', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }, min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
], ]
} }
}, }
]; ];
} }
@ -187,12 +180,10 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'container-id:s' => { name => 'container_id' }, 'container-id:s' => { name => 'container_id' },
'container-name:s' => { name => 'container_name' }, 'container-name:s' => { name => 'container_name' },
'filter-name:s' => { name => 'filter_name' }, 'filter-name:s' => { name => 'filter_name' },
'use-name' => { name => 'use_name' }, 'use-name' => { name => 'use_name' }
'warning-container-status:s' => { name => 'warning_container_status', default => '' },
'critical-container-status:s' => { name => 'critical_container_status', default => '' },
}); });
$self->{statefile_cache_containers} = centreon::plugins::statefile->new(%options); $self->{statefile_cache_containers} = centreon::plugins::statefile->new(%options);
@ -203,7 +194,6 @@ sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::check_options(%options); $self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_container_status', 'critical_container_status']);
$self->{statefile_cache_containers}->check_options(%options); $self->{statefile_cache_containers}->check_options(%options);
} }

View File

@ -37,7 +37,7 @@ sub set_counters {
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All node informations are ok', skipped_code => { -11 => 1 } }, { name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All node informations are ok', skipped_code => { -11 => 1 } },
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All node status are ok', skipped_code => { -11 => 1 } }, { name => 'nodes', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All node status are ok', skipped_code => { -11 => 1 } }
]; ];
$self->{maps_counters}->{nodes} = [ $self->{maps_counters}->{nodes} = [
@ -50,7 +50,7 @@ sub set_counters {
} }
]; ];
$self->{maps_counters}->{node} = [ $self->{maps_counters}->{node} = [
{ label => 'containers-running', set => { { label => 'containers-running', nlabel => 'node.containers.running.count', set => {
key_values => [ { name => 'containers_running' }, { name => 'display' } ], key_values => [ { name => 'containers_running' }, { name => 'display' } ],
output_template => 'Containers Running : %s', output_template => 'Containers Running : %s',
perfdatas => [ perfdatas => [
@ -59,7 +59,7 @@ sub set_counters {
] ]
} }
}, },
{ label => 'containers-stopped', set => { { label => 'containers-stopped', nlabel => 'node.containers.stopped.count', set => {
key_values => [ { name => 'containers_stopped' }, { name => 'display' } ], key_values => [ { name => 'containers_stopped' }, { name => 'display' } ],
output_template => 'Containers Stopped : %s', output_template => 'Containers Stopped : %s',
perfdatas => [ perfdatas => [
@ -68,7 +68,7 @@ sub set_counters {
] ]
} }
}, },
{ label => 'containers-paused', set => { { label => 'containers-paused', nlabel => 'node.containers.paused.count', set => {
key_values => [ { name => 'containers_paused' }, { name => 'display' } ], key_values => [ { name => 'containers_paused' }, { name => 'display' } ],
output_template => 'Containers Paused : %s', output_template => 'Containers Paused : %s',
perfdatas => [ perfdatas => [

View File

@ -30,37 +30,24 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_event_output { sub custom_event_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("Status is '%s', Impacted items: %d, Start date: %s, End date: %s", return sprintf(
"Status is '%s', Impacted items: %d, Start date: %s, End date: %s",
$self->{result_values}->{status}, $self->{result_values}->{status},
$self->{result_values}->{items}, $self->{result_values}->{items},
($self->{result_values}->{start_date} ne "-") ? $self->{result_values}->{start_date} . ' (' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since_start}) . ' ago)' : '-', ($self->{result_values}->{start_date} ne "-") ? $self->{result_values}->{start_date} . ' (' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since_start}) . ' ago)' : '-',
($self->{result_values}->{end_date} ne "-") ? $self->{result_values}->{end_date} . ' (' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since_end}) . ' ago)' : '-'); ($self->{result_values}->{end_date} ne "-") ? $self->{result_values}->{end_date} . ' (' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since_end}) . ' ago)' : '-'
return $msg; );
}
sub custom_event_calc {
my ($self, %options) = @_;
$self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'};
$self->{result_values}->{subject} = $options{new_datas}->{$self->{instance} . '_subject'};
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{items} = $options{new_datas}->{$self->{instance} . '_items'};
$self->{result_values}->{start_date} = $options{new_datas}->{$self->{instance} . '_start_date'};
$self->{result_values}->{since_start} = $options{new_datas}->{$self->{instance} . '_since_start'};
$self->{result_values}->{end_date} = $options{new_datas}->{$self->{instance} . '_end_date'};
$self->{result_values}->{since_end} = $options{new_datas}->{$self->{instance} . '_since_end'};
return 0;
} }
sub prefix_global_output { sub prefix_global_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Number of events "; return "Number of events ";
} }
sub prefix_events_output { sub prefix_events_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Event '" . $options{instance_value}->{id} . "' with subject '" . $options{instance_value}->{subject} . "' "; return "Event '" . $options{instance_value}->{id} . "' with subject '" . $options{instance_value}->{subject} . "' ";
} }
@ -71,46 +58,43 @@ sub set_counters {
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }, { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } },
{ name => 'events', type => 1, cb_prefix_output => 'prefix_events_output' }, { name => 'events', type => 1, cb_prefix_output => 'prefix_events_output' },
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'active', set => { { label => 'active', nlabel => 'events.active.count', set => {
key_values => [ { name => 'active' } ], key_values => [ { name => 'active' } ],
output_template => 'Active : %d', output_template => 'Active : %d',
perfdatas => [ perfdatas => [
{ label => 'active_events', value => 'active', template => '%d', { label => 'active_events', template => '%d', min => 0 }
min => 0 }, ]
],
} }
}, },
{ label => 'completed', set => { { label => 'completed', nlabel => 'events.completed.count', set => {
key_values => [ { name => 'completed' } ], key_values => [ { name => 'completed' } ],
output_template => 'Completed : %d', output_template => 'Completed : %d',
perfdatas => [ perfdatas => [
{ label => 'completed_events', value => 'completed', template => '%d', { label => 'completed_events', template => '%d', min => 0 }
min => 0 }, ]
],
} }
}, },
{ label => 'published', set => { { label => 'published',nlabel => 'events.published.count', set => {
key_values => [ { name => 'published' } ], key_values => [ { name => 'published' } ],
output_template => 'Published : %d', output_template => 'Published : %d',
perfdatas => [ perfdatas => [
{ label => 'published_events', value => 'published', template => '%d', { label => 'published_events', template => '%d', min => 0 }
min => 0 }, ]
],
} }
}, }
]; ];
$self->{maps_counters}->{events} = [ $self->{maps_counters}->{events} = [
{ label => 'event', threshold => 0, set => { { label => 'event', type => 2, critical_default => '%{status} =~ /Active/ && %{items} > 0', set => {
key_values => [ { name => 'id' }, { name => 'subject' }, { name => 'status' }, { name => 'items' }, key_values => [ { name => 'id' }, { name => 'subject' }, { name => 'status' }, { name => 'items' },
{ name => 'start_date' }, { name => 'since_start' }, { name => 'end_date' }, { name => 'since_end' } ], { name => 'start_date' }, { name => 'since_start' }, { name => 'end_date' }, { name => 'since_end' } ],
closure_custom_calc => $self->can('custom_event_calc'),
closure_custom_output => $self->can('custom_event_output'), closure_custom_output => $self->can('custom_event_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, }
]; ];
} }
@ -119,23 +103,13 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'filter-status:s' => { name => 'filter_status', default => 'Active' }
"filter-status:s" => { name => 'filter_status', default => 'Active' }, });
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Active/ && %{items} > 0' },
});
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;

View File

@ -25,35 +25,24 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use DateTime; use DateTime;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_ticket_output { sub custom_ticket_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("Title: '%s', Group: '%s', Priority: %s, Create Date: %s (%s ago)", return sprintf(
"Title: '%s', Group: '%s', Priority: %s, Create Date: %s (%s ago)",
$self->{result_values}->{title}, $self->{result_values}->{title},
$self->{result_values}->{group}, $self->{result_values}->{group},
$self->{result_values}->{priority}, $self->{result_values}->{priority},
$self->{result_values}->{create_date}, $self->{result_values}->{create_date},
centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since})); centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since})
return $msg; );
}
sub custom_ticket_calc {
my ($self, %options) = @_;
$self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'};
$self->{result_values}->{title} = $options{new_datas}->{$self->{instance} . '_title'};
$self->{result_values}->{priority} = $options{new_datas}->{$self->{instance} . '_priority'};
$self->{result_values}->{create_date} = $options{new_datas}->{$self->{instance} . '_create_date'};
$self->{result_values}->{group} = $options{new_datas}->{$self->{instance} . '_group'};
$self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'};
return 0;
} }
sub prefix_tickets_output { sub prefix_tickets_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Ticket '" . $options{instance_value}->{id} . "' is open with "; return "Ticket '" . $options{instance_value}->{id} . "' is open with ";
} }
@ -62,30 +51,29 @@ sub set_counters {
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0 }, { name => 'global', type => 0 },
{ name => 'tickets', type => 1, cb_prefix_output => 'prefix_tickets_output' }, { name => 'tickets', type => 1, cb_prefix_output => 'prefix_tickets_output' }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'open', set => { { label => 'open', nlabel => 'tickets.open.count', set => {
key_values => [ { name => 'open' } ], key_values => [ { name => 'open' } ],
output_template => 'Number of open tickets : %d', output_template => 'Number of open tickets : %d',
perfdatas => [ perfdatas => [
{ label => 'open_tickets', value => 'open', template => '%d', { label => 'open_tickets', template => '%d', min => 0 }
min => 0 }, ]
],
} }
}, }
]; ];
$self->{maps_counters}->{tickets} = [ $self->{maps_counters}->{tickets} = [
{ label => 'ticket', threshold => 0, set => { { label => 'ticket', type => 2, set => {
key_values => [ { name => 'id' }, { name => 'title' }, { name => 'priority' }, { name => 'create_date' }, key_values => [ { name => 'id' }, { name => 'title' }, { name => 'priority' }, { name => 'create_date' },
{ name => 'group' }, { name => 'since' } ], { name => 'group' }, { name => 'since' } ],
closure_custom_calc => $self->can('custom_ticket_calc'),
closure_custom_output => $self->can('custom_ticket_output'), closure_custom_output => $self->can('custom_ticket_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold_ng
} }
}, }
]; ];
} }
@ -94,23 +82,13 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'ticket-group:s' => { name => 'ticket_group' }
"ticket-group:s" => { name => 'ticket_group' }, });
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' },
});
return $self; return $self;
} }
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;

View File

@ -30,12 +30,12 @@ sub new {
bless $self, $class; bless $self, $class;
$self->{version} = '0.1'; $self->{version} = '0.1';
%{$self->{modes}} = ( $self->{modes} = {
'events' => 'cloud::ibm::softlayer::mode::events', 'events' => 'cloud::ibm::softlayer::mode::events',
'open-tickets' => 'cloud::ibm::softlayer::mode::opentickets', 'open-tickets' => 'cloud::ibm::softlayer::mode::opentickets'
); };
$self->{custom_modes}{xmlapi} = 'cloud::ibm::softlayer::custom::xmlapi'; $self->{custom_modes}->{xmlapi} = 'cloud::ibm::softlayer::custom::xmlapi';
return $self; return $self;
} }