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.2
Committed: Sun Nov 25 20:33:18 2001 UTC (24 years ago) by tdb
Content type: text/plain
Branch: MAIN
Changes since 1.1: +8 -6 lines
Log Message:
Fixed the following Sourceforge bug tracker:
    [ #483806 ] df output on redhat 7.1

The regular expression now more closely checks what it's parsing, ensuring
that ill-parsing lines are ignored completely. A special check as then been
added for the linux "devfs" which seems to split the line in two. This is a
rather specific check, and I have no idea if this will cover all cases...

File Contents

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