enhance indent

This commit is contained in:
garnier-quentin 2019-10-24 09:27:52 +02:00
parent c481f00618
commit c415e4ed64
8 changed files with 206 additions and 145 deletions

View File

@ -30,12 +30,11 @@ 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' }, 'units:s' => { name => 'units', default => 'absolute' },
"units:s" => { name => 'units', default => 'absolute' }, });
});
return $self; return $self;
} }
@ -82,15 +81,18 @@ sub run {
my $exit = $self->{perfdata}->threshold_check(value => $value, my $exit = $self->{perfdata}->threshold_check(value => $value,
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(
short_msg => sprintf("Connections: %d%s", $result->{$oid_fwNumCom}, $extra)); severity => $exit,
$self->{output}->perfdata_add(label => "connections", unit => 'con', short_msg => sprintf("Connections: %d%s", $result->{$oid_fwNumCom}, $extra)
value => $result->{$oid_fwNumCom}, );
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', %total_options), $self->{output}->perfdata_add(
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', %total_options), label => "connections", unit => 'con',
min => 0 value => $result->{$oid_fwNumCom},
); warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', %total_options),
min => 0
);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }

View File

@ -30,11 +30,10 @@ 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', }, });
});
return $self; return $self;
} }
@ -90,7 +89,6 @@ sub run {
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0, max => 100); min => 0, max => 100);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }

View File

