Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/apps/apache/serverstatus/mode/slotstates.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2024 Centreon (http://www.centreon.com/)
# Copyright 2026-Present Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
Expand All @@ -25,6 +25,7 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::http;
use centreon::plugins::constants qw/:values :counters/;

sub custom_value_threshold {
my ($self, %options) = @_;
Expand Down Expand Up @@ -79,7 +80,7 @@ sub custom_value_calc {
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
if ($self->{result_values}->{total} == 0) {
$self->{error_msg} = "skipped";
return -2;
return NOT_PROCESSED;
}
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{label_ref}};
$self->{result_values}->{prct} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
Expand All @@ -92,7 +93,7 @@ sub set_counters {
my ($self, %options) = @_;

$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -2 => 1 } }
{ name => 'global', type => COUNTER_TYPE_GLOBAL, cb_prefix_output => 'prefix_global_output', skipped_code => { NOT_PROCESSED() => 1 } }
];

$self->{maps_counters}->{global} = [
Expand Down
30 changes: 24 additions & 6 deletions src/centreon/plugins/constants.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,36 @@ use warnings;
use Exporter qw(import);

use constant {
RUN_OK => 0,
BUFFER_CREATION => -1,
CLEAR_BUFFER => -2,
NO_VALUE => -10,
RUN_OK => 0, # value present
BUFFER_CREATION => -1, # cache creation, check will be done next time
NOT_PROCESSED => -2, # no result processed
NO_VALUE => -10, # contains no value

# Define the scope of a couunter
COUNTER_TYPE_GLOBAL => 0, # global counter
COUNTER_TYPE_INSTANCE => 1, # counter defined per instance
COUNTER_TYPE_GROUP => 2, # group of counters
COUNTER_TYPE_MULTIPLE => 3, # multiple group of counters

# Only used with COUNTER_TYPE_MULTIPLE counters
COUNTER_MULTIPLE_INSTANCE => 0, # counter global to the instance
COUNTER_MULTIPLE_SUBINSTANCE => 1, # counter defined per subinstance

# Define the nature of a counter ( numeric or text )
COUNTER_KIND_METRIC => 1, # numeric counter with thesholds and perfdata
COUNTER_KIND_TEXT => 2, # text counter with status check and no perfdata

MSG_JSON_DECODE_ERROR => 'Cannot decode response (add --debug option to display returned content)'
};

our %EXPORT_TAGS = (
values => [ qw(NO_VALUE BUFFER_CREATION RUN_OK CLEAR_BUFFER) ],
messages => [ qw(MSG_JSON_DECODE_ERROR) ]
values => [ qw(NO_VALUE BUFFER_CREATION RUN_OK NOT_PROCESSED) ],
counter_types => [ qw(COUNTER_TYPE_GLOBAL COUNTER_TYPE_INSTANCE COUNTER_TYPE_GROUP COUNTER_TYPE_MULTIPLE) ],
counter_multiple_types => [ qw(COUNTER_MULTIPLE_INSTANCE COUNTER_MULTIPLE_SUBINSTANCE) ],
counter_kinds => [ qw(COUNTER_KIND_METRIC COUNTER_KIND_TEXT) ],
messages => [ qw(MSG_JSON_DECODE_ERROR) ]
);
$EXPORT_TAGS{counters} = [ @{$EXPORT_TAGS{counter_types}}, @{$EXPORT_TAGS{counter_multiple_types}}, @{$EXPORT_TAGS{counter_kinds}} ];
$EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ];

