This commit is contained in:
garnier-quentin 2020-10-02 14:21:15 +02:00
parent 1a82b86189
commit ab154df5a7
5 changed files with 53 additions and 97 deletions

View File

@ -25,27 +25,25 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_sync_status_output {
my ($self, %options) = @_;
my $msg = sprintf(
return sprintf(
'sync status: %s [enabled: %s]',
$self->{result_values}->{status},
$self->{result_values}->{enabled}
);
return $msg;
}
sub custom_member_status_output {
my ($self, %options) = @_;
my $msg = sprintf(
return sprintf(
'state: %s',
$self->{result_values}->{state}
);
return $msg;
}
sub custom_member_status_calc {
@ -79,42 +77,40 @@ sub set_counters {
{ name => 'member', type => 3, cb_prefix_output => 'prefix_member_output', cb_long_output => 'member_long_output', indent_long_output => ' ', message_multiple => 'All members are ok',
group => [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
{ name => 'link', display_long => 1, cb_prefix_output => 'prefix_link_output', message_multiple => 'All links are ok', type => 1, skipped_code => { -10 => 1 } },
{ name => 'link', display_long => 1, cb_prefix_output => 'prefix_link_output', message_multiple => 'All links are ok', type => 1, skipped_code => { -10 => 1 } }
]
}
];
$self->{maps_counters}->{sync} = [
{ label => 'sync-status', threshold => 0, set => {
{ label => 'sync-status', type => 2, critical_default => '%{enabled} eq "yes" and %{status} ne "synchronized"', set => {
key_values => [ { name => 'enabled' }, { name => 'status'} ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_sync_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
}
];
$self->{maps_counters}->{global} = [
{ label => 'member-status', threshold => 0, set => {
{ label => 'member-status', type => 2, critical_default => '%{state} ne %{stateLast}', set => {
key_values => [ { name => 'state' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_member_status_calc'),
closure_custom_output => $self->can('custom_member_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
}
];
$self->{maps_counters}->{link} = [
{ label => 'link-status', threshold => 0, set => {
{ label => 'link-status', type => 2, critical_default => '%{status} ne "up"', set => {
key_values => [ { name => 'status' }, { name => 'display' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_link_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
}
];
}
@ -142,33 +138,11 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'unknown-member-status:s' => { name => 'unknown_member_status', default => '' },
'warning-member-status:s' => { name => 'warning_member_status', default => '' },
'critical-member-status:s' => { name => 'critical_member_status', default => '%{state} ne %{stateLast}' },
'unknown-link-status:s' => { name => 'unknown_link_status', default => '' },
'warning-link-status:s' => { name => 'warning_link_status', default => '' },
'critical-link-status:s' => { name => 'critical_link_status', default => '%{status} ne "up"' },
'unknown-sync-status:s' => { name => 'unknown_sync_status', default => '' },
'warning-sync-status:s' => { name => 'warning_sync_status', default => '' },
'critical-sync-status:s' => { name => 'critical_sync_status', default => '%{enabled} eq "yes" and %{status} ne "synchronized"' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(
macros => [
'unknown_sync_status', 'warning_sync_status', 'critical_sync_status',
'unknown_member_status', 'warning_member_status', 'critical_member_status',
'unknown_link_status', 'warning_link_status', 'critical_link_status'
]
);
}
sub manage_selection {
my ($self, %options) = @_;

View File

@ -25,17 +25,16 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
my $msg = sprintf(
return sprintf(
'state: %s [type: %s]',
$self->{result_values}->{state},
$self->{result_values}->{type}
);
return $msg;
}
sub set_counters {
@ -51,22 +50,21 @@ sub set_counters {
key_values => [ { name => 'total' } ],
output_template => 'total interfaces: %s',
perfdatas => [
{ value => 'total', template => '%s', min => 0 }
{ template => '%s', min => 0 }
]
}
},
];
$self->{maps_counters}->{interface} = [
{ label => 'status', threshold => 0, set => {
{ label => 'status', type => 2, critical_default => '%{state} ne "up"', set => {
key_values => [
{ name => 'state' }, { name => 'type' },
{ name => 'ha_state' }, { name => 'display' }
],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
@ -84,26 +82,12 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'unknown-status:s' => { name => 'unknown_status', default => '' },
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{state} ne "up"' }
'filter-name:s' => { name => 'filter_name' }
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(
macros => [
'unknown_status', 'warning_status', 'critical_status'
]
);
}
sub manage_selection {
my ($self, %options) = @_;

View File

@ -83,6 +83,7 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }
});
return $self;
@ -96,7 +97,13 @@ sub manage_selection {
$self->{global} = { total_ipsec => 0 };
$self->{tunnels} = {};
foreach (@{$result->{entry}}) {
$self->{tunnels}->{$_->{gwid}} = {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$_->{name} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $_->{name} . "': no matching filter.", debug => 1);
next;
}
$self->{tunnels}->{ $_->{gwid} } = {
display => $_->{name},
ike_phase1_state => defined($_->{created}) && $_->{created} ne '' ? 'up' : 'down',
monitor_status => 'unknown', # could be 'up', 'down', 'off'
@ -106,6 +113,8 @@ sub manage_selection {
$self->{global}->{total_ipsec}++;
}
return if ($self->{global}->{total_ipsec} == 0);
$result = $options{custom}->execute_command(command => 'show vpn ipsec-sa', ForceArray => ['entry']);
foreach (@{$result->{entries}->{entry}}) {
if (defined($self->{tunnels}->{$_->{gwid}})) {
@ -118,8 +127,8 @@ sub manage_selection {
next if (!defined($self->{tunnels}->{$gwid}->{tid}));
foreach (@{$result->{IPSec}->{entry}}) {
next if ($self->{tunnels}->{$gwid}->{tid} ne $_->{id});
$self->{tunnels}->{$_->{gwid}}->{state} = $_->{state};
$self->{tunnels}->{$_->{gwid}}->{monitor_status} = $_->{mon};
$self->{tunnels}->{ $_->{gwid} }->{state} = $_->{state};
$self->{tunnels}->{ $_->{gwid} }->{monitor_status} = $_->{mon};
}
}
}
@ -134,6 +143,10 @@ Check ipsec tunnels.
=over 8
=item B<--filter-name>
Filter tunnels by name (can be a regexp).
=item B<--unknown-status>
Set unknown threshold for status.

View File

@ -25,7 +25,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
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_status_output {
my ($self, %options) = @_;
@ -63,12 +63,12 @@ sub set_counters {
];
$self->{maps_counters}->{features} = [
{ label => 'status', threshold => 0, set => {
{ label => 'status', type => 2, critical_default => '%{expired} eq "yes"', set => {
key_values => [ { name => 'feature' }, { name => 'expired' }, { name => 'expiry_date' }, { name => 'expiry_seconds' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
];
@ -86,20 +86,11 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{expired} eq "yes"' },
});
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) = @_;

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
use DateTime;
use centreon::plugins::misc;
use Digest::MD5 qw(md5_hex);
@ -32,8 +32,7 @@ use Digest::MD5 qw(md5_hex);
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'system operational mode: ' . $self->{result_values}->{oper_mode};
return $msg;
return 'system operational mode: ' . $self->{result_values}->{oper_mode};
}
sub custom_av_output {
@ -64,28 +63,27 @@ sub set_counters {
];
$self->{maps_counters}->{system} = [
{ label => 'status', threshold => 0, set => {
{ label => 'status', type => 2, critical_default => '%{oper_mode} !~ /normal/i', set => {
key_values => [ { name => 'oper_mode' } ],
closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold,
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
},
{ label => 'av-update', nlabel => 'system.antivirus.lastupdate.time.seconds', set => {
key_values => [ { name => 'av_lastupdate_time' }, { name => 'av_version' } ],
closure_custom_output => $self->can('custom_av_output'),
perfdatas => [
{ value => 'av_lastupdate_time', template => '%d', min => 0, unit => 's' }
],
{ template => '%d', min => 0, unit => 's' }
]
}
},
{ label => 'threat-update', nlabel => 'system.threat.lastupdate.time.seconds', set => {
key_values => [ { name => 'threat_lastupdate_time' }, { name => 'threat_version' } ],
closure_custom_output => $self->can('custom_threat_output'),
perfdatas => [
{ value => 'threat_lastupdate_time', template => '%d', min => 0, unit => 's' }
],
{ template => '%d', min => 0, unit => 's' }
]
}
},
{ label => 'sessions-traffic', nlabel => 'system.sessions.traffic.count', set => {
@ -93,19 +91,18 @@ sub set_counters {
output_template => 'session traffic: %s %s/s',
output_change_bytes => 2,
perfdatas => [
{ value => 'throughput', template => '%s',
unit => 'b/s', min => 0 },
],
{ template => '%s', unit => 'b/s', min => 0 }
]
}
},
{ label => 'sessions-total-active', nlabel => 'system.sessions.total.active.count', display_ok => 0, set => {
key_values => [ { name => 'active_sessions' } ],
output_template => 'total active sessions: %s',
perfdatas => [
{ value => 'active_sessions', template => '%s', min => 0 },
],
{ template => '%s', min => 0 }
]
}
},
}
];
}
@ -114,10 +111,8 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'warning-status:s' => { name => 'warning_status', default => '' },
'critical-status:s' => { name => 'critical_status', default => '%{oper_mode} !~ /normal/i' },
'timezone:s' => { name => 'timezone' }
$options{options}->add_options(arguments => {
'timezone:s' => { name => 'timezone' }
});
return $self;
@ -127,7 +122,6 @@ sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
$self->{option_results}->{timezone} = 'GMT' if (!defined($self->{option_results}->{timezone}) || $self->{option_results}->{timezone} eq '');
}