CTOR-792 Plugin(os::as400::connector) - Mode(messagequeue) : add an option to ignore acknowledge messages (#5700)

Co-authored-by: garnier-quentin <garnier.quentin@gmail.com>
Co-authored-by: pkippes <pkippes@centreon.com>
This commit is contained in:
Sylvain Cresto 2025-08-11 13:56:34 +02:00 committed by GitHub
parent 0e896346e3
commit 0f8af4dd53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 300 additions and 75 deletions

View File

@ -8,7 +8,7 @@ apt-get update
apt-get install -y \
ca-certificates \
git \
openjdk-17-jdk \
openjdk-17-jdk-headless \
wget \
zstd
@ -27,4 +27,4 @@ apt-get clean all
EOF
WORKDIR /src
WORKDIR /src

View File

@ -85,7 +85,7 @@ jobs:
run: mvn -version && mvn clean install -f as400/connector.as400/pom.xml
- name: Remove me after debug
run: find / -name "centreon-as400*.jar"
run: find / -path /proc -prune -o -name "centreon-as400*.jar"
- name: Package
uses: ./.github/actions/package-nfpm

View File

@ -94,11 +94,6 @@ public class MessageQueueHandler extends AbstractHandler implements IMessageQueu
.debug("Message found : " + message.getID() + " - " + message.getText().replace('|', ' '));
if ((message.getSeverity() >= minSeverityLevel) && (message.getSeverity() < maxSeverityLevel)) {
if ("A".equals(message.getReplyStatus())) {
// The message has been acknowledge already and we don't take it into account
continue;
}
final String messageId = message.getID();
if (messageIdfilterPattern != null && !messageId.matches(messageIdfilterPattern)) {
continue;
@ -112,6 +107,7 @@ public class MessageQueueHandler extends AbstractHandler implements IMessageQueu
attrs.put("jobName", message.getFromJobName());
attrs.put("jobNumber", message.getFromJobNumber());
attrs.put("user", message.getUser());
attrs.put("replyStatus", message.getReplyStatus());
data.getResult().add(attrs);
}
}

View File

@ -161,7 +161,8 @@ sub new {
$options{options}->add_options(arguments => {
'disk-name:s' => { name => 'disk_name' },
'filter-disk-name:s' => { name => 'filter_disk_name' }
'include-disk-name:s' => { name => 'include_disk_name' },
'filter-disk-name:s' => { redirect => 'include_disk_name' }
});
return $self;
@ -172,7 +173,7 @@ sub check_options {
$self->SUPER::check_options(%options);
$self->{uuid} = '';
foreach ('filter_counters', 'filter_disk_name') {
foreach ('filter_counters', 'include_disk_name') {
if (defined($self->{option_results}->{$_}) && $self->{option_results}->{$_} ne '') {
$self->{uuid} .= $self->{option_results}->{$_};
}
@ -203,8 +204,8 @@ sub manage_selection {
$self->{disks} = {};
my ($max, $min) = (0, 100);
foreach my $disk (@{$disks->{result}}) {
if (defined($self->{option_results}->{filter_disk_name}) && $self->{option_results}->{filter_disk_name} ne '' &&
$disk->{name} !~ /$self->{option_results}->{filter_disk_name}/) {
if (defined($self->{option_results}->{include_disk_name}) && $self->{option_results}->{include_disk_name} ne '' &&
$disk->{name} !~ /$self->{option_results}->{include_disk_name}/) {
$self->{output}->output_add(long_msg => "skipping disk '" . $disk->{name} . "': no matching filter.", debug => 1);
next;
}
@ -249,7 +250,7 @@ Check disks.
Check exact disk.
=item B<--filter-disk-name>
=item B<--include-disk-name>
Filter disks by name (can be a regexp).
@ -268,11 +269,69 @@ You can use the following variables: %{status}, %{name}
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /^(noAccess|otherDiskSubFailed|failed|notOperational|noUnitControl)$/i').
You can use the following variables: %{status}, %{name}
=item B<--warning-*> B<--critical-*>
=item B<--warning-disks-active>
Thresholds.
Can be: 'space-usage', 'space-usage-free', 'space-usage-prct', 'reserved',
'disks-total', 'disks-active', 'disks-errors', 'disks-gap-repartition'.
Threshold.
=item B<--critical-disks-active>
Threshold.
=item B<--warning-disks-errors>
Threshold.
=item B<--critical-disks-errors>
Threshold.
=item B<--warning-disks-gap-repartition>
Threshold in percentage.
=item B<--critical-disks-gap-repartition>
Threshold in percentage.
=item B<--warning-disks-total>
Threshold.
=item B<--critical-disks-total>
Threshold.
=item B<--warning-reserved>
Threshold in bytes.
=item B<--critical-reserved>
Threshold in bytes.
=item B<--warning-space-usage>
Threshold in bytes.
=item B<--critical-space-usage>
Threshold in bytes.
=item B<--warning-space-usage-free>
Threshold in bytes.
=item B<--critical-space-usage-free>
Threshold in bytes.
=item B<--warning-space-usage-prct>
Threshold in percentage.
=item B<--critical-space-usage-prct>
Threshold in percentage.
=back

View File

@ -218,11 +218,37 @@ You can use the following variables: %{status}, %{name}, %{library}
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /HELD/i').
You can use the following variables: %{status}, %{name}, %{library}
=item B<--warning-*> B<--critical-*>
=item B<--warning-jobqueue-jobs-active>
Thresholds.
Can be: 'jobqueues-total', 'jobqueue-jobs-active',
'jobqueue-jobs-scheduled', 'jobqueue-jobs-held'.
Threshold.
=item B<--critical-jobqueue-jobs-active>
Threshold.
=item B<--warning-jobqueue-jobs-held>
Threshold.
=item B<--critical-jobqueue-jobs-held>
Threshold.
=item B<--warning-jobqueue-jobs-scheduled>
Threshold.
=item B<--critical-jobqueue-jobs-scheduled>
Threshold.
=item B<--warning-jobqueues-total>
Threshold.
=item B<--critical-jobqueues-total>
Threshold.
=back

View File

@ -50,10 +50,13 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-active-status:s' => { name => 'filter_active_status' },
'filter-name:s' => { name => 'filter_name' },
'filter-subsystem:s' => { name => 'filter_subsystem' },
'display-jobs' => { name => 'display_jobs' }
'include-active-status:s' => { name => 'include_active_status' },
'filter-active-status:s' => { redirect => 'include_active_status' },
'include-name:s' => { name => 'include_name' },
'filter-name:s' => { redirect => 'include_name' },
'include-subsystem:s' => { name => 'include_subsystem' },
'filter-subsystem:s' => { redirect => 'include_subsystem' },
'display-jobs' => { name => 'display_jobs' }
});
return $self;
@ -64,7 +67,7 @@ sub check_options {
$self->SUPER::check_options(%options);
$self->{uuid} = '';
foreach ('filter_counters', 'filter_name', 'filter_active_status', 'filter_subsystem') {
foreach ('filter_counters', 'include_name', 'include_active_status', 'include_subsystem') {
if (defined($self->{option_results}->{$_}) && $self->{option_results}->{$_} ne '') {
$self->{uuid} .= $self->{option_results}->{$_};
}
@ -82,18 +85,18 @@ sub manage_selection {
$self->{global} = { total => 0 };
foreach my $entry (@{$jobs->{result}}) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$entry->{name} !~ /$self->{option_results}->{filter_name}/) {
if (defined($self->{option_results}->{include_name}) && $self->{option_results}->{include_name} ne '' &&
$entry->{name} !~ /$self->{option_results}->{include_name}/) {
$self->{output}->output_add(long_msg => "skipping job '" . $entry->{name} . "': no matching filter (name).", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_subsystem}) && $self->{option_results}->{filter_subsystem} ne '' &&
$entry->{subSystem} !~ /$self->{option_results}->{filter_subsystem}/) {
if (defined($self->{option_results}->{include_subsystem}) && $self->{option_results}->{include_subsystem} ne '' &&
$entry->{subSystem} !~ /$self->{option_results}->{include_subsystem}/) {
$self->{output}->output_add(long_msg => "skipping job '" . $entry->{name} . "': no matching filter (subsystem).", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_active_status}) && $self->{option_results}->{filter_active_status} ne '' &&
$entry->{activeStatus} !~ /$self->{option_results}->{filter_active_status}/) {
if (defined($self->{option_results}->{include_active_status}) && $self->{option_results}->{include_active_status} ne '' &&
$entry->{activeStatus} !~ /$self->{option_results}->{include_active_status}/) {
$self->{output}->output_add(long_msg => "skipping job '" . $entry->{name} . "': no matching filter (activeStatus).", debug => 1);
next;
}
@ -123,16 +126,16 @@ Check active jobs.
=over 8
=item B<--filter-active-status>
=item B<--include-active-status>
Filter jobs by ACTIVE_JOB_STATUS (can be a regexp).
Example: --filter-active-status='MSGW' to count jobs with MSGW.
Example: --include-active-status='MSGW' to count jobs with MSGW.
=item B<--filter-name>
=item B<--include-name>
Filter jobs by name (can be a regexp).
=item B<--filter-subsystem>
=item B<--include-subsystem>
Filter jobs by subsystem (can be a regexp).
@ -140,10 +143,13 @@ Filter jobs by subsystem (can be a regexp).
Display jobs in verbose output.
=item B<--warning-*> B<--critical-*>
=item B<--warning-jobs-total>
Thresholds.
Can be: 'jobs-total'.
Threshold.
=item B<--critical-jobs-total>
Threshold.
=back

View File

@ -57,16 +57,21 @@ sub set_counters {
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
my $self = $class->SUPER::new(package => __PACKAGE__, %options, ); #force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'message-queue-path:s' => { name => 'message_queue_path' },
'memory' => { name => 'memory' },
'filter-message-id:s' => { name => 'filter_message_id' },
'min-severity:s' => { name => 'min_severity' },
'max-severity:s' => { name => 'max_severity' },
'display-messages' => { name => 'display_messages' }
'message-queue-path:s' => { name => 'message_queue_path' },
'memory' => { name => 'memory' },
'include-message-id:s' => { name => 'include_message_id', default => '' },
'filter-message-id:s' => { redirect => 'include_message_id' }, # for compatibility
'include-reply-status:s' => { name => 'include_reply_status', default => '' },
'exclude-reply-status:s' => { name => 'exclude_reply_status', default => 'A' },
'include-text:s' => { name => 'include_text', default => '' },
'exclude-text:s' => { name => 'exclude_text', default => '' },
'min-severity:s' => { name => 'min_severity', default => '' },
'max-severity:s' => { name => 'max_severity', default => '' },
'display-messages' => { name => 'display_messages' }
});
return $self;
@ -86,14 +91,14 @@ sub manage_selection {
my ($self, %options) = @_;
my %cmd = (command => 'getErrorMessageQueue', args => { messageQueuePath => $self->{option_results}->{message_queue_path} });
$cmd{args}->{messageIdfilterPattern} = $self->{option_results}->{filter_message_id}
if (defined($self->{option_results}->{filter_message_id}) && $self->{option_results}->{filter_message_id} ne '');
$cmd{args}->{messageIdfilterPattern} = $self->{option_results}->{include_message_id}
if $self->{option_results}->{include_message_id} ne '';
$cmd{args}->{minSeverityLevel} = $self->{option_results}->{min_severity}
if (defined($self->{option_results}->{min_severity}) && $self->{option_results}->{min_severity} ne '');
if $self->{option_results}->{min_severity} ne '';
$cmd{args}->{maxSeverityLevel} = $self->{option_results}->{max_severity}
if (defined($self->{option_results}->{max_severity}) && $self->{option_results}->{max_severity} ne '');
if $self->{option_results}->{max_severity} ne '';
$cmd{command} = 'getNewMessageInMessageQueue'
if (defined($self->{option_results}->{memory}));
if defined($self->{option_results}->{memory});
$self->{global} = { total => 0, mq_path => $self->{option_results}->{message_queue_path} };
my $messages = $options{custom}->request_api(%cmd);
@ -104,15 +109,24 @@ sub manage_selection {
}
foreach my $entry (@{$messages->{result}}) {
if (defined($self->{option_results}->{display_messages})) {
# compatibility with old as400 daemon version who does not return 'replyStatus'
$entry->{replyStatus} //= '';
next if $self->{option_results}->{include_reply_status} ne '' && $entry->{replyStatus} !~ /$self->{option_results}->{include_reply_status}/;
next if $self->{option_results}->{exclude_reply_status} ne '' && $entry->{replyStatus} =~ /$self->{option_results}->{exclude_reply_status}/;
next if $self->{option_results}->{include_text} ne '' && $entry->{text} !~ /$self->{option_results}->{include_text}/;
next if $self->{option_results}->{exclude_text} ne '' && $entry->{text} =~ /$self->{option_results}->{exclude_text}/;
if (defined($self->{option_results}->{display_messages})) {
$entry->{text} =~ s/\|/ /g;
$self->{output}->output_add(
long_msg => sprintf(
'message [id: %s] [severity: %s] [date: %s] [user: %s]: %s',
'message [id: %s] [severity: %s] [date: %s] [user: %s]%s: %s',
$entry->{id},
$entry->{severity},
scalar(localtime($entry->{date} / 1000)),
defined($entry->{user}) ? $entry->{user} : '-',
$entry->{replyStatus} ne '' ? ' [replyStatus: ' . $entry->{replyStatus} . ']': '',
$entry->{text}
)
);
@ -140,10 +154,26 @@ Specify the message queue (required. Example: --message-queue-path='/QSYS.LIB/QS
Check only new messages.
=item B<--filter-message-id>
=item B<--include-message-id>
Filter messages by ID (can be a regexp).
=item B<--include-reply-status>
Filter messages by reply status (can be a regexp).
=item B<--exclude-reply-status>
Exclude messages by reply status (can be a regexp) (default: 'A').
=item B<--include-text>
Filter messages by text (can be a regexp).
=item B<--exclude-text>
Exclude messages by text (can be a regexp).
=item B<--min-severity>
Filter messages with severity greater than or equal to X.
@ -156,7 +186,11 @@ Filter messages with severity less than to X.
Display messages in verbose output.
=item B<--warning-messages> B<--critical-messages>
=item B<--warning-messages>
Thresholds.
=item B<--critical-messages>
Thresholds.

View File

@ -95,10 +95,21 @@ Check page faults.
=over 8
=item B<--warning-*> B<--critical-*>
=item B<--warning-pagefaults-database>
Thresholds.
Can be: 'pagefaults-database', 'pagefaults-nondatabase'.
Threshold in percentage.
=item B<--critical-pagefaults-database>
Threshold in percentage.
=item B<--warning-pagefaults-nondatabase>
Threshold in percentage.
=item B<--critical-pagefaults-nondatabase>
Threshold in percentage.
=back

View File

@ -121,8 +121,10 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-subsystem-name:s' => { name => 'filter_subsystem_name' },
'filter-subsystem-library:s' => { name => 'filter_subsystem_library' }
'include-subsystem-name:s' => { name => 'include_subsystem_name' },
'filter-subsystem-name:s' => { redirect => 'include_subsystem_name' },
'include-subsystem-library:s' => { name => 'include_subsystem_library' },
'filter-subsystem-library:s' => { redirect => 'include_subsystem_library' }
});
return $self;
@ -133,7 +135,7 @@ sub check_options {
$self->SUPER::check_options(%options);
$self->{uuid} = '';
foreach ('filter_counters', 'filter_subsystem_name', 'filter_subsystem_library') {
foreach ('filter_counters', 'include_subsystem_name', 'include_subsystem_library') {
if (defined($self->{option_results}->{$_}) && $self->{option_results}->{$_} ne '') {
$self->{uuid} .= $self->{option_results}->{$_};
}
@ -160,13 +162,13 @@ sub manage_selection {
$self->{global} = { total => 0, active => 0, ending => 0, inactive => 0, restricted => 0, starting => 0 };
$self->{subsys} = {};
foreach my $entry (@{$subsys->{result}}) {
if (defined($self->{option_results}->{filter_subsystem_name}) && $self->{option_results}->{filter_subsystem_name} ne '' &&
$entry->{name} !~ /$self->{option_results}->{filter_subsystem_name}/) {
if (defined($self->{option_results}->{include_subsystem_name}) && $self->{option_results}->{include_subsystem_name} ne '' &&
$entry->{name} !~ /$self->{option_results}->{include_subsystem_name}/) {
$self->{output}->output_add(long_msg => "skipping subsystem '" . $entry->{name} . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_subsystem_library}) && $self->{option_results}->{filter_subsystem_library} ne '' &&
$entry->{library} !~ /$self->{option_results}->{filter_subsystem_library}/) {
if (defined($self->{option_results}->{include_subsystem_library}) && $self->{option_results}->{include_subsystem_library} ne '' &&
$entry->{library} !~ /$self->{option_results}->{include_subsystem_library}/) {
$self->{output}->output_add(long_msg => "skipping subsystem '" . $entry->{name} . "': no matching filter.", debug => 1);
next;
}
@ -193,11 +195,11 @@ Check subsystems.
=over 8
=item B<--filter-subsystem-name>
=item B<--include-subsystem-name>
Filter subsystems by name (can be a regexp).
=item B<--filter-subsystem-library>
=item B<--include-subsystem-library>
Filter subsystems by library (can be a regexp).
@ -216,12 +218,61 @@ You can use the following variables: %{status}, %{name}, %{library}
Define the conditions to match for the status to be CRITICAL.
You can use the following variables: %{status}, %{name}, %{library}
=item B<--warning-*> B<--critical-*>
=item B<--warning-jobs-active>
Thresholds.
Can be: 'subsystems-total', 'subsystems-active', 'subsystems-ending',
'subsystems-inactive', 'subsystems-restricted', 'subsystems-starting',
'jobs-active'.
Threshold.
=item B<--critical-jobs-active>
Threshold.
=item B<--warning-subsystems-active>
Threshold.
=item B<--critical-subsystems-active>
Threshold.
=item B<--warning-subsystems-ending>
Threshold.
=item B<--critical-subsystems-ending>
Threshold.
=item B<--warning-subsystems-inactive>
Threshold.
=item B<--critical-subsystems-inactive>
Threshold.
=item B<--warning-subsystems-restricted>
Threshold.
=item B<--critical-subsystems-restricted>
Threshold.
=item B<--warning-subsystems-starting>
Threshold.
=item B<--critical-subsystems-starting>
Threshold.
=item B<--warning-subsystems-total>
Threshold.
=item B<--critical-subsystems-total>
Threshold.
=back

View File

@ -167,11 +167,53 @@ Check system usage.
Only display some counters (regexp can be used).
Example: --filter-counters='processing-units'
=item B<--warning-*> B<--critical-*>
=item B<--warning-batch-jobs-running>
Thresholds.
Can be: 'processing-units-usage' (%), 'storage-pool-space-usage' (%),
Threshold.
=item B<--critical-batch-jobs-running>
Threshold.
=item B<--warning-batch-jobs-waiting-message>
Threshold.
=item B<--critical-batch-jobs-waiting-message>
Threshold.
=item B<--warning-jobs-active>
Threshold.
=item B<--critical-jobs-active>
Threshold.
=item B<--warning-jobs-total>
Threshold.
=item B<--critical-jobs-total>
Threshold.
=item B<--warning-processing-units-usage>
Threshold in percentage.
=item B<--critical-processing-units-usage>
Threshold in percentage.
=item B<--warning-storage-pool-space-usage>
Threshold in percentage.
=item B<--critical-storage-pool-space-usage>
Threshold in percentage.
=back