@ -41,13 +41,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 => {
{ 'label:s' => { name => 'label' },
"label:s" => { name => 'label' }, 'command:s' => { name => 'command' },
"command:s" => { name => 'command' }, 'args:s' => { name => 'args' },
"args:s" => { name => 'args' }, 'shell' => { name => 'shell' },
"shell" => { name => 'shell' }, });
});
return $self; return $self;
} }
@ -95,13 +95,13 @@ sub create_command {
sub update_command { sub update_command {
my ($self, %options) = @_; my ($self, %options) = @_;
my $shell = defined($self->{option_results}->{shell}) ? 2 : 1; my $shell = defined($self->{option_results}->{shell}) ? 2 : 1;
# Cannot change values # Cannot change values
if ($options{result}->{$oid_nsExtendStorage . '.' . $options{instance}} != 2) { if ($options{result}->{$oid_nsExtendStorage . '.' . $options{instance}} != 2) {
$self->{output}->add_option_msg(short_msg => "Command label '" . $self->{option_results}->{label} . "' is not volatile. So we can't manage it."); $self->{output}->add_option_msg(short_msg => "Command label '" . $self->{option_results}->{label} . "' is not volatile. So we can't manage it.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
my $oids2set = {}; my $oids2set = {};
if (!defined($options{result}->{$oid_nsExtendCommand . '.' . $options{instance}}) || if (!defined($options{result}->{$oid_nsExtendCommand . '.' . $options{instance}}) ||
$options{result}->{$oid_nsExtendCommand . '.' . $options{instance}} ne $self->{option_results}->{command}) { $options{result}->{$oid_nsExtendCommand . '.' . $options{instance}} ne $self->{option_results}->{command}) {
@ -124,32 +124,41 @@ sub update_command {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{snmp} = $options{snmp}; $self->{snmp} = $options{snmp};
$self->{hostname} = $self->{snmp}->get_hostname();
# snmpset -On -c test -v 2c localhost \ # snmpset -On -c test -v 2c localhost \
# '.1.3.6.1.4.1.8072.1.3.2.2.1.21.4.104.102.101.102' = 4 \ # '.1.3.6.1.4.1.8072.1.3.2.2.1.21.4.104.102.101.102' = 4 \
# '.1.3.6.1.4.1.8072.1.3.2.2.1.2.4.104.102.101.102' = /bin/echo \ # '.1.3.6.1.4.1.8072.1.3.2.2.1.2.4.104.102.101.102' = /bin/echo \
# '.1.3.6.1.4.1.8072.1.3.2.2.1.3.4.104.102.101.102' = 'myplop' # '.1.3.6.1.4.1.8072.1.3.2.2.1.3.4.104.102.101.102' = 'myplop'
# #
my $instance = $self->get_instance(); my $instance = $self->get_instance();
$self->{snmp}->load(oids => [$oid_nsExtendArgs, $oid_nsExtendStatus, $self->{snmp}->load(
$oid_nsExtendCommand, $oid_nsExtendStorage, $oid_nsExtendExecType], oids => [
instances => [$instance], $oid_nsExtendArgs, $oid_nsExtendStatus,
instance_regexp => '^(.+)$'); $oid_nsExtendCommand, $oid_nsExtendStorage, $oid_nsExtendExecType
],
instances => [$instance],
instance_regexp => '^(.+)$'
);
my $result = $self->{snmp}->get_leef(); my $result = $self->{snmp}->get_leef();
if (!defined($result->{$oid_nsExtendCommand . '.' . $instance})) { if (!defined($result->{$oid_nsExtendCommand . '.' . $instance})) {
$self->create_command(instance => $instance); $self->create_command(instance => $instance);
} else { } else {
$self->update_command(result => $result, instance => $instance); $self->update_command(result => $result, instance => $instance);
} }
$result = $self->{snmp}->get_leef(oids => [$oid_nsExtendOutputFull . '.' . $instance, $result = $self->{snmp}->get_leef(
$oid_nsExtendResult . '.' . $instance], nothing_quit => 1); oids => [
$oid_nsExtendOutputFull . '.' . $instance,
$oid_nsExtendResult . '.' . $instance
],
nothing_quit => 1
);
$self->{output}->output_add(severity => $self->{output}->get_litteral_status(status => $result->{$oid_nsExtendResult . '.' . $instance}), $self->{output}->output_add(
short_msg => $result->{$oid_nsExtendOutputFull . '.' . $instance}); severity => $self->{output}->get_litteral_status(status => $result->{$oid_nsExtendResult . '.' . $instance}),
short_msg => $result->{$oid_nsExtendOutputFull . '.' . $instance}
);
$self->{output}->display(force_ignore_perfdata => 1); $self->{output}->display(force_ignore_perfdata => 1);
$self->{output}->exit(); $self->{output}->exit();
} }

View File

@ -50,10 +50,9 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'sensor-scale' => { name => 'sensor_scale' },
"sensor-scale" => { name => 'sensor_scale' }, });
});
return $self; return $self;
} }
@ -207,9 +206,15 @@ sub check {
} }
$self->{components}->{sensor}->{total}++; $self->{components}->{sensor}->{total}++;
$self->{output}->output_add(long_msg => sprintf("sensor '%s' status is '%s' [instance = %s, value = %s]", $self->{output}->output_add(
$name, $result->{entPhySensorOperStatus}, $result->{entPhySensorType} . '.' . $instance, long_msg => sprintf(
defined($result->{entPhySensorValue}) ? $result->{entPhySensorValue} : '-')); "sensor '%s' status is '%s' [instance = %s, value = %s]",
$name,
$result->{entPhySensorOperStatus},
$result->{entPhySensorType} . '.' . $instance,
defined($result->{entPhySensorValue}) ? $result->{entPhySensorValue} : '-'
)
);
my $exit = $self->get_severity(label => 'sensor', section => 'sensor.' . $result->{entPhySensorType}, value => $result->{entPhySensorOperStatus}); my $exit = $self->get_severity(label => 'sensor', section => 'sensor.' . $result->{entPhySensorType}, value => $result->{entPhySensorOperStatus});
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(severity => $exit,
@ -221,13 +226,23 @@ sub check {
my $component = 'sensor.' . $result->{entPhySensorType}; my $component = 'sensor.' . $result->{entPhySensorType};
my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => $component, instance => $instance, value => $result->{entPhySensorValue}); my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => $component, instance => $instance, value => $result->{entPhySensorValue});
if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit2, $self->{output}->output_add(
short_msg => sprintf("Sensor '%s/%s' is %s %s", $name, $instance, $result->{entPhySensorValue}, $perfdata_unit{$result->{entPhySensorType}})); severity => $exit2,
short_msg => sprintf(
"Sensor '%s/%s' is %s %s",
$name,
$instance,
$result->{entPhySensorValue},
$perfdata_unit{$result->{entPhySensorType}}
)
);
} }
$self->{output}->perfdata_add(label => $component . '_' . $name, unit => $perfdata_unit{$result->{entPhySensorType}}, $self->{output}->perfdata_add(
value => $result->{entPhySensorValue}, label => $component . '_' . $name, unit => $perfdata_unit{$result->{entPhySensorType}},
warning => $warn, value => $result->{entPhySensorValue},
critical => $crit); warning => $warn,
critical => $crit
);
} }
} }

