summaryrefslogtreecommitdiff
path: root/nagios-check-libs
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2012-04-21 08:11:16 +0000
committerweasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede>2012-04-21 08:11:16 +0000
commitc184ebc092de5d462ec286203f2cac9f238a29e2 (patch)
tree175476fa40defab93fd0ea8bf1423b549a27fcd1 /nagios-check-libs
parent14575ea814ce8eed84e54b82b5fe8bc5527e7576 (diff)
Uli Martens: nagios-check-libs: Use machine readable lsof output format
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@520 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
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;
};
};