diff --git a/centreon/plugins/output.pm b/centreon/plugins/output.pm index a479ae146..6d51034c8 100644 --- a/centreon/plugins/output.pm +++ b/centreon/plugins/output.pm @@ -195,6 +195,7 @@ sub explode_perfdatas { sub output_json { my ($self, %options) = @_; my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0; + my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; my $json_content = {plugin => { name => $self->{plugin}, mode => $self->{mode}, @@ -217,7 +218,7 @@ sub output_json { } } - if (defined($self->{option_results}->{verbose}) || defined($options{force_long_output})) { + if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) { foreach (@{$self->{global_long_output}}) { push @{$json_content->{plugin}->{outputs}}, { type => 2, @@ -249,6 +250,7 @@ sub output_json { sub output_xml { my ($self, %options) = @_; my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0; + my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; my ($child_plugin_name, $child_plugin_mode, $child_plugin_exit, $child_plugin_output, $child_plugin_perfdata); my $root = $self->{xml_output}->createElement('plugin'); @@ -294,7 +296,7 @@ sub output_xml { } } - if (defined($self->{option_results}->{verbose}) || defined($options{force_long_output})) { + if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) { foreach (@{$self->{global_long_output}}) { my ($child_output, $child_type, $child_msg); @@ -335,6 +337,7 @@ sub output_xml { sub output_txt { my ($self, %options) = @_; my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0; + my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; if (defined($self->{global_short_concat_outputs}->{UNQUALIFIED_YET})) { $self->output_add(severity => uc($options{exit_litteral}), short_msg => $self->{global_short_concat_outputs}->{UNQUALIFIED_YET}); @@ -366,7 +369,7 @@ sub output_txt { print "\n"; } - if (defined($self->{option_results}->{verbose}) || defined($options{force_long_output})) { + if (defined($self->{option_results}->{verbose}) || $force_long_output == 1) { if (scalar(@{$self->{global_long_output}})) { print join("\n", @{$self->{global_long_output}}); print "\n"; @@ -378,25 +381,29 @@ sub display { my ($self, %options) = @_; my $nolabel = defined($options{nolabel}) ? 1 : 0; my $force_ignore_perfdata = (defined($options{force_ignore_perfdata}) && $options{force_ignore_perfdata} == 1) ? 1 : 0; + my $force_long_output = (defined($options{force_long_output}) && $options{force_long_output} == 1) ? 1 : 0; if (defined($self->{option_results}->{output_xml})) { $self->create_xml_document(); if ($self->{is_output_xml}) { $self->output_xml(exit_litteral => $self->get_litteral_status(), - nolabel => $nolabel, force_ignore_perfdata => $force_ignore_perfdata); + nolabel => $nolabel, + force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output); return ; } } elsif (defined($self->{option_results}->{output_json})) { $self->create_json_document(); if ($self->{is_output_json}) { $self->output_json(exit_litteral => $self->get_litteral_status(), - nolabel => $nolabel, force_ignore_perfdata => $force_ignore_perfdata); + nolabel => $nolabel, + force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output); return ; } } $self->output_txt(exit_litteral => $self->get_litteral_status(), - nolabel => $nolabel, force_ignore_perfdata => $force_ignore_perfdata); + nolabel => $nolabel, + force_ignore_perfdata => $force_ignore_perfdata, force_long_output => $force_long_output); } sub die_exit { diff --git a/os/linux/local/mode/listinterfaces.pm b/os/linux/local/mode/listinterfaces.pm index f3c6cabfd..4f258fd7c 100644 --- a/os/linux/local/mode/listinterfaces.pm +++ b/os/linux/local/mode/listinterfaces.pm @@ -87,12 +87,20 @@ sub manage_selection { $states .= 'R' if ($values =~ /RUNNING/ms); $states .= 'U' if ($values =~ /UP/ms); - next if (defined($self->{option_results}->{no_loopback}) && $values =~ /LOOPBACK/ms); - next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $interface_name !~ /$self->{option_results}->{filter_name}/); - next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' && - $states !~ /$self->{option_results}->{filter_state}/); - + if (defined($self->{option_results}->{no_loopback}) && $values =~ /LOOPBACK/ms) { + $self->{output}->output_add(long_msg => "Skipping interface '" . $interface_name . "': option --no-loopback"); + next; + } + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $interface_name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "Skipping interface '" . $interface_name . "': no matching filter name"); + next; + } + if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' && + $states !~ /$self->{option_results}->{filter_state}/) { + $self->{output}->output_add(long_msg => "Skipping interface '" . $interface_name . "': no matching filter state"); + next; + } $self->{result}->{$interface_name} = {state => $states}; } } @@ -101,16 +109,13 @@ sub run { my ($self, %options) = @_; $self->manage_selection(); - my $interfaces_display = ''; - my $interfaces_display_append = ''; foreach my $name (sort(keys %{$self->{result}})) { - $interfaces_display .= $interfaces_display_append . 'name = ' . $name . ' [state = ' . $self->{result}->{$name}->{state} . ']'; - $interfaces_display_append = ', '; + $self->{output}->output_add(long_msg => "'" . $name . "' [state = " . $self->{result}->{$name}->{state} . ']'); } $self->{output}->output_add(severity => 'OK', - short_msg => 'List interfaces: ' . $interfaces_display); - $self->{output}->display(nolabel => 1); + short_msg => 'List interfaces:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } diff --git a/os/linux/local/mode/listpartitions.pm b/os/linux/local/mode/listpartitions.pm index 1064c774a..1906d902e 100644 --- a/os/linux/local/mode/listpartitions.pm +++ b/os/linux/local/mode/listpartitions.pm @@ -86,8 +86,11 @@ sub manage_selection { next if ($line !~ /^\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/); my ($major, $minor, $blocks, $name) = ($1, $2, $3, $4); - next if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && - $name !~ /$self->{option_results}->{filter_name}/); + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "Skipping partition '" . $name . "': no matching filter name"); + next; + } $self->{result}->{$name} = 1; } @@ -97,16 +100,13 @@ sub run { my ($self, %options) = @_; $self->manage_selection(); - my $partitions_display = ''; - my $partitions_display_append = ''; foreach my $name (sort(keys %{$self->{result}})) { - $partitions_display .= $partitions_display_append . 'name = ' . $name; - $partitions_display_append = ', '; + $self->{output}->output_add(long_msg => "'" . $name . "'"); } $self->{output}->output_add(severity => 'OK', - short_msg => 'List partitions: ' . $partitions_display); - $self->{output}->display(nolabel => 1); + short_msg => 'List partitions:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } diff --git a/os/linux/local/mode/liststorages.pm b/os/linux/local/mode/liststorages.pm index c9f684ff9..046e754b8 100644 --- a/os/linux/local/mode/liststorages.pm +++ b/os/linux/local/mode/liststorages.pm @@ -88,12 +88,21 @@ sub manage_selection { next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/); my ($fs, $type, $size, $used, $available, $percent, $mount) = ($1, $2, $3, $4, $5, $6, $7); - next if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' && - $fs !~ /$self->{option_results}->{filter_fs}/); - next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && - $type !~ /$self->{option_results}->{filter_type}/); - next if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' && - $mount !~ /$self->{option_results}->{filter_mount}/); + if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' && + $fs !~ /$self->{option_results}->{filter_fs}/) { + $self->{output}->output_add(long_msg => "Skipping storage '" . $mount . "': no matching filter filesystem"); + next; + } + if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && + $type !~ /$self->{option_results}->{filter_type}/) { + $self->{output}->output_add(long_msg => "Skipping storage '" . $mount . "': no matching filter filesystem type"); + next; + } + if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' && + $mount !~ /$self->{option_results}->{filter_mount}/) { + $self->{output}->output_add(long_msg => "Skipping storage '" . $mount . "': no matching filter mount point"); + next; + } $self->{result}->{$mount} = {fs => $fs, type => $type}; } @@ -103,16 +112,13 @@ sub run { my ($self, %options) = @_; $self->manage_selection(); - my $storages_display = ''; - my $storages_display_append = ''; foreach my $name (sort(keys %{$self->{result}})) { - $storages_display .= $storages_display_append . 'name = ' . $name . ' [fs = ' . $self->{result}->{$name}->{fs} . ', type = ' . $self->{result}->{$name}->{type} . ']'; - $storages_display_append = ', '; + $self->{output}->output_add(long_msg => "'" . $name . "' [fs = " . $self->{result}->{$name}->{fs} . ', type = ' . $self->{result}->{$name}->{type} . ']'); } $self->{output}->output_add(severity => 'OK', - short_msg => 'List storages: ' . $storages_display); - $self->{output}->display(nolabel => 1); + short_msg => 'List storages:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } diff --git a/snmp_standard/mode/listdiskspath.pm b/snmp_standard/mode/listdiskspath.pm index 5e8f8e90b..010311f21 100644 --- a/snmp_standard/mode/listdiskspath.pm +++ b/snmp_standard/mode/listdiskspath.pm @@ -78,23 +78,24 @@ sub run { $self->manage_selection(); my $result = $self->get_additional_information(); - - my $diskpath_display = ''; - my $diskpath_display_append = ''; + foreach (sort @{$self->{diskpath_id_selected}}) { - if (defined($result)) { - my $total_size = (($result->{$oid_dskTotalHigh . "." . $_} << 32) + $result->{$oid_dskTotalLow . "." . $_}); - next if ($total_size == 0); - } my $display_value = $self->get_display_value(id => $_); - $diskpath_display .= $diskpath_display_append . "name = $display_value [id = $_]"; - $diskpath_display_append = ', '; + if (defined($result)) { + my $total_size = (($result->{$oid_dskTotalHigh . "." . $_} << 32) + $result->{$oid_dskTotalLow . "." . $_}); + if ($total_size == 0) { + $self->{output}->output_add(long_msg => "Skipping disk path '" . $display_value . "': size is 0"); + next; + } + } + + $self->{output}->output_add(long_msg => "'" . $display_value . "' [id = " . $_ . ']'); } $self->{output}->output_add(severity => 'OK', - short_msg => 'List disk path: ' . $diskpath_display); - $self->{output}->display(nolabel => 1); + short_msg => 'List disk path:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } diff --git a/snmp_standard/mode/listinterfaces.pm b/snmp_standard/mode/listinterfaces.pm index 39e85c44e..c1e7c67c0 100644 --- a/snmp_standard/mode/listinterfaces.pm +++ b/snmp_standard/mode/listinterfaces.pm @@ -103,8 +103,6 @@ sub run { $self->manage_selection(); my $result = $self->get_additional_information(); - my $interfaces_display = ''; - my $interfaces_display_append = ''; foreach (sort @{$self->{interface_id_selected}}) { my $display_value = $self->get_display_value(id => $_); @@ -113,21 +111,25 @@ sub run { $interface_speed = $self->{option_results}->{speed}; } - next if (defined($self->{option_results}->{skip_speed0}) && $interface_speed == 0); + if (defined($self->{option_results}->{skip_speed0}) && $interface_speed == 0) { + $self->{output}->output_add(long_msg => "Skipping interface '" . $display_value . "': interface speed is 0 and option --skip-speed0 is set"); + next; + } if (defined($self->{option_results}->{filter_status}) && $operstatus[$result->{$oid_operstatus . "." . $_} - 1] !~ /$self->{option_results}->{filter_status}/i) { + $self->{output}->output_add(long_msg => "Skipping interface '" . $display_value . "': no matching filter status"); next; } if (defined($self->{option_results}->{use_adminstatus}) && $operstatus[$result->{$oid_adminstatus . "." . $_} - 1] ne 'up') { + $self->{output}->output_add(long_msg => "Skipping interface '" . $display_value . "': adminstatus is not 'up' and option --use-adminstatus is set"); next; } - $interfaces_display .= $interfaces_display_append . "name = $display_value [speed = $interface_speed, status = " . $operstatus[$result->{$oid_operstatus . "." . $_} - 1] . ", id = $_]"; - $interfaces_display_append = ', '; + $self->{output}->output_add(long_msg => "'" . $display_value . "' [speed = $interface_speed, status = " . $operstatus[$result->{$oid_operstatus . "." . $_} - 1] . ", id = $_]"); } $self->{output}->output_add(severity => 'OK', - short_msg => 'List interfaces: ' . $interfaces_display); - $self->{output}->display(nolabel => 1); + short_msg => 'List interfaces:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); } diff --git a/snmp_standard/mode/liststorages.pm b/snmp_standard/mode/liststorages.pm index 6eade826c..cedc5d104 100644 --- a/snmp_standard/mode/liststorages.pm +++ b/snmp_standard/mode/liststorages.pm @@ -133,22 +133,22 @@ sub run { $self->manage_selection(); my $result = $self->get_additional_information(); - - my $storage_display = ''; - my $storage_display_append = ''; + foreach (sort @{$self->{storage_id_selected}}) { my $display_value = $self->get_display_value(id => $_); my $storage_type = $result->{$oid_hrStorageType . "." . $_}; - next if (!defined($storage_type) || - ($storage_types_manage{$storage_type} !~ /$self->{option_results}->{filter_storage_type}/i)); + if (!defined($storage_type) || + ($storage_types_manage{$storage_type} !~ /$self->{option_results}->{filter_storage_type}/i)) { + $self->{output}->output_add(long_msg => "Skipping storage '" . $display_value . "': no type or no matching filter type"); + next; + } - $storage_display .= $storage_display_append . "name = $display_value [size = " . $result->{$oid_hrStorageSize . "." . $_} * $result->{$oid_hrStorageAllocationUnits . "." . $_} . "B, id = $_]"; - $storage_display_append = ', '; + $self->{output}->output_add(long_msg => "'" . $display_value . "' [size = " . $result->{$oid_hrStorageSize . "." . $_} * $result->{$oid_hrStorageAllocationUnits . "." . $_} . "B, id = $_]"); } $self->{output}->output_add(severity => 'OK', - short_msg => 'List storage: ' . $storage_display); - $self->{output}->display(nolabel => 1); + short_msg => 'List storage:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); $self->{output}->exit(); }