View File

@ -72,11 +72,10 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'filter-name:s' => { name => 'filter_name' },
"filter-name:s" => { name => 'filter_name' }, });
});
return $self; return $self;
} }
@ -107,12 +106,14 @@ sub manage_selection {
$self->{isdn} = {}; $self->{isdn} = {};
$self->{bearer} = { active => 0, total => 0 }; $self->{bearer} = { active => 0, total => 0 };
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ my $snmp_result = $options{snmp}->get_multiple_table(
{ oid => $oid_isdnBearerOperStatus }, oids => [
{ oid => $oid_isdnSignalingIfIndex }, { oid => $oid_isdnBearerOperStatus },
{ oid => $oid_isdnSignalingStatsEntry }, { oid => $oid_isdnSignalingIfIndex },
], { oid => $oid_isdnSignalingStatsEntry },
nothing_quit => 1); ],
nothing_quit => 1
);
# Get interface name # Get interface name
foreach my $oid (keys %{$snmp_result->{$oid_isdnSignalingIfIndex}}) { foreach my $oid (keys %{$snmp_result->{$oid_isdnSignalingIfIndex}}) {
@ -132,8 +133,11 @@ sub manage_selection {
} }
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_isdnSignalingStatsEntry}, instance => $instance); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_isdnSignalingStatsEntry}, instance => $instance);
$self->{isdn}->{$instance} = { in => $result->{isdnSigStatsInCalls}, out => $result->{isdnSigStatsOutCalls}, $self->{isdn}->{$instance} = {
display => $display }; in => $result->{isdnSigStatsInCalls},
out => $result->{isdnSigStatsOutCalls},
display => $display
};
} }
foreach my $oid (keys %{$snmp_result->{$oid_isdnBearerOperStatus}}) { foreach my $oid (keys %{$snmp_result->{$oid_isdnBearerOperStatus}}) {

View File

@ -53,20 +53,22 @@ sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
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 => '.*?#.*?#.*?#.*?#.*?#(?!(listen))', builtin => 1, number => 0, msg => 'Total connections: %d' } }; $self->{services} = { total => { filter => '.*?#.*?#.*?#.*?#.*?#(?!(listen))', builtin => 1, number => 0, msg => 'Total connections: %d' } };
$self->{applications} = {}; $self->{applications} = {};
$self->{states} = { closed => 0, listen => 0, synSent => 0, synReceived => 0, $self->{states} = {
established => 0, finWait1 => 0, finWait2 => 0, closeWait => 0, closed => 0, listen => 0, synSent => 0, synReceived => 0,
lastAck => 0, closing => 0, timeWait => 0 }; established => 0, finWait1 => 0, finWait2 => 0, closeWait => 0,
lastAck => 0, closing => 0, timeWait => 0
};
return $self; return $self;
} }
@ -89,15 +91,17 @@ sub get_ipv6 {
sub get_from_rfc4022 { sub get_from_rfc4022 {
my ($self, %options) = @_; my ($self, %options) = @_;
my $oid_tcpConnectionState = '.1.3.6.1.2.1.6.19.1.7'; my $oid_tcpConnectionState = '.1.3.6.1.2.1.6.19.1.7';
my $oid_tcpListenerProcess = '.1.3.6.1.2.1.6.20.1.4'; my $oid_tcpListenerProcess = '.1.3.6.1.2.1.6.20.1.4';
my $results = $self->{snmp}->get_multiple_table(oids => [ my $results = $self->{snmp}->get_multiple_table(
{ oid => $oid_tcpConnectionState }, oids => [
{ oid => $oid_tcpListenerProcess }, { oid => $oid_tcpConnectionState },
]); { oid => $oid_tcpListenerProcess },
]
);
return 0 if (scalar(keys %{$results->{$oid_tcpConnectionState}}) + scalar(keys %{$results->{$oid_tcpListenerProcess}}) == 0); return 0 if (scalar(keys %{$results->{$oid_tcpConnectionState}}) + scalar(keys %{$results->{$oid_tcpListenerProcess}}) == 0);
# Listener # Listener
foreach (keys %{$results->{$oid_tcpListenerProcess}}) { foreach (keys %{$results->{$oid_tcpListenerProcess}}) {
/^$oid_tcpListenerProcess\.(\d+)/; /^$oid_tcpListenerProcess\.(\d+)/;
@ -117,7 +121,7 @@ sub get_from_rfc4022 {
push @{$self->{connections}}, $ipv . "#$src_addr#$src_port#$dst_addr#0#listen"; push @{$self->{connections}}, $ipv . "#$src_addr#$src_port#$dst_addr#0#listen";
$self->{states}->{listen}++; $self->{states}->{listen}++;
} }
foreach (keys %{$results->{$oid_tcpConnectionState}}) { foreach (keys %{$results->{$oid_tcpConnectionState}}) {
/^$oid_tcpConnectionState\.(\d+)/; /^$oid_tcpConnectionState\.(\d+)/;
my $ipv = $map_addr_type{$1}; my $ipv = $map_addr_type{$1};
@ -134,16 +138,16 @@ sub get_from_rfc4022 {
$self->{states}->{$map_states{$results->{$oid_tcpConnectionState}->{$_}}}++; $self->{states}->{$map_states{$results->{$oid_tcpConnectionState}->{$_}}}++;
push @{$self->{connections}}, $ipv . "#$src_addr#$src_port#$dst_addr#$dst_port#" . lc($map_states{$results->{$oid_tcpConnectionState}->{$_}}); push @{$self->{connections}}, $ipv . "#$src_addr#$src_port#$dst_addr#$dst_port#" . lc($map_states{$results->{$oid_tcpConnectionState}->{$_}});
} }
return 1; return 1;
} }
sub get_from_rfc1213 { sub get_from_rfc1213 {
my ($self, %options) = @_; my ($self, %options) = @_;
my $oid_tcpConnState = '.1.3.6.1.2.1.6.13.1.1'; my $oid_tcpConnState = '.1.3.6.1.2.1.6.13.1.1';
my $result = $self->{snmp}->get_table(oid => $oid_tcpConnState, nothing_quit => 1); my $result = $self->{snmp}->get_table(oid => $oid_tcpConnState, nothing_quit => 1);
# Construct # Construct
foreach (keys %$result) { foreach (keys %$result) {
/(\d+\.\d+\.\d+\.\d+).(\d+)\.(\d+\.\d+\.\d+\.\d+).(\d+)$/; /(\d+\.\d+\.\d+\.\d+).(\d+)\.(\d+\.\d+\.\d+\.\d+).(\d+)$/;
@ -154,7 +158,7 @@ sub get_from_rfc1213 {
sub build_connections { sub build_connections {
my ($self, %options) = @_; my ($self, %options) = @_;
if ($self->get_from_rfc4022() == 0) { if ($self->get_from_rfc4022() == 0) {
$self->get_from_rfc1213(); $self->get_from_rfc1213();
} }
@ -162,7 +166,7 @@ sub build_connections {
sub check_services { sub check_services {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach my $service (@{$self->{option_results}->{service}}) { foreach my $service (@{$self->{option_results}->{service}}) {
my ($tag, $ipv, $state, $port_src, $port_dst, $filter_ip_src, $filter_ip_dst, $warn, $crit) = split /,/, $service; my ($tag, $ipv, $state, $port_src, $port_dst, $filter_ip_src, $filter_ip_dst, $warn, $crit) = split /,/, $service;
@ -175,14 +179,17 @@ 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_src) && $filter_ip_src ne '') ? $filter_ip_src : '.*?') . '#' . filter =>
((defined($port_src) && $port_src ne '') ? $port_src : '.*?') . '#' . ((defined($ipv) && $ipv ne '') ? $ipv : '.*?') . '#' .
((defined($filter_ip_dst) && $filter_ip_dst ne '') ? $filter_ip_dst : '.*?') . '#' . ((defined($filter_ip_src) && $filter_ip_src ne '') ? $filter_ip_src : '.*?') . '#' .
((defined($port_dst) && $port_dst ne '') ? $port_dst : '.*?') . '#' . ((defined($port_src) && $port_src ne '') ? $port_src : '.*?') . '#' .
((defined($state) && $state ne '') ? lc($state) : '(?!(listen))') ((defined($filter_ip_dst) && $filter_ip_dst ne '') ? $filter_ip_dst : '.*?') . '#' .
, ((defined($port_dst) && $port_dst ne '') ? $port_dst : '.*?') . '#' .
builtin => 0, number => 0 }; ((defined($state) && $state ne '') ? lc($state) : '(?!(listen))'),
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();
@ -209,9 +216,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.");
@ -239,22 +244,31 @@ sub test_services {
if (/$self->{services}->{$tag}->{filter}/) { if (/$self->{services}->{$tag}->{filter}/) {
$self->{services}->{$tag}->{number}++; $self->{services}->{$tag}->{number}++;
} }
} }
my $exit_code = $self->{perfdata}->threshold_check(
value => $self->{services}->{$tag}->{number},
threshold => [ { label => 'critical-service-' . $tag, exit_litteral => 'critical' }, { label => 'warning-service-' . $tag, exit_litteral => 'warning' } ]
);
my $exit_code = $self->{perfdata}->threshold_check(value => $self->{services}->{$tag}->{number}, my $msg = "Service '$tag' connections: %d";
threshold => [ { label => 'critical-service-' . $tag, 'exit_litteral' => 'critical' }, { label => 'warning-service-' . $tag, exit_litteral => 'warning' } ]);
my ($perf_label, $msg) = ('service_' . $tag, "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.tcp.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
);
} }
} }
@ -263,20 +277,28 @@ sub test_applications {
foreach my $tag (keys %{$self->{applications}}) { foreach my $tag (keys %{$self->{applications}}) {
my $number = 0; my $number = 0;
foreach (keys %{$self->{applications}->{$tag}->{services}}) { foreach (keys %{$self->{applications}->{$tag}->{services}}) {
$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.tcp.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
);
} }
} }
@ -299,15 +321,18 @@ sub check_options {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{snmp} = $options{snmp}; $self->{snmp} = $options{snmp};
$self->build_connections(); $self->build_connections();
$self->test_services(); $self->test_services();
$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.tcp.' . lc($_) . '.count',
value => $self->{states}->{$_},
min => 0
);
} }
$self->{output}->display(); $self->{output}->display();

View File

@ -125,15 +125,21 @@ sub run {
my $exit_code = $self->{perfdata}->threshold_check(value => floor($value / $unitdiv->{$self->{option_results}->{unit}}), my $exit_code = $self->{perfdata}->threshold_check(value => floor($value / $unitdiv->{$self->{option_results}->{unit}}),
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->perfdata_add(label => 'uptime', unit => $self->{option_results}->{unit}, $self->{output}->perfdata_add(
value => floor($value / $unitdiv->{$self->{option_results}->{unit}}), label => 'uptime', unit => $self->{option_results}->{unit},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), value => floor($value / $unitdiv->{$self->{option_results}->{unit}}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
min => 0); critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0
);
$self->{output}->output_add(severity => $exit_code, $self->{output}->output_add(
short_msg => sprintf("System uptime is: %s", severity => $exit_code,
centreon::plugins::misc::change_seconds(value => $value, start => 'd'))); short_msg => sprintf(
'System uptime is: %s',
centreon::plugins::misc::change_seconds(value => $value, start => 'd')
)
);
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();

View File

@ -29,7 +29,7 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("state : %s [admin state : '%s']", my $msg = sprintf("state : %s [admin state : '%s']",
$self->{result_values}->{operState}, $self->{result_values}->{adminState}); $self->{result_values}->{operState}, $self->{result_values}->{adminState});
return $msg; return $msg;
@ -80,11 +80,10 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ 'warning-status:s' => { name => 'warning_status', default => '' },
"warning-status:s" => { name => 'warning_status', default => '' }, 'critical-status:s' => { name => 'critical_status', default => '%{adminState} eq "up" and %{operState} ne %{operStateLast}' },
"critical-status:s" => { name => 'critical_status', default => '%{adminState} eq "up" and %{operState} ne %{operStateLast}' }, });
});
return $self; return $self;
} }
@ -110,8 +109,11 @@ sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{vrrp} = {}; $self->{vrrp} = {};
my $snmp_result = $options{snmp}->get_table(oid => $oid_vrrpOperEntry, end => $mapping->{vrrpOperMasterIpAddr}->{oid}, my $snmp_result = $options{snmp}->get_table(
nothing_quit => 1); oid => $oid_vrrpOperEntry,
end => $mapping->{vrrpOperMasterIpAddr}->{oid},
nothing_quit => 1
);
foreach my $oid (keys %{$snmp_result}) { foreach my $oid (keys %{$snmp_result}) {
next if ($oid !~ /^$mapping->{vrrpOperState}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{vrrpOperState}->{oid}\.(.*)$/);