From cd790587e6d7d7d92c48a8b7038e5f577a11d925 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Thu, 22 Oct 2020 20:42:26 +0200 Subject: [PATCH] Don't return garbage in mpath discovery if command failed --- zabbix_scripts/disco_mpath_sudo | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/zabbix_scripts/disco_mpath_sudo b/zabbix_scripts/disco_mpath_sudo index 0622d6b..90b022f 100644 --- a/zabbix_scripts/disco_mpath_sudo +++ b/zabbix_scripts/disco_mpath_sudo @@ -22,7 +22,13 @@ if (not defined $multipath){ exit 0; } -foreach (qx($multipath -l -v1)){ +my @dev = qx($multipath -l -v1); +# If command failed (eg no /etc/multipath.conf), then return an empty result +if ($? ne 0){ + print to_json($json, { pretty => $pretty }); + exit 1; +} +foreach (@dev){ chomp; push @{$json}, { '{#MPATH_DEV}' => $_ }; }