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.5
Committed: Sat May 18 18:15:56 2002 UTC (22 years, 5 months ago) by tdb
Content type: text/plain
Branch: MAIN
Changes since 1.4: +20 -1 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

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