our @EXPORT_OK = @{$EXPORT_TAGS{all}};
Expand Down
35 changes: 18 additions & 17 deletions src/centreon/plugins/templates/counter.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2024 Centreon (http://www.centreon.com/)
# Copyright 2026-Present Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
Expand All @@ -26,6 +26,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::values;
use centreon::plugins::constants qw/:counters/;
use centreon::plugins::misc qw/is_empty/;
use JSON::XS;

Expand All @@ -43,10 +44,10 @@ sub set_counters {

$self->{maps_counters_type} = [];

# 0 = mode total
# 1 = mode instances
# COUNTER_TYPE_GLOBAL (0) = mode total
# COUNTER_TYPE_INSTANCE (1) = mode instances
#push @{$self->{maps_counters_type}}, {
# name => 'global', type => 0, message_separator => ', ', cb_prefix_output => undef, cb_init => undef,
# name => 'global', type => COUNTER_TYPE_GLOBAL, message_separator => ', ', cb_prefix_output => undef, cb_init => undef,
#};

#$self->{maps_counters}->{global} = [
Expand All @@ -63,7 +64,7 @@ sub set_counters {

# Example for instances
#push @{$self->{maps_counters_type}}, {
# name => 'cpu', type => 1, message_separator => ', ', cb_prefix_output => undef, cb_init => undef,
# name => 'cpu', type => COUNTER_KIND_METRIC, message_separator => ', ', cb_prefix_output => undef, cb_init => undef,
# message_multiple => 'All CPU usages are ok',
#};
}
Expand Down Expand Up @@ -97,15 +98,15 @@ sub get_threshold_prefix {
my $prefix = '';
END_LOOP: foreach (@{$self->{maps_counters_type}}) {
if ($_->{name} eq $options{name}) {
$prefix = 'instance-' if ($_->{type} == 1);
$prefix = 'instance-' if $_->{type} == COUNTER_TYPE_INSTANCE;
last;
}

if ($_->{type} == 3) {
if ($_->{type} == COUNTER_TYPE_MULTIPLE) {
foreach (@{$_->{group}}) {
if ($_->{name} eq $options{name}) {
$prefix = 'instance-' if ($_->{type} == 0);
$prefix = 'subinstance-' if ($_->{type} == 1);
$prefix = 'instance-' if $_->{type} == COUNTER_MULTIPLE_INSTANCE;
$prefix = 'subinstance-' if $_->{type} == COUNTER_MULTIPLE_SUBINSTANCE;
last END_LOOP;
}
}
Expand Down Expand Up @@ -239,9 +240,9 @@ sub check_options {
foreach my $key (keys %{$self->{maps_counters}}) {
foreach (@{$self->{maps_counters}->{$key}}) {
push @$change_macros_opt, 'unknown-' . $_->{label}, 'warning-' . $_->{label}, 'critical-' . $_->{label}
if (defined($_->{type}) && $_->{type} == 2);
if $_->{type} && $_->{type} == COUNTER_KIND_TEXT;
$_->{obj}->{instance_mode} = $self;
$_->{obj}->init(option_results => $self->{option_results}) if (!defined($_->{type}) || $_->{type} != 2);
$_->{obj}->init(option_results => $self->{option_results}) if !defined($_->{type}) || $_->{type} != COUNTER_KIND_TEXT;
}
}

Expand Down Expand Up @@ -727,9 +728,9 @@ sub run_multiple {
next if (!defined($self->{$options{config}->{name}}->{$instance}->{$group->{name}}));
$self->{$group->{name}} = $self->{$options{config}->{name}}->{$instance}->{$group->{name}};

if ($group->{type} == 1) {
if ($group->{type} == COUNTER_MULTIPLE_SUBINSTANCE) {
$self->run_multiple_instances(config => $group, multiple_parent => $multiple, instance_parent => $instance, indent_long_output => $indent_long_output);
} elsif ($group->{type} == 0) {
} elsif ($group->{type} == COUNTER_MULTIPLE_INSTANCE) {
$self->run_global(
config => $group,
multiple_parent => $multiple,
Expand Down Expand Up @@ -768,13 +769,13 @@ sub run {
}

foreach my $entry (@{$self->{maps_counters_type}}) {
if ($entry->{type} == 0) {
if ($entry->{type} == COUNTER_TYPE_GLOBAL) {
$self->run_global(config => $entry);
} elsif ($entry->{type} == 1) {
} elsif ($entry->{type} == COUNTER_TYPE_INSTANCE) {
$self->run_instances(config => $entry);
} elsif ($entry->{type} == 2) {
} elsif ($entry->{type} == COUNTER_TYPE_GROUP) {
$self->run_group(config => $entry);
} elsif ($entry->{type} == 3) {
} elsif ($entry->{type} == COUNTER_TYPE_MULTIPLE) {
$self->run_multiple(config => $entry);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/os/linux/local/mode/checkplugin.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2024 Centreon (http://www.centreon.com/)
# Copyright 2026-Present Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
Expand Down Expand Up @@ -27,6 +27,7 @@ use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
use Time::HiRes qw(gettimeofday tv_interval);
use centreon::plugins::ssh;
use centreon::plugins::constants qw/:counters/;
use centreon::plugins::misc;

sub custom_status_output {
Expand All @@ -39,7 +40,7 @@ sub set_counters {
my ($self, %options) = @_;

$self->{maps_counters_type} = [
{ name => 'commands', type => 1, message_separator => ' - ', display_long => 0 }
{ name => 'commands', type => COUNTER_TYPE_INSTANCE, message_separator => ' - ', display_long => 0 }
];

$self->{maps_counters}->{commands} = [
Expand Down
4 changes: 2 additions & 2 deletions src/snmp_standard/mode/interfaces.pm
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ sub custom_traffic_calc {
# no percentage for traffic
$self->{result_values}->{traffic_prct} = undef;
$self->{error_msg} = 'clear buffer';
return CLEAR_BUFFER;
return NOT_PROCESSED;
}
return RUN_OK;
}
Expand Down Expand Up @@ -509,7 +509,7 @@ sub custom_errors_calc {
}
$self->{result_values}->{prct} = undef;
$self->{error_msg} = "clear buffer";
return CLEAR_BUFFER;
return NOT_PROCESSED;
}

return RUN_OK;
Expand Down
Loading