This commit is contained in:
Colin Gagnaire 2019-08-02 11:18:12 +02:00
commit 33a8c57a2c
4 changed files with 158 additions and 54 deletions

View File

@ -25,6 +25,67 @@ use base qw(snmp_standard::mode::interfaces);
use strict;
use warnings;
sub custom_status_output {
my ($self, %options) = @_;
my $msg = 'Status : ' . $self->{result_values}->{opstatus} . ' (admin: ' . $self->{result_values}->{admstatus} . ')';
if (defined($self->{instance_mode}->{option_results}->{add_duplex_status})) {
$msg .= ' (duplex: ' . $self->{result_values}->{duplexstatus} . ')';
}
if (defined($self->{instance_mode}->{option_results}->{add_err_disable})) {
$msg .= ' (error disable: ' . $self->{result_values}->{errdisable} . ')';
}
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->SUPER::custom_status_calc(%options);
$self->{result_values}->{errdisable} = $options{new_datas}->{$self->{instance} . '_errdisable'};
return 0;
}
sub set_key_values_status {
my ($self, %options) = @_;
return [ { name => 'opstatus' }, { name => 'admstatus' }, { name => 'duplexstatus' }, { name => 'errdisable' }, { name => 'display' } ];
}
sub set_oids_status {
my ($self, %options) = @_;
$self->SUPER::set_oids_status(%options);
$self->{oid_cErrDisableIfStatusCause} = '.1.3.6.1.4.1.9.9.548.1.3.1.1.2';
$self->{oid_cErrDisableIfStatusCause_mapping} = {
1 => 'udld', 2 => 'bpduGuard', 3 => 'channelMisconfig',
4 => 'pagpFlap', 5 => 'dtpFlap', 6 => 'linkFlap',
7 => 'l2ptGuard', 8 => 'dot1xSecurityViolation',
9 => 'portSecurityViolation', 10 => 'gbicInvalid',
11 => 'dhcpRateLimit', 12 => 'unicastFlood',
13 => 'vmps', 14 => 'stormControl', 15 => 'inlinePower',
16 => 'arpInspection', 17 => 'portLoopback',
18 => 'packetBuffer', 19 => 'macLimit', 20 => 'linkMonitorFailure',
21 => 'oamRemoteFailure', 22 => 'dot1adIncompEtype', 23 => 'dot1adIncompTunnel',
24 => 'sfpConfigMismatch', 25 => 'communityLimit', 26 => 'invalidPolicy',
27 => 'lsGroup', 28 => 'ekey', 29 => 'portModeFailure',
30 => 'pppoeIaRateLimit', 31 => 'oamRemoteCriticalEvent',
32 => 'oamRemoteDyingGasp', 33 => 'oamRemoteLinkFault',
34 => 'mvrp', 35 => 'tranceiverIncomp', 36 => 'other',
37 => 'portReinitLimitReached', 38 => 'adminRxBBCreditPerfBufIncomp',
39 => 'ficonNotEnabled', 40 => 'adminModeIncomp', 41 => 'adminSpeedIncomp',
42 => 'adminRxBBCreditIncomp', 43 => 'adminRxBufSizeIncomp',
44 => 'eppFailure', 45 => 'osmEPortUp', 46 => 'osmNonEPortUp',
47 => 'udldUniDir', 48 => 'udldTxRxLoop', 49 => 'udldNeighbourMismatch',
50 => 'udldEmptyEcho', 51 => 'udldAggrasiveModeLinkFailed',
52 => 'excessivePortInterrupts', 53 => 'channelErrDisabled',
54 => 'hwProgFailed', 55 => 'internalHandshakeFailed',
56 => 'stpInconsistencyOnVpcPeerLink', 57 => 'stpPortStateFailure',
58 => 'ipConflict', 59 => 'multipleMSapIdsRcvd',
60 => 'oneHundredPdusWithoutAck', 61 => 'ipQosCompatCheckFailure',
};
}
sub set_oids_errors {
my ($self, %options) = @_;
@ -56,7 +117,11 @@ sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
'add-err-disable' => { name => 'add_err_disable' },
});
return $self;
}
@ -74,6 +139,15 @@ sub load_errors {
);
}
sub load_status {
my ($self, %options) = @_;
$self->SUPER::load_status(%options);
if (defined($self->{option_results}->{add_err_disable})) {
$self->{snmp_errdisable_result} = $self->{snmp}->get_table(oid => $self->{oid_cErrDisableIfStatusCause});
}
}
sub add_result_errors {
my ($self, %options) = @_;
@ -84,6 +158,31 @@ sub add_result_errors {
$self->{int}->{$options{instance}}->{incrc} = $self->{results}->{$self->{oid_ifInCrc} . '.' . $options{instance}};
}
sub add_result_status {
my ($self, %options) = @_;
$self->SUPER::add_result_status(%options);
$self->{int}->{$options{instance}}->{errdisable} = '';
if (defined($self->{option_results}->{add_err_disable})) {
my $append = '';
# ifIndex.vlanIndex (if physical interface, vlanIndex = 0)
foreach (keys %{$self->{snmp_errdisable_result}}) {
next if (! /^$self->{oid_cErrDisableIfStatusCause}\.$options{instance}\.(.*)/);
if ($1 == 0) {
$self->{int}->{$options{instance}}->{errdisable} = $self->{oid_cErrDisableIfStatusCause_mapping}->{ $self->{snmp_errdisable_result}->{$_} };
last;
}
$self->{int}->{$options{instance}}->{errdisable} .= $append . 'vlan' . $1 . ':' . $self->{oid_cErrDisableIfStatusCause_mapping}->{ $self->{snmp_errdisable_result}->{$_} };
$append = ',';
}
}
$self->{int}->{$options{instance}}->{errdisable} = '-'
if ($self->{int}->{$options{instance}}->{errdisable} eq '');
}
1;
__END__
@ -106,6 +205,10 @@ Check interface status.
Check duplex status (with --warning-status and --critical-status).
=item B<--add-err-disable>
Check error disable (with --warning-status and --critical-status).
=item B<--add-traffic>
Check interface traffic.
@ -129,24 +232,16 @@ Check interface data volume between two checks (not supposed to be graphed, usef
=item B<--warning-status>
Set warning threshold for status.
Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display}
Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{errdisable}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{admstatus} eq "up" and %{opstatus} ne "up"').
Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{display}
Can used special variables like: %{admstatus}, %{opstatus}, %{duplexstatus}, %{errdisable}, %{display}
=item B<--warning-*>
=item B<--warning-*> B<--critical-*>
Threshold warning.
Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down',
'in-traffic', 'out-traffic', 'in-crc', 'in-error', 'in-discard', 'out-error', 'out-discard',
'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%),
'speed' (b/s).
=item B<--critical-*>
Threshold critical.
Thresholds.
Can be: 'total-port', 'total-admin-up', 'total-admin-down', 'total-oper-up', 'total-oper-down',
'in-traffic', 'out-traffic', 'in-crc', 'in-error', 'in-discard', 'out-error', 'out-discard',
'in-ucast' (%), 'in-bcast' (%), 'in-mcast' (%), 'out-ucast' (%), 'out-bcast' (%), 'out-mcast' (%),

View File

@ -5,6 +5,7 @@
<disconnected>Total sessions disconnected</disconnected>
<reconnected>Total sessions reconnected</reconnected>
<activestate>Active</activestate>
<disconnectedstate>Disc</disconnectedstate>
<header_sessionname>SESSIONNAME</header_sessionname>
<header_state>STATE</header_state>
</qwinsta>
@ -13,6 +14,7 @@
<disconnected>Nombre total de sessions d.*?connect.*?es</disconnected>
<reconnected>Nombre total de sessions reconnect.*?es</reconnected>
<activestate>Actif</activestate>
<disconnectedstate>D.*?co</disconnectedstate>
<header_sessionname>SESSION</header_sessionname>
<header_state>^.*?TAT</header_state>
</qwinsta>

View File

@ -35,38 +35,47 @@ sub set_counters {
];
$self->{maps_counters}->{global} = [
{ label => 'sessions-created', set => {
{ label => 'sessions-created', nlabel => 'sessions.created.total.count', set => {
key_values => [ { name => 'sessions_created', diff => 1 } ],
output_template => 'Created : %s',
output_template => 'created : %s',
perfdatas => [
{ label => 'sessions_created', value => 'sessions_created_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'sessions-disconnected', set => {
{ label => 'sessions-disconnected', nlabel => 'sessions.disconnected.total.count', set => {
key_values => [ { name => 'sessions_disconnected', diff => 1 } ],
output_template => 'Disconnected : %s',
output_template => 'disconnected : %s',
perfdatas => [
{ label => 'sessions_disconnected', value => 'sessions_disconnected_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'sessions-reconnected', set => {
{ label => 'sessions-reconnected', nlabel => 'sessions.reconnected.total.count', set => {
key_values => [ { name => 'sessions_reconnected', diff => 1 } ],
output_template => 'Reconnected : %s',
output_template => 'reconnected : %s',
perfdatas => [
{ label => 'sessions_reconnected', value => 'sessions_reconnected_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'sessions-active', set => {
{ label => 'sessions-active', nlabel => 'sessions.active.current.count', set => {
key_values => [ { name => 'sessions_active' } ],
output_template => 'Active : %s',
output_template => 'current active : %s',
perfdatas => [
{ label => 'sessions_active', value => 'sessions_active_absolute', template => '%s', min => 0 },
],
}
},
{ label => 'sessions-disconnected-current', nlabel => 'sessions.disconnected.current.count', set => {
key_values => [ { name => 'sessions_disconnected_current' } ],
output_template => 'current disconnected : %s',
perfdatas => [
{ label => 'sessions_disconnected_current', value => 'sessions_disconnected_current_absolute',
template => '%s', min => 0 },
],
}
},
];
}
@ -81,16 +90,15 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$options{options}->add_options(arguments =>
{
"command:s" => { name => 'command', default => 'qwinsta' },
"command-path:s" => { name => 'command_path' },
"command-options:s" => { name => 'command_options', default => '/COUNTER' },
"timeout:s" => { name => 'timeout', default => 30 },
"filter-sessionname:s" => { name => 'filter_sessionname' },
"config:s" => { name => 'config' },
"language:s" => { name => 'language', default => 'en' },
});
$options{options}->add_options(arguments => {
'command:s' => { name => 'command', default => 'qwinsta' },
'command-path:s' => { name => 'command_path' },
'command-options:s' => { name => 'command_options', default => '/COUNTER' },
'timeout:s' => { name => 'timeout', default => 30 },
'filter-sessionname:s' => { name => 'filter_sessionname' },
'config:s' => { name => 'config' },
'language:s' => { name => 'language', default => 'en' },
});
return $self;
}
@ -203,16 +211,18 @@ sub manage_selection {
my ($self, %options) = @_;
my $config = $self->read_config();
my ($stdout) = centreon::plugins::misc::execute(output => $self->{output},
options => $self->{option_results},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options});
my ($stdout) = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results},
command => $self->{option_results}->{command},
command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}
);
my $datas = $self->read_qwinsta(stdout => $stdout, config => $config);
my $counters = $self->read_qwinsta_counters(stdout => $stdout, config => $config);
my $active = 0;
my ($active, $disconnected) = (0, 0);
foreach my $session (@$datas) {
if (defined($self->{option_results}->{filter_sessionname}) && $self->{option_results}->{filter_sessionname} ne '' &&
$session->{$config->{header_sessionname}} !~ /$self->{option_results}->{filter_sessionname}/) {
@ -220,21 +230,24 @@ sub manage_selection {
next;
}
my $matching = 0;
my ($matching_active, $matching_discon) = (0, 0);
foreach my $label (keys %$session) {
$matching = 1 if ($label =~ /$config->{header_state}/ &&
$session->{$label} =~ /$config->{activestate}/);
$matching_active = 1 if ($label =~ /$config->{header_state}/ &&
$session->{$label} =~ /$config->{activestate}/);
$matching_discon = 1 if ($label =~ /$config->{header_state}/ &&
$session->{$label} =~ /$config->{disconnectedstate}/);
}
if ($matching == 1) {
$active++;
if ($matching_active == 1 || $matching_discon == 1) {
$active++ if ($matching_active == 1);
$disconnected++ if ($matching_discon == 1);
my $output = '';
$output .= " [$_ => $session->{$_}]" for (sort keys %$session);
$self->{output}->output_add(long_msg => $output);
}
}
$self->{global} = { %$counters, sessions_active => $active };
$self->{global} = { %$counters, sessions_active => $active, sessions_disconnected_current => $disconnected };
$self->{cache_name} = "windows_" . $self->{mode} . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
@ -281,17 +294,11 @@ Timeout in seconds for the command (Default: 30).
Filter session name (can be a regexp).
=item B<--warning-*>
=item B<--warning-*> B<--critical-*>
Threshold warning.
Thresholds.
Can be: 'sessions-created', 'sessions-disconnected',
'sessions-reconnected', 'sessions-active'.
=item B<--critical-*>
Threshold critical.
Can be: 'sessions-created', 'sessions-disconnected',
'sessions-reconnected', 'sessions-active'.
'sessions-reconnected', 'sessions-active', 'sessions-disconnected-current'.
=back

View File

@ -65,13 +65,13 @@ sub custom_status_output {
if (defined($self->{instance_mode}->{option_results}->{add_duplex_status})) {
$msg .= ' (duplex: ' . $self->{result_values}->{duplexstatus} . ')';
}
return $msg;
}
sub custom_status_calc {
my ($self, %options) = @_;
$self->{result_values}->{opstatus} = $options{new_datas}->{$self->{instance} . '_opstatus'};
$self->{result_values}->{admstatus} = $options{new_datas}->{$self->{instance} . '_admstatus'};
$self->{result_values}->{duplexstatus} = $options{new_datas}->{$self->{instance} . '_duplexstatus'};