| 1 |
tdb |
1.1 |
#!/usr/bin/perl -w |
| 2 |
|
|
|
| 3 |
tdb |
1.5 |
# |
| 4 |
|
|
# i-scream central monitoring system |
| 5 |
tdb |
1.6 |
# http://www.i-scream.org.uk |
| 6 |
tdb |
1.5 |
# Copyright (C) 2000-2002 i-scream |
| 7 |
|
|
# |
| 8 |
|
|
# This program is free software; you can redistribute it and/or |
| 9 |
|
|
# modify it under the terms of the GNU General Public License |
| 10 |
|
|
# as published by the Free Software Foundation; either version 2 |
| 11 |
|
|
# of the License, or (at your option) any later version. |
| 12 |
|
|
# |
| 13 |
|
|
# This program is distributed in the hope that it will be useful, |
| 14 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
|
|
# GNU General Public License for more details. |
| 17 |
|
|
# |
| 18 |
|
|
# You should have received a copy of the GNU General Public License |
| 19 |
|
|
# along with this program; if not, write to the Free Software |
| 20 |
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 |
|
|
# |
| 22 |
|
|
|
| 23 |
tdb |
1.1 |
#----------------------------------------------------------------- |
| 24 |
|
|
# i-scream host plugin - disk information |
| 25 |
tdb |
1.4 |
# $Author: tdb $ |
| 26 |
tdb |
1.7 |
# $Id: i-scream_disk.pl,v 1.6 2002/05/21 16:47:12 tdb Exp $ |
| 27 |
tdb |
1.1 |
# |
| 28 |
|
|
# A short perl script to grab the current disk states and info |
| 29 |
|
|
#----------------------------------------------------------------- |
| 30 |
|
|
|
| 31 |
|
|
|
| 32 |
|
|
$| = 1; |
| 33 |
|
|
|
| 34 |
|
|
|
| 35 |
|
|
# You'd be silly not to use this ;) |
| 36 |
|
|
use strict; |
| 37 |
|
|
|
| 38 |
tdb |
1.3 |
# Exclude list |
| 39 |
|
|
my($exclude_list) = "^/nfs/;^/cdrom/"; |
| 40 |
|
|
my(@exclude_array) = split(';', $exclude_list); |
| 41 |
|
|
|
| 42 |
tdb |
1.4 |
# Get the OS type from the args, or try towork it out |
| 43 |
|
|
my($ostype) = $ARGV[0]; |
| 44 |
|
|
$ostype = `uname -s` if not defined $ostype; |
| 45 |
|
|
chomp($ostype); |
| 46 |
tdb |
1.1 |
|
| 47 |
|
|
# Decide which paths we should use. |
| 48 |
|
|
my($dfbin); |
| 49 |
|
|
if ($ostype eq "SunOS") { |
| 50 |
|
|
# covers: Solaris 7/8 |
| 51 |
|
|
$dfbin = "/usr/bin/df -akl"; |
| 52 |
|
|
} |
| 53 |
|
|
elsif ($ostype eq "Linux") { |
| 54 |
|
|
# covers: Debian r2.2 |
| 55 |
|
|
$dfbin = "/bin/df -akl"; |
| 56 |
|
|
} |
| 57 |
|
|
elsif ($ostype eq "FreeBSD") { |
| 58 |
|
|
# covers: FreeBSD 4.X |
| 59 |
|
|
$dfbin = "/bin/df -ak"; |
| 60 |
|
|
} |
| 61 |
|
|
else { |
| 62 |
|
|
print "i-scream_disk.pl Error: Unable to identify system type - \"$ostype\".\n"; |
| 63 |
|
|
print "\"uname -s\" does not report one of the following known types;\n"; |
| 64 |
|
|
print " SunOS, Linux, FreeBSD\n"; |
| 65 |
|
|
exit(1); |
| 66 |
|
|
} |
| 67 |
|
|
|
| 68 |
|
|
# Run the following components: - |
| 69 |
|
|
&include_disk(); |
| 70 |
|
|
|
| 71 |
|
|
# End the program normally. |
| 72 |
|
|
exit(0); |
| 73 |
|
|
|
| 74 |
|
|
|
| 75 |
|
|
|
| 76 |
|
|
|
| 77 |
|
|
# sub to print pairs of data, separated by a single space character. |
| 78 |
|
|
# If the second argument is undefined, then the pair is still printed, |
| 79 |
|
|
# however, the value shall be displayed as the the 'default' value |
| 80 |
|
|
# if the passed value was undefined. |
| 81 |
|
|
sub print_pair($$$) { |
| 82 |
|
|
my($default, $name, $value) = @_; |
| 83 |
|
|
|
| 84 |
|
|
if (!defined $value) { |
| 85 |
|
|
$value = $default; |
| 86 |
|
|
} |
| 87 |
|
|
|
| 88 |
|
|
# Remove the trailing linefeed if we've not already done so. |
| 89 |
|
|
chomp($value); |
| 90 |
|
|
|
| 91 |
|
|
# print the pair of data with a space inbetween. |
| 92 |
|
|
print "$name $value\n"; |
| 93 |
|
|
} |
| 94 |
|
|
|
| 95 |
|
|
|
| 96 |
|
|
# sub to find out disk partition information, if it exists. |
| 97 |
|
|
sub include_disk() { |
| 98 |
|
|
|
| 99 |
|
|
# Run the df program. |
| 100 |
|
|
my(@df) = `$dfbin`; |
| 101 |
|
|
|
| 102 |
|
|
# Go through each line of the program, looking for each thing we want. |
| 103 |
|
|
my($partition_no) = 0; |
| 104 |
tdb |
1.2 |
for (my($i) = 0; $i <= $#df; ++$i) { |
| 105 |
tdb |
1.1 |
my($line) = $df[$i]; |
| 106 |
tdb |
1.2 |
if ($line =~ /^[^\s]+\s*$/) { |
| 107 |
|
|
++$i; |
| 108 |
|
|
$line .= $df[$i] if defined $df[$i]; |
| 109 |
|
|
} |
| 110 |
|
|
if ($line =~ /^([^\s]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+[^\s]+\s+(\/[^\s]*)\s*/) { |
| 111 |
tdb |
1.1 |
my ($filesystem, $kbytes, $used, $avail, $mount) = ($1, $2, $3, $4, $5); |
| 112 |
tdb |
1.3 |
my($do_disk) = 1; |
| 113 |
|
|
foreach my $exclusion (@exclude_array) { |
| 114 |
|
|
if ($mount =~ /$exclusion/) { |
| 115 |
|
|
$do_disk = 0; |
| 116 |
|
|
last; |
| 117 |
|
|
} |
| 118 |
|
|
} |
| 119 |
|
|
if($do_disk) { |
| 120 |
|
|
&print_pair("unknown", "packet.disk.p$partition_no.attributes.name", $filesystem); |
| 121 |
|
|
&print_pair(0, "packet.disk.p$partition_no.attributes.kbytes", $kbytes); |
| 122 |
|
|
&print_pair(0, "packet.disk.p$partition_no.attributes.used", $used); |
| 123 |
|
|
&print_pair(0, "packet.disk.p$partition_no.attributes.avail", $avail); |
| 124 |
|
|
&print_pair("unknown", "packet.disk.p$partition_no.attributes.mount", $mount); |
| 125 |
|
|
++$partition_no; |
| 126 |
|
|
} |
| 127 |
tdb |
1.1 |
} |
| 128 |
|
|
} |
| 129 |
|
|
|
| 130 |
|
|
} |