Skip to content

Commit

Permalink
fix(linux-local): limit column size to avoid filter issues (#5303)
Browse files Browse the repository at this point in the history
Co-authored-by: Stéphane Duret <sduret@centreon.com>

Refs: CTOR-490
  • Loading branch information
omercier authored Nov 29, 2024
1 parent 69144e3 commit 4c42e04
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 10 deletions.
101 changes: 91 additions & 10 deletions src/os/linux/local/mode/process.pm
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ sub parse_output {

my ($stdout) = $options{custom}->execute_command(
command => 'ps',
command_options => '-e -o state -o etime -o pid -o ppid -o comm:50 -o %a -w 2>&1'
command_options => '-e -o state -o etime:15 -o pid:10 -o ppid:10 -o comm:50 -o args -w 2>&1'
);

$self->{global} = { processes => 0 };
Expand Down Expand Up @@ -394,35 +394,116 @@ Monitor disk I/O.
=item B<--filter-command>
Filter process commands (regexp can be used).
Define which processes should be included based on the name of the executable.
This option will be treated as a regular expression.
=item B<--exclude-command>
Exclude process commands (regexp can be used).
Define which processes should be excluded based on the name of the executable.
This option will be treated as a regular expression.
=item B<--filter-arg>
Filter process arguments (regexp can be used).
Define which processes should be included based on the arguments of the executable.
This option will be treated as a regular expression.
=item B<--exclude-arg>
Exclude process arguments (regexp can be used).
Define which processes should be excluded based on the arguments of the executable.
This option will be treated as a regular expression.
=item B<--filter-ppid>
Filter process ppid (regexp can be used).
Define which processes should be excluded based on the process's parent process ID (PPID).
This option will be treated as a regular expression.
=item B<--filter-state>
Filter process states (regexp can be used).
Define which processes should be excluded based on the process state.
This option will be treated as a regular expression.
You can use: 'zombie', 'dead', 'paging', 'stopped',
'InterrupibleSleep', 'running', 'UninterrupibleSleep'.
=item B<--warning-*> B<--critical-*>
=item B<--warning-total>
Thresholds.
=item B<--critical-total>
Thresholds.
=item B<--warning-total-memory-usage>
Thresholds.
=item B<--critical-total-memory-usage>
Thresholds.
=item B<--warning-total-cpu-utilization>
Thresholds.
=item B<--critical-total-cpu-utilization>
Thresholds.
=item B<--warning-total-disks-read>
Thresholds.
=item B<--critical-total-disks-read>
Thresholds.
=item B<--warning-total-disks-write>
Thresholds.
=item B<--critical-total-disks-write>
Thresholds.
=item B<--warning-time>
Thresholds.
=item B<--critical-time>
Thresholds.
=item B<--warning-memory-usage>
Thresholds.
=item B<--critical-memory-usage>
Thresholds.
=item B<--warning-cpu-utilization>
Thresholds.
=item B<--critical-cpu-utilization>
Thresholds.
=item B<--warning-disks-read>
Thresholds.
=item B<--critical-disks-read>
Thresholds.
=item B<--warning-disks-write>
Thresholds.
=item B<--critical-disks-write>
Thresholds.
Can be: 'total', 'total-memory-usage', 'total-cpu-utilization', 'total-disks-read',
'total-disks-write', 'time', 'memory-usage', 'cpu-utilization', 'disks-read', 'disks-write'.
=back
Expand Down
45 changes: 45 additions & 0 deletions tests/os/linux/local/process.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
*** Settings ***
Documentation Linux Local list-systemdservices
Resource ${CURDIR}${/}..${/}..${/}..${/}resources/import.resource

Test Timeout 120s


*** Variables ***
${CMD} ${CENTREON_PLUGINS} --plugin=os::linux::local::plugin
${COND} ${PERCENT}\{sub\} =~ /exited/ && ${PERCENT}{display} =~ /network/'


*** Test Cases ***
Process ${tc}
[Tags] os linux local
${command} Catenate
... ${CMD}
... --mode=process
... --command-options='${CURDIR}${/}process_bin${/}${ps_output}'
... --command=cat
... --warning-total='${warning}'
... --critical-total='${critical}'
... --filter-command='${filter_command}'

Ctn Run Command And Check Result As Strings ${command} ${expected_result}

Examples: tc ps_output filter_command warning critical expected_result --
... 1 ps-centreon.output cs.sapC4P_C00 ${EMPTY} ${EMPTY} OK: Number of current processes: 0 | 'processes.total.count'=0;;;0;
... 2 ps-centreon.output cs.sapC4P_C00 1:1 ${EMPTY} WARNING: Number of current processes: 0 | 'processes.total.count'=0;1:1;;0;
... 3 ps-centreon.output cs.sapC4P_C00 1:1 1:1 CRITICAL: Number of current processes: 0 | 'processes.total.count'=0;1:1;1:1;0;
... 4 ps-centreon.output cs.sapC4P_C00 0:0 0:0 OK: Number of current processes: 0 | 'processes.total.count'=0;0:0;0:0;0;
... 5 ps-centreon.output gorgone-proxy ${EMPTY} ${EMPTY} OK: Number of current processes: 5 | 'processes.total.count'=5;;;0;
... 6 ps-centreon.output gorgone-proxy 1:1 ${EMPTY} WARNING: Number of current processes: 5 | 'processes.total.count'=5;1:1;;0;
... 7 ps-centreon.output gorgone-proxy 1:1 1:1 CRITICAL: Number of current processes: 5 | 'processes.total.count'=5;1:1;1:1;0;
... 8 ps-centreon.output gorgone-proxy 5:5 5:5 OK: Number of current processes: 5 | 'processes.total.count'=5;5:5;5:5;0;
... 9 ps-sap.output cs.sapC4P_C00 ${EMPTY} ${EMPTY} OK: Process: [command => cs.sapC4P_C00] [arg => cs.sapC4P_C00 pf=/usr/sap/C4P/SYS/profile/C4P_C00_lunisapcsprd2] [state => S] duration: 3M 2w 5d 21h 51m 25s - Number of current processes: 1 | 'processes.total.count'=1;;;0;
... 10 ps-sap.output cs.sapC4P_C00 2:2 ${EMPTY} WARNING: Number of current processes: 1 | 'processes.total.count'=1;2:2;;0;
... 11 ps-sap.output cs.sapC4P_C00 2:2 2:2 CRITICAL: Number of current processes: 1 | 'processes.total.count'=1;2:2;2:2;0;
... 12 ps-sap.output cs.sapC4P_C00 1:1 1:1 OK: Process: [command => cs.sapC4P_C00] [arg => cs.sapC4P_C00 pf=/usr/sap/C4P/SYS/profile/C4P_C00_lunisapcsprd2] [state => S] duration: 3M 2w 5d 21h 51m 25s - Number of current processes: 1 | 'processes.total.count'=1;1:1;1:1;0;
... 13 ps-sap.output gorgone-proxy ${EMPTY} ${EMPTY} OK: Number of current processes: 0 | 'processes.total.count'=0;;;0;
... 14 ps-sap.output gorgone-proxy 2:2 ${EMPTY} WARNING: Number of current processes: 0 | 'processes.total.count'=0;2:2;;0;
... 15 ps-sap.output gorgone-proxy 2:2 2:2 CRITICAL: Number of current processes: 0 | 'processes.total.count'=0;2:2;2:2;0;
... 16 ps-sap.output gorgone-proxy 0:0 0:0 OK: Number of current processes: 0 | 'processes.total.count'=0;0:0;0:0;0;

Loading

0 comments on commit 4c42e04

Please sign in to comment.