mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-29 00:24:46 +02:00
update azure alert
This commit is contained in:
parent
94ab380be1
commit
ef2d0aea14
@ -25,20 +25,13 @@ use base qw(centreon::plugins::templates::counter);
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
sub custom_calc {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
$self->{result_values}->{severity} = $options{new_datas}->{$self->{instance} . '_severity'};
|
|
||||||
$self->{result_values}->{count} = $options{new_datas}->{$self->{instance} . '_count'};
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub custom_output {
|
sub custom_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
return sprintf("Alert severity: '%s', Count: '%d'",
|
return sprintf(
|
||||||
$self->{result_values}->{severity},
|
"alert severity: '%s', Count: '%d'",
|
||||||
$self->{result_values}->{count}
|
$self->{result_values}->{severity_absolute},
|
||||||
|
$self->{result_values}->{count_absolute}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,37 +39,26 @@ sub custom_perfdata {
|
|||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{output}->perfdata_add(
|
$self->{output}->perfdata_add(
|
||||||
label => $self->{result_values}->{severity},
|
nlabel => 'alerts.' . $self->{result_values}->{severity_aboluste} . '.count',
|
||||||
value => $self->{result_values}->{count},
|
value => $self->{result_values}->{count_absolute},
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub custom_threshold_check {
|
|
||||||
my ($self, %options) = @_;
|
|
||||||
|
|
||||||
my $exit = $self->{perfdata}->threshold_check(
|
|
||||||
value => $self->{result_values}->{count},
|
|
||||||
threshold => [ { label => 'critical', exit_litteral => 'critical' },
|
|
||||||
{ label => 'warning', exit_litteral => 'warning' } ]);
|
|
||||||
return $exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub set_counters {
|
sub set_counters {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{maps_counters_type} = [
|
$self->{maps_counters_type} = [
|
||||||
{ name => 'alert', type => 1, message_multiple => 'All alert are ok' },
|
{ name => 'alert', type => 1, message_multiple => 'All alerts are ok' },
|
||||||
];
|
];
|
||||||
|
|
||||||
$self->{maps_counters}->{alert} = [
|
$self->{maps_counters}->{alert} = [
|
||||||
{ label => 'severity', threshold => 0, set => {
|
{ label => 'count', set => {
|
||||||
key_values => [ { name => 'severity' }, { name => 'count' } ],
|
key_values => [ { name => 'severity' }, { name => 'count' } ],
|
||||||
closure_custom_calc => $self->can('custom_calc'),
|
|
||||||
closure_custom_output => $self->can('custom_output'),
|
closure_custom_output => $self->can('custom_output'),
|
||||||
|
threshold_use => 'count_absolute',
|
||||||
closure_custom_perfdata => $self->can('custom_perfdata'),
|
closure_custom_perfdata => $self->can('custom_perfdata'),
|
||||||
closure_custom_threshold_check => $self->can('custom_threshold_check'),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -84,19 +66,17 @@ sub set_counters {
|
|||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments => {
|
$options{options}->add_options(arguments => {
|
||||||
"resource:s" => { name => 'resource' },
|
'resource:s' => { name => 'resource' },
|
||||||
"resource-group:s" => { name => 'resource_group' },
|
'resource-group:s' => { name => 'resource_group', default => '' },
|
||||||
"group-by:s" => { name => 'group_by', default => 'severity' },
|
'group-by:s' => { name => 'group_by', default => 'severity' },
|
||||||
"time-range:s" => { name => 'time_range', default => '1h' },
|
'time-range:s' => { name => 'time_range', default => '1h' },
|
||||||
"warning:s" => { name => 'warning', default => '' },
|
'filter:s' => { name => 'filter', default => '.*' },
|
||||||
"critical:s" => { name => 'critical', default => '' },
|
|
||||||
"filter:s" => { name => 'filter', default => '.*' },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,25 +85,15 @@ sub check_options {
|
|||||||
$self->SUPER::check_options(%options);
|
$self->SUPER::check_options(%options);
|
||||||
|
|
||||||
$self->{option_results}->{api_version} = '2018-05-05';
|
$self->{option_results}->{api_version} = '2018-05-05';
|
||||||
|
if (!defined($self->{option_results}->{resource}) || $self->{option_results}->{resource} eq '') {
|
||||||
if (!defined($self->{option_results}->{resource})) {
|
|
||||||
$self->{output}->add_option_msg(short_msg => "Need to specify either --resource <name> with --resource-group option or --resource <id>.");
|
$self->{output}->add_option_msg(short_msg => "Need to specify either --resource <name> with --resource-group option or --resource <id>.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{az_resource} = $self->{option_results}->{resource};
|
$self->{az_resource} = $self->{option_results}->{resource};
|
||||||
$self->{az_resource_group} = $self->{option_results}->{resource_group} if (defined($self->{option_results}->{resource_group}));
|
$self->{az_resource_group} = $self->{option_results}->{resource_group} if (defined($self->{option_results}->{resource_group}));
|
||||||
$self->{az_group_by} = $self->{option_results}->{group_by} if ($self->{option_results}->{group_by} =~ /^(alertRule|alertState|monitorCondition|monitorService|severity|signalType)$/i);
|
$self->{az_group_by} = $self->{option_results}->{group_by} if ($self->{option_results}->{group_by} =~ /^(alertRule|alertState|monitorCondition|monitorService|severity|signalType)$/i);
|
||||||
$self->{az_time_range} = $self->{option_results}->{time_range} if ($self->{option_results}->{time_range} =~ /^(1d|1h|30d|7d)$/);
|
$self->{az_time_range} = $self->{option_results}->{time_range} if ($self->{option_results}->{time_range} =~ /^(1d|1h|30d|7d)$/);
|
||||||
|
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
|
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
|
|
||||||
$self->{output}->option_exit();
|
|
||||||
}
|
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
|
||||||
$self->{output}->option_exit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
@ -163,8 +133,7 @@ __END__
|
|||||||
|
|
||||||
=head1 MODE
|
=head1 MODE
|
||||||
|
|
||||||
Check check alert count.
|
Check alerts.
|
||||||
|
|
||||||
|
|
||||||
=over 8
|
=over 8
|
||||||
|
|
||||||
@ -180,13 +149,10 @@ Set resource group (Required if resource's name is used).
|
|||||||
|
|
||||||
Filter on alert name Can be a regexp).
|
Filter on alert name Can be a regexp).
|
||||||
|
|
||||||
=item B<--warning>
|
=item B<--warning-*> B<--critical-*>
|
||||||
|
|
||||||
Thresholds warning.
|
Thresholds.
|
||||||
|
Can be: 'count'.
|
||||||
=item B<--critical>
|
|
||||||
|
|
||||||
Thresholds critical.
|
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user