add rudder plugin
This commit is contained in:
parent
1c94d66f6e
commit
3809f44dc4
|
@ -60,7 +60,7 @@ sub set_counters {
|
|||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0 },
|
||||
{ name => 'compliances', type => 1, cb_prefix_output => 'prefix_compliances_output',
|
||||
message_multiple => 'All detailed compliances are ok' },
|
||||
message_multiple => 'All compliance details are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::rudder::restapi::mode::listrules;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $results = $options{custom}->request_api(url_path => '/rules');
|
||||
|
||||
foreach my $rule (@{$results->{rules}}) {
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$rule->{displayName} !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $rule->{hostname} . "': no matching filter name.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
my @tags;
|
||||
foreach my $tag (@{$rule->{tags}}) {
|
||||
push @tags, (keys %{$tag})[0] . ':' . (values %{$tag})[0];
|
||||
}
|
||||
|
||||
$self->{rules}->{$rule->{id}} = {
|
||||
name => $rule->{displayName},
|
||||
tags => join(',', @tags),
|
||||
enabled => $rule->{enabled},
|
||||
id => $rule->{id},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection(%options);
|
||||
foreach my $rule (sort keys %{$self->{rules}}) {
|
||||
$self->{output}->output_add(long_msg => sprintf("[name = %s] [tags = %s] [enabled = %s] [id = %s]",
|
||||
$self->{rules}->{$rule}->{name},
|
||||
$self->{rules}->{$rule}->{tags},
|
||||
$self->{rules}->{$rule}->{enabled},
|
||||
$self->{rules}->{$rule}->{id}));
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List rules:');
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub disco_format {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{output}->add_disco_format(elements => ['name', 'tags', 'enabled', 'id']);
|
||||
}
|
||||
|
||||
sub disco_show {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection(%options);
|
||||
foreach my $rule (sort keys %{$self->{rules}}) {
|
||||
$self->{output}->add_disco_entry(
|
||||
name => $self->{rules}->{$rule}->{name},
|
||||
tags => $self->{rules}->{$rule}->{tags},
|
||||
enabled => $self->{rules}->{$rule}->{enabled},
|
||||
id => $self->{rules}->{$rule}->{id},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
List rules.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-name>
|
||||
|
||||
Filter rule name (can be a regexp).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,188 @@
|
|||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::rudder::restapi::mode::nodecompliance;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf("Compliance: %.2f%%", $self->{result_values}->{compliance});
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{rule} = $options{new_datas}->{$self->{instance} . '_rule'};
|
||||
$self->{result_values}->{compliance} = $options{new_datas}->{$self->{instance} . '_compliance'};
|
||||
$self->{result_values}->{display} = $self->{instance};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'nodes', type => 3, cb_prefix_output => 'prefix_node_output', cb_long_output => 'long_output',
|
||||
message_multiple => 'All nodes compliance are ok', indent_long_output => ' ',
|
||||
group => [
|
||||
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
|
||||
{ name => 'rules', display_long => 1, cb_prefix_output => 'prefix_rule_output',
|
||||
message_multiple => 'All rules compliance are ok', type => 1 },
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'node-compliance', set => {
|
||||
key_values => [ { name => 'compliance' }, { name => 'display' } ],
|
||||
output_template => 'Compliance: %.2f%%',
|
||||
perfdatas => [
|
||||
{ label => 'node_compliance', value => 'compliance_absolute', template => '%.2f',
|
||||
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{rules} = [
|
||||
{ label => 'status', set => {
|
||||
key_values => [ { name => 'compliance' }, { name => 'rule' } ],
|
||||
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,
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_node_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Node '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
|
||||
}
|
||||
|
||||
sub prefix_rule_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Rule '" . $options{instance_value}->{rule} . "' ";
|
||||
}
|
||||
|
||||
sub long_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Checking node '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{nodes} = {};
|
||||
|
||||
my $results = $options{custom}->request_api(url_path => '/compliance/nodes?level=2');
|
||||
|
||||
foreach my $node (@{$results->{nodes}}) {
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$node->{name} !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $node->{name} . "': no matching filter name.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{nodes}->{$node->{id}}->{id} = $node->{id};
|
||||
$self->{nodes}->{$node->{id}}->{display} = $node->{name};
|
||||
$self->{nodes}->{$node->{id}}->{global}->{compliance} = $node->{compliance};
|
||||
$self->{nodes}->{$node->{id}}->{global}->{display} = $node->{name};
|
||||
|
||||
foreach my $rule (@{$node->{rules}}) {
|
||||
$self->{nodes}->{$node->{id}}->{rules}->{$rule->{id}} = {
|
||||
rule => $rule->{name},
|
||||
compliance => $rule->{compliance},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{nodes}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No nodes found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check nodes compliance.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-node-compliance>
|
||||
|
||||
Set warning threshold on node compliance.
|
||||
|
||||
=item B<--critical-node-compliance>
|
||||
|
||||
Set critical threshold on node compliance.
|
||||
|
||||
=item B<--warning-status>
|
||||
|
||||
Set warning threshold for status of rule compliance (Default: '').
|
||||
Can used special variables like: %{rule}, %{compliance}
|
||||
|
||||
=item B<--critical-status>
|
||||
|
||||
Set critical threshold for status of rule compliance (Default: '').
|
||||
Can used special variables like: %{rule}, %{compliance}
|
||||
|
||||
Example :
|
||||
--critical-status='%{rule} eq "Global configuration for all nodes" && %{compliance} < 95'
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,198 @@
|
|||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::rudder::restapi::mode::nodesoverallcompliance;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
my $instance_mode;
|
||||
|
||||
sub custom_compliance_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my %total_options = ();
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$total_options{total} = $self->{result_values}->{total};
|
||||
$total_options{cast_int} = 1;
|
||||
}
|
||||
|
||||
$self->{output}->perfdata_add(label => 'compliance_' . $self->{label},
|
||||
value => $self->{result_values}->{count},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
|
||||
unit => 'nodes', min => 0, max => $self->{result_values}->{total});
|
||||
}
|
||||
|
||||
sub custom_compliance_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $threshold_value = $self->{result_values}->{count};
|
||||
if ($instance_mode->{option_results}->{units} eq '%') {
|
||||
$threshold_value = $self->{result_values}->{prct_count};
|
||||
}
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $threshold_value,
|
||||
threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' },
|
||||
{ label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]);
|
||||
return $exit;
|
||||
|
||||
}
|
||||
|
||||
sub custom_compliance_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf("%s: %d (%.2f%%)",
|
||||
$self->{result_values}->{output},
|
||||
$self->{result_values}->{count},
|
||||
$self->{result_values}->{prct_count});
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_compliance_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{label} = $options{extra_options}->{label};
|
||||
$self->{result_values}->{output} = $options{extra_options}->{output};
|
||||
$self->{result_values}->{count} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{label}};
|
||||
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
|
||||
|
||||
$self->{result_values}->{prct_count} = ($self->{result_values}->{total} != 0) ? $self->{result_values}->{count} * 100 / $self->{result_values}->{total} : 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_compliance_output' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'perfect', set => {
|
||||
key_values => [ { name => 'perfect' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_compliance_calc'),
|
||||
closure_custom_calc_extra_options => { label => 'perfect', output => 'Perfect (100%)' },
|
||||
closure_custom_output => $self->can('custom_compliance_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_compliance_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_compliance_perfdata')
|
||||
}
|
||||
},
|
||||
{ label => 'good', set => {
|
||||
key_values => [ { name => 'good' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_compliance_calc'),
|
||||
closure_custom_calc_extra_options => { label => 'good', output => 'Good (>75%)' },
|
||||
closure_custom_output => $self->can('custom_compliance_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_compliance_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_compliance_perfdata')
|
||||
}
|
||||
},
|
||||
{ label => 'average', set => {
|
||||
key_values => [ { name => 'average' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_compliance_calc'),
|
||||
closure_custom_calc_extra_options => { label => 'average', output => 'Average (>50%)' },
|
||||
closure_custom_output => $self->can('custom_compliance_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_compliance_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_compliance_perfdata')
|
||||
}
|
||||
},
|
||||
{ label => 'poor', set => {
|
||||
key_values => [ { name => 'poor' }, { name => 'total' } ],
|
||||
closure_custom_calc => $self->can('custom_compliance_calc'),
|
||||
closure_custom_calc_extra_options => { label => 'poor', output => 'Poor (<50%)' },
|
||||
closure_custom_output => $self->can('custom_compliance_output'),
|
||||
closure_custom_threshold_check => $self->can('custom_compliance_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_compliance_perfdata')
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_compliance_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Nodes Count by Overall Compliance ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"units:s" => { name => 'units', default => '%' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$instance_mode = $self;
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{global} = { perfect => 0, good => 0, average => 0, poor => 0, total => 0 };
|
||||
|
||||
my $results = $options{custom}->request_api(url_path => '/compliance/nodes?level=1');
|
||||
|
||||
foreach my $node (@{$results->{nodes}}) {
|
||||
$self->{global}->{total}++;
|
||||
$self->{global}->{poor}++ if ($node->{compliance} < 50);
|
||||
$self->{global}->{average}++ if ($node->{compliance} >= 50 && $node->{compliance} < 75);
|
||||
$self->{global}->{good}++ if ($node->{compliance} >= 75 && $node->{compliance} < 100);
|
||||
$self->{global}->{perfect}++ if ($node->{compliance} == 100);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check nodes count by overall compliance.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'perfect', 'good', 'average', 'poor'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'perfect', 'good', 'average', 'poor'.
|
||||
|
||||
=item B<--units>
|
||||
|
||||
Units of thresholds (Default: '%') ('%', 'count').
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,194 @@
|
|||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::rudder::restapi::mode::rulecompliance;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf("Compliance: %.2f%%", $self->{result_values}->{compliance});
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{directive} = $options{new_datas}->{$self->{instance} . '_directive'};
|
||||
$self->{result_values}->{compliance} = $options{new_datas}->{$self->{instance} . '_compliance'};
|
||||
$self->{result_values}->{display} = $self->{instance};
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'rules', type => 3, cb_prefix_output => 'prefix_rule_output', cb_long_output => 'long_output',
|
||||
message_multiple => 'All rules compliance are ok', indent_long_output => ' ',
|
||||
group => [
|
||||
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
|
||||
{ name => 'directives', display_long => 1, cb_prefix_output => 'prefix_directive_output',
|
||||
message_multiple => 'All directives compliance are ok', type => 1 },
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'rule-compliance', set => {
|
||||
key_values => [ { name => 'compliance' } ],
|
||||
output_template => 'Compliance: %.2f%%',
|
||||
perfdatas => [
|
||||
{ label => 'rule_compliance', value => 'compliance_absolute', template => '%.2f',
|
||||
min => 0, max => 100, unit => '%', label_extra_instance => 1 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{directives} = [
|
||||
{ label => 'status', set => {
|
||||
key_values => [ { name => 'compliance' }, { name => 'directive' } ],
|
||||
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,
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub prefix_rule_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Rule '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
|
||||
}
|
||||
|
||||
sub prefix_directive_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Directive '" . $options{instance_value}->{directive} . "' ";
|
||||
}
|
||||
|
||||
sub long_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Checking rule '" . $options{instance_value}->{display} . "' [Id: " . $options{instance_value}->{id} . "] ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my %rules_mapping;
|
||||
$self->{rules} = {};
|
||||
|
||||
my $results = $options{custom}->request_api(url_path => '/rules');
|
||||
|
||||
foreach my $rule (@{$results->{rules}}) {
|
||||
$rules_mapping{$rule->{id}} = $rule->{displayName};
|
||||
}
|
||||
|
||||
$results = $options{custom}->request_api(url_path => '/compliance/rules?level=2');
|
||||
|
||||
foreach my $rule (@{$results->{rules}}) {
|
||||
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
|
||||
$rules_mapping{$rule->{id}} !~ /$self->{option_results}->{filter_name}/) {
|
||||
$self->{output}->output_add(long_msg => "skipping '" . $rules_mapping{$rule->{id}} . "': no matching filter name.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{rules}->{$rule->{id}}->{id} = $rule->{id};
|
||||
$self->{rules}->{$rule->{id}}->{display} = $rules_mapping{$rule->{id}};
|
||||
$self->{rules}->{$rule->{id}}->{global}->{compliance} = $rule->{compliance};
|
||||
|
||||
foreach my $directive (@{$rule->{directives}}) {
|
||||
$self->{rules}->{$rule->{id}}->{directives}->{$directive->{id}} = {
|
||||
directive => $directive->{name},
|
||||
compliance => $directive->{compliance},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (scalar(keys %{$self->{rules}}) <= 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "No rules found.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check rules compliance.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-rule-compliance>
|
||||
|
||||
Set warning threshold on rule compliance.
|
||||
|
||||
=item B<--critical-rule-compliance>
|
||||
|
||||
Set critical threshold on rule compliance.
|
||||
|
||||
=item B<--warning-status>
|
||||
|
||||
Set warning threshold for status of directive compliance (Default: '').
|
||||
Can used special variables like: %{directive}, %{compliance}
|
||||
|
||||
=item B<--critical-status>
|
||||
|
||||
Set critical threshold for status of directive compliance (Default: '').
|
||||
Can used special variables like: %{directive}, %{compliance}
|
||||
|
||||
Example :
|
||||
--critical-status='%{directive} eq "Users" && %{compliance} < 85'
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -0,0 +1,162 @@
|
|||
#
|
||||
# Copyright 2019 Centreon (http://www.centreon.com/)
|
||||
#
|
||||
# Centreon is a full-fledged industry-strength solution that meets
|
||||
# the needs in IT infrastructure and application monitoring for
|
||||
# service performance.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
package apps::rudder::restapi::mode::statistics;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0 },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'nodes', set => {
|
||||
key_values => [ { name => 'nodes' } ],
|
||||
output_template => 'Nodes: %d',
|
||||
perfdatas => [
|
||||
{ label => 'nodes', value => 'nodes_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'pending_nodes', set => {
|
||||
key_values => [ { name => 'pending_nodes' } ],
|
||||
output_template => 'Pending Nodes: %d',
|
||||
perfdatas => [
|
||||
{ label => 'pending_nodes', value => 'pending_nodes_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'rules', set => {
|
||||
key_values => [ { name => 'rules' } ],
|
||||
output_template => 'Rules: %d',
|
||||
perfdatas => [
|
||||
{ label => 'rules', value => 'rules_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'directives', set => {
|
||||
key_values => [ { name => 'directives' } ],
|
||||
output_template => 'Directives: %d',
|
||||
perfdatas => [
|
||||
{ label => 'directives', value => 'directives_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'groups', set => {
|
||||
key_values => [ { name => 'groups' } ],
|
||||
output_template => 'Groups: %d',
|
||||
perfdatas => [
|
||||
{ label => 'groups', value => 'groups_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'techniques', set => {
|
||||
key_values => [ { name => 'techniques' } ],
|
||||
output_template => 'Techniques: %d',
|
||||
perfdatas => [
|
||||
{ label => 'techniques', value => 'techniques_absolute', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{compliances} = {};
|
||||
|
||||
my $results = $options{custom}->request_api(url_path => '/nodes?include=minimal');
|
||||
$self->{global}->{nodes} = scalar(@{$results->{nodes}});
|
||||
$results = $options{custom}->request_api(url_path => '/nodes/pending?include=minimal');
|
||||
$self->{global}->{pending_nodes} = scalar(@{$results->{nodes}});
|
||||
$results = $options{custom}->request_api(url_path => '/rules');
|
||||
$self->{global}->{rules} = scalar(@{$results->{rules}});
|
||||
$results = $options{custom}->request_api(url_path => '/directives');
|
||||
$self->{global}->{directives} = scalar(@{$results->{directives}});
|
||||
$results = $options{custom}->request_api(url_path => '/groups');
|
||||
$self->{global}->{groups} = scalar(@{$results->{groups}});
|
||||
$results = $options{custom}->request_api(url_path => '/techniques');
|
||||
$self->{global}->{techniques} = scalar(@{$results->{techniques}});
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check statistics.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-global-compliance>
|
||||
|
||||
Set warning threshold on global compliance.
|
||||
|
||||
=item B<--critical-global-compliance>
|
||||
|
||||
Set critical threshold on global compliance.
|
||||
|
||||
=item B<--warning-status>
|
||||
|
||||
Set warning threshold for status (Default: '').
|
||||
Can used special variables like: %{detail}, %{value}
|
||||
|
||||
=item B<--critical-status>
|
||||
|
||||
Set critical threshold for status (Default: '').
|
||||
Can used special variables like: %{detail}, %{value}
|
||||
|
||||
Example :
|
||||
--critical-status='%{detail} eq "error" && %{value} > 5'
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -31,8 +31,13 @@ sub new {
|
|||
|
||||
$self->{version} = '0.1';
|
||||
%{$self->{modes}} = (
|
||||
'global-compliance' => 'apps::rudder::restapi::mode::globalcompliance',
|
||||
'list-nodes' => 'apps::rudder::restapi::mode::listnodes',
|
||||
'global-compliance' => 'apps::rudder::restapi::mode::globalcompliance',
|
||||
'list-nodes' => 'apps::rudder::restapi::mode::listnodes',
|
||||
'list-rules' => 'apps::rudder::restapi::mode::listrules',
|
||||
'node-compliance' => 'apps::rudder::restapi::mode::nodecompliance',
|
||||
'nodes-overall-compliance' => 'apps::rudder::restapi::mode::nodesoverallcompliance',
|
||||
'rule-compliance' => 'apps::rudder::restapi::mode::rulecompliance',
|
||||
'statistics' => 'apps::rudder::restapi::mode::statistics',
|
||||
);
|
||||
|
||||
$self->{custom_modes}{api} = 'apps::rudder::restapi::custom::api';
|
||||
|
|
Loading…
Reference in New Issue