enhance udp con
This commit is contained in:
parent
21a1ca76f0
commit
cb4c23e5cc
|
@ -39,13 +39,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 => {
|
||||||
{
|
'warning:s' => { name => 'warning', },
|
||||||
"warning:s" => { name => 'warning', },
|
'critical:s' => { name => 'critical', },
|
||||||
"critical:s" => { name => 'critical', },
|
'service:s@' => { name => 'service', },
|
||||||
"service:s@" => { name => 'service', },
|
'application:s@' => { name => 'application', },
|
||||||
"application:s@" => { name => 'application', },
|
});
|
||||||
});
|
|
||||||
@{$self->{connections}} = ();
|
@{$self->{connections}} = ();
|
||||||
$self->{services} = { total => { filter => '.*?#.*?#.*?', builtin => 1, number => 0, msg => 'Total connections: %d' } };
|
$self->{services} = { total => { filter => '.*?#.*?#.*?', builtin => 1, number => 0, msg => 'Total connections: %d' } };
|
||||||
$self->{applications} = {};
|
$self->{applications} = {};
|
||||||
|
@ -74,9 +74,11 @@ sub get_from_rfc4022 {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $oid_udpListenerProcess = '.1.3.6.1.2.1.7.7.1.8';
|
my $oid_udpListenerProcess = '.1.3.6.1.2.1.7.7.1.8';
|
||||||
my $results = $self->{snmp}->get_multiple_table(oids => [
|
my $results = $self->{snmp}->get_multiple_table(
|
||||||
{ oid => $oid_udpListenerProcess },
|
oids => [
|
||||||
]);
|
{ oid => $oid_udpListenerProcess },
|
||||||
|
]
|
||||||
|
);
|
||||||
return 0 if (scalar(keys %{$results->{$oid_udpListenerProcess}}) == 0);
|
return 0 if (scalar(keys %{$results->{$oid_udpListenerProcess}}) == 0);
|
||||||
|
|
||||||
# Listener
|
# Listener
|
||||||
|
@ -137,11 +139,14 @@ sub check_services {
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{services}->{$tag} = { filter => ((defined($ipv) && $ipv ne '') ? $ipv : '.*?') . '#' .
|
$self->{services}->{$tag} = {
|
||||||
((defined($filter_ip) && $filter_ip ne '') ? $filter_ip : '.*?') . '#' .
|
filter =>
|
||||||
((defined($port) && $port ne '') ? $port : '.*?'),
|
((defined($ipv) && $ipv ne '') ? $ipv : '.*?') . '#' .
|
||||||
builtin => 0,
|
((defined($filter_ip) && $filter_ip ne '') ? $filter_ip : '.*?') . '#' .
|
||||||
number => 0 };
|
((defined($port) && $port ne '') ? $port : '.*?'),
|
||||||
|
builtin => 0,
|
||||||
|
number => 0
|
||||||
|
};
|
||||||
if (($self->{perfdata}->threshold_validate(label => 'warning-service-' . $tag, value => $warn)) == 0) {
|
if (($self->{perfdata}->threshold_validate(label => 'warning-service-' . $tag, value => $warn)) == 0) {
|
||||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $warn . "' for service '$tag'.");
|
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $warn . "' for service '$tag'.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
|
@ -168,9 +173,7 @@ sub check_applications {
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{applications}->{$tag} = {
|
$self->{applications}->{$tag} = { services => {} };
|
||||||
services => {},
|
|
||||||
};
|
|
||||||
foreach my $service (split /\|/, $services) {
|
foreach my $service (split /\|/, $services) {
|
||||||
if (!defined($self->{services}->{$service})) {
|
if (!defined($self->{services}->{$service})) {
|
||||||
$self->{output}->add_option_msg(short_msg => "Service '" . $service . "' is not defined.");
|
$self->{output}->add_option_msg(short_msg => "Service '" . $service . "' is not defined.");
|
||||||
|
@ -200,20 +203,28 @@ sub test_services {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $exit_code = $self->{perfdata}->threshold_check(value => $self->{services}->{$tag}->{number},
|
my $exit_code = $self->{perfdata}->threshold_check(
|
||||||
threshold => [ { label => 'critical-service-' . $tag, 'exit_litteral' => 'critical' }, { label => 'warning-service-' . $tag, exit_litteral => 'warning' } ]);
|
value => $self->{services}->{$tag}->{number},
|
||||||
my ($perf_label, $msg) = ('service_' . $tag, "Service '$tag' connections: %d");
|
threshold => [ { label => 'critical-service-' . $tag, 'exit_litteral' => 'critical' }, { label => 'warning-service-' . $tag, exit_litteral => 'warning' } ]
|
||||||
|
);
|
||||||
|
my $msg = "Service '$tag' connections: %d";
|
||||||
if ($self->{services}->{$tag}->{builtin} == 1) {
|
if ($self->{services}->{$tag}->{builtin} == 1) {
|
||||||
($perf_label, $msg) = ($tag, $self->{services}->{$tag}->{msg});
|
$msg = $self->{services}->{$tag}->{msg};
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->output_add(severity => $exit_code,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf($msg, $self->{services}->{$tag}->{number}));
|
severity => $exit_code,
|
||||||
$self->{output}->perfdata_add(label => $perf_label,
|
short_msg => sprintf($msg, $self->{services}->{$tag}->{number})
|
||||||
value => $self->{services}->{$tag}->{number},
|
);
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-service-' . $tag),
|
$self->{output}->perfdata_add(
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-service-' . $tag),
|
label => 'service',
|
||||||
min => 0);
|
nlabel => 'service.connections.udp.count',
|
||||||
|
instances => $tag,
|
||||||
|
value => $self->{services}->{$tag}->{number},
|
||||||
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-service-' . $tag),
|
||||||
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-service-' . $tag),
|
||||||
|
min => 0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,15 +238,23 @@ sub test_applications {
|
||||||
$number += $self->{services}->{$_}->{number};
|
$number += $self->{services}->{$_}->{number};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $exit_code = $self->{perfdata}->threshold_check(value => $number,
|
my $exit_code = $self->{perfdata}->threshold_check(
|
||||||
threshold => [ { label => 'critical-app-' . $tag, 'exit_litteral' => 'critical' }, { label => 'warning-app-' . $tag, exit_litteral => 'warning' } ]);
|
value => $number,
|
||||||
$self->{output}->output_add(severity => $exit_code,
|
threshold => [ { label => 'critical-app-' . $tag, 'exit_litteral' => 'critical' }, { label => 'warning-app-' . $tag, exit_litteral => 'warning' } ]
|
||||||
short_msg => sprintf("Applicatin '%s' connections: %d", $tag, $number));
|
);
|
||||||
$self->{output}->perfdata_add(label => 'app_' . $tag,
|
$self->{output}->output_add(
|
||||||
value => $number,
|
severity => $exit_code,
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-app-' . $tag),
|
short_msg => sprintf("Applicatin '%s' connections: %d", $tag, $number)
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-app-' . $tag),
|
);
|
||||||
min => 0);
|
$self->{output}->perfdata_add(
|
||||||
|
label => 'app',
|
||||||
|
nlabel => 'application.connections.udp.count',
|
||||||
|
instances => $tag,
|
||||||
|
value => $number,
|
||||||
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-app-' . $tag),
|
||||||
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-app-' . $tag),
|
||||||
|
min => 0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,9 +283,12 @@ sub run {
|
||||||
$self->test_applications();
|
$self->test_applications();
|
||||||
|
|
||||||
foreach (keys %{$self->{states}}) {
|
foreach (keys %{$self->{states}}) {
|
||||||
$self->{output}->perfdata_add(label => 'con_' . $_,
|
$self->{output}->perfdata_add(
|
||||||
value => $self->{states}->{$_},
|
label => 'con_' . $_,
|
||||||
min => 0);
|
nlabel => 'connections.udp.' . lc($_) . '.count',
|
||||||
|
value => $self->{states}->{$_},
|
||||||
|
min => 0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
|
|
Loading…
Reference in New Issue