ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/ihost-perl/plugins/perl/i-scream_disk.pl
Revision: 1.3
Committed: Mon Dec 3 15:14:11 2001 UTC (22 years, 10 months ago) by tdb
Content type: text/plain
Branch: MAIN
Changes since 1.2: +21 -8 lines
Log Message:
Added an exclusion mechanism for sending disk information. A list can now
be specified like this:

my($exclude_list) = "^/nfs/;^/cdrom/";

These are just regular expressions saying ignore anything starting with
either /nfs/ or /cdrom/. These are the defaults as they suit our systems
well - /nfs/ mounts are nfs mounted from other systems, and /cdrom/ mounts
are obviously cd-roms (always 100% full!).

I did consider putting this in an external config file, but the overhead of
reading it in every time was too expensive. As it is this script is run on
every check, so it can be changed "live" anyway.

File Contents

# User Rev Content
1 tdb 1.1 #!/usr/bin/perl -w
2    
3     #-----------------------------------------------------------------
4     # i-scream host plugin - disk information
5     # $Author: tdb1 $
6 tdb 1.3 # $Id: i-scream_disk.pl,v 1.2 2001/11/25 20:33:18 tdb1 Exp $
7 tdb 1.1 #
8     # A short perl script to grab the current disk states and info
9     #-----------------------------------------------------------------
10    
11    
12     $| = 1;
13    
14    
15     # You'd be silly not to use this ;)
16     use strict;
17    
18 tdb 1.3 # Exclude list
19     my($exclude_list) = "^/nfs/;^/cdrom/";
20     my(@exclude_array) = split(';', $exclude_list);
21    
22 tdb 1.1 # Have to hope this will work really.
23     my($ostype) = `uname -s`; chomp($ostype);
24    
25     # Decide which paths we should use.
26     my($dfbin);
27     if ($ostype eq "SunOS") {
28     # covers: Solaris 7/8
29     $dfbin = "/usr/bin/df -akl";
30     }
31     elsif ($ostype eq "Linux") {
32     # covers: Debian r2.2
33     $dfbin = "/bin/df -akl";
34     }
35     elsif ($ostype eq "FreeBSD") {
36     # covers: FreeBSD 4.X
37     $dfbin = "/bin/df -ak";
38     }
39     else {
40     print "i-scream_disk.pl Error: Unable to identify system type - \"$ostype\".\n";
41     print "\"uname -s\" does not report one of the following known types;\n";
42     print " SunOS, Linux, FreeBSD\n";
43     exit(1);
44     }
45    
46     # Run the following components: -
47     &print_ident();
48     &include_disk();
49    
50     # End the program normally.
51     exit(0);
52    
53    
54    
55    
56     # prints out an identifier for this version of the script
57     # this could be used in checks further downstream
58     sub print_ident() {
59 tdb 1.3 print 'packet.plugins.ident.i-scream_disk i-scream_disk.pl $Revision: 1.2 $';
60 tdb 1.1 print "\n";
61     }
62    
63     # sub to print pairs of data, separated by a single space character.
64     # If the second argument is undefined, then the pair is still printed,
65     # however, the value shall be displayed as the the 'default' value
66     # if the passed value was undefined.
67     sub print_pair($$$) {
68     my($default, $name, $value) = @_;
69    
70     if (!defined $value) {
71     $value = $default;
72     }
73    
74     # Remove the trailing linefeed if we've not already done so.
75     chomp($value);
76    
77     # print the pair of data with a space inbetween.
78     print "$name $value\n";
79     }
80    
81    
82     # sub to find out disk partition information, if it exists.
83     sub include_disk() {
84    
85     # Run the df program.
86     my(@df) = `$dfbin`;
87    
88     # Go through each line of the program, looking for each thing we want.
89     my($partition_no) = 0;
90 tdb 1.2 for (my($i) = 0; $i <= $#df; ++$i) {
91 tdb 1.1 my($line) = $df[$i];
92 tdb 1.2 if ($line =~ /^[^\s]+\s*$/) {
93     ++$i;
94     $line .= $df[$i] if defined $df[$i];
95     }
96     if ($line =~ /^([^\s]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+[^\s]+\s+(\/[^\s]*)\s*/) {
97 tdb 1.1 my ($filesystem, $kbytes, $used, $avail, $mount) = ($1, $2, $3, $4, $5);
98 tdb 1.3 my($do_disk) = 1;
99     foreach my $exclusion (@exclude_array) {
100     if ($mount =~ /$exclusion/) {
101     $do_disk = 0;
102     last;
103     }
104     }
105     if($do_disk) {
106     &print_pair("unknown", "packet.disk.p$partition_no.attributes.name", $filesystem);
107     &print_pair(0, "packet.disk.p$partition_no.attributes.kbytes", $kbytes);
108     &print_pair(0, "packet.disk.p$partition_no.attributes.used", $used);
109     &print_pair(0, "packet.disk.p$partition_no.attributes.avail", $avail);
110     &print_pair("unknown", "packet.disk.p$partition_no.attributes.mount", $mount);
111     ++$partition_no;
112     }
113 tdb 1.1 }
114     }
115    
116     }