set $user to <unknown> if lsof could not tell the username
authorEvgeni Golov <evgeni@debian.org>
Sat, 24 Sep 2016 09:25:33 +0000 (11:25 +0200)
committerPeter Palfrader <peter@palfrader.org>
Sat, 24 Sep 2016 09:54:42 +0000 (11:54 +0200)
this happens e.g. on hosts that run containers in own user namespaces

without, the output will be full of warnings:
 Use of uninitialized value $user in hash element at dsa-check-libs line 188.

Signed-off-by: Peter Palfrader <peter@palfrader.org>
dsa-nagios-checks/checks/dsa-check-libs

index aaaf1ee..fd9e338 100755 (executable)
@@ -156,7 +156,7 @@ LINE: for my $line (@lsof)  {
                my %fields = map { m/^(.)(.*)$/ ; $1 => $2 } grep { defined $_  and length $_ >1} split /\0/, $line;
                $process = $fields{c};
                $pid     = $fields{p};
-               $user    = $fields{L};
+               $user    = $fields{L} || '<unknown>';
                next;
        }