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.1
Committed: Mon Nov 19 21:42:11 2001 UTC (22 years, 11 months ago) by tdb
Content type: text/plain
Branch: MAIN
Log Message:
Initial set of i-scream ihost plugins. These are derived completely from
statgrab, and offer no new features over it. They do, however, allow for
parts of this code to be replaced in other languages if required.
Only a few minor changes were made, mainly for efficiency, commenting, and
some changes of chop to chomp :)

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     # $Id: statgrab.pl,v 1.46 2001/11/14 15:18:25 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.46 $';
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     $line =~ /^([^\s]*)\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)\s*[^\s]*\s*(\/[^\s]*)\s*/;
89     # $4 will not match unless everything before it does...
90     if (defined $5) {
91     my ($filesystem, $kbytes, $used, $avail, $mount) = ($1, $2, $3, $4, $5);
92     &print_pair("unknown", "packet.disk.p$partition_no.attributes.name", $filesystem);
93     &print_pair(0, "packet.disk.p$partition_no.attributes.kbytes", $kbytes);
94     &print_pair(0, "packet.disk.p$partition_no.attributes.used", $used);
95     &print_pair(0, "packet.disk.p$partition_no.attributes.avail", $avail);
96     &print_pair("unknown", "packet.disk.p$partition_no.attributes.mount", $mount);
97     ++$partition_no;
98     }
99     }
100    
101     }