summaryrefslogtreecommitdiff
path: root/nagios-check-libs
diff options
context:
space:
mode:
Diffstat (limited to 'nagios-check-libs')
-rwxr-xr-xnagios-check-libs32
1 files changed, 27 insertions, 5 deletions
diff --git a/nagios-check-libs b/nagios-check-libs
index ab89460..977605d 100755
--- a/nagios-check-libs
+++ b/nagios-check-libs
@@ -1,6 +1,7 @@
#!/usr/bin/perl -w
# Copyright (C) 2005, 2006, 2007, 2008, 2012 Peter Palfrader <peter@palfrader.org>
+# 2012 Uli Martens <uli@youam.net>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -28,8 +29,8 @@ use Getopt::Long;
$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
-my $LSOF = '/usr/bin/lsof';
-my $VERSION = '0.1.0';
+my $LSOF = '/usr/bin/lsof -F0';
+my $VERSION = '0.2012042101';
# nagios exit codes
my $OK = 0;
@@ -148,15 +149,36 @@ if ($CHILD_ERROR) { # program failed
dief("$LSOF -n returned with non-zero exit code: ".($CHILD_ERROR / 256)."\n");
};
+my ($process, $pid, $user);
LINE: for my $line (@lsof) {
- my ($process, $pid, $user, $fd, undef, undef, undef, $path, $rest) = split /\s+/, $line;
- if ($line =~ m/\.dpkg-/ || $line =~ m/path inode=/ || $fd eq 'DEL') {
+ if ( $line =~ /^p/ ) {
+ my %fields = map { m/^(.)(.*)$/ ; $1 => $2 } grep { defined $_ and length $_ >1} split /\0/, $line;
+ $process = $fields{c};
+ $pid = $fields{p};
+ $user = $fields{L};
+ next;
+ }
+
+ unless ( $line =~ /^f/ ) {
+ dief("UNKNOWN strange line read from lsof\n");
+ # don't print it because it contains NULL characters...
+ }
+
+ my %fields = map { m/^(.)(.*)$/ ; $1 => $2 } grep { defined $_ and length $_ >1} split /\0/, $line;
+
+ my $fd = $fields{f};
+ my $inode = $fields{i};
+ my $path = $fields{n};
+ if ($path =~ m/\.dpkg-/ || $path =~ m/\(deleted\)/ || $path =~ /path inode=/ || $fd eq 'DEL') {
for my $i (@{$config->{'ignorelist'}}) {
my $ignore = eval($i);
next LINE if $ignore;
}
next if ($INVSERVER && ($process eq 'init') && ($pid == 1) && ($user eq 'root'));
- #$processes{$user}->{$process} = [] unless defined $processes{$user}->{$process};
+ if ( $params->{'verbose'} ) {
+ print STDERR "adding $process($pid) because of [$path]:\n";
+ print STDERR $line;
+ }
$processes{$user}->{$process}->{$pid} = 1;
};
};