25 |
|
&include_osver(); |
26 |
|
&include_users(); |
27 |
|
&include_top(); |
28 |
+ |
&include_disk(); |
29 |
|
|
30 |
|
exit(0); |
31 |
|
|
40 |
|
} |
41 |
|
|
42 |
|
# sub to print pairs of data, separated by a single space character. |
43 |
+ |
# If the second argument is undefined, then the pair is still printed, |
44 |
+ |
# however, the value shall be displayed as the string "unknown". |
45 |
|
sub print_pair($$) { |
46 |
|
my($name, $value) = @_; |
47 |
|
|
57 |
|
} |
58 |
|
|
59 |
|
|
60 |
+ |
# sub to find out disk partition information, if it exists. |
61 |
+ |
sub include_disk() { |
62 |
+ |
|
63 |
+ |
# Run the df program. |
64 |
+ |
my(@df) = `df -a`; |
65 |
+ |
|
66 |
+ |
# Only look for these partitions at the moment. |
67 |
+ |
my(@partition_list) = qw{ / /home /var /tmp }; |
68 |
+ |
|
69 |
+ |
# Go through each line of the program, looking for each thing we want. |
70 |
+ |
my($scan_for) = '('.join('|', @partition_list).')'; |
71 |
+ |
my($partition_no) = 0; |
72 |
+ |
for (my($i) = 0; $i < $#df; $i++) { |
73 |
+ |
my($line) = $df[$i]; |
74 |
+ |
$line =~ /^$scan_for\s*\(([^\s]*)\s*\):\s*([0-9]*)\s*blocks\s*([0-9]*)\s*files/; |
75 |
+ |
# $4 will not match unless everything before it does... |
76 |
+ |
if (defined $4) { |
77 |
+ |
my ($partition, $mounted, $blocks, $files) = ($1, $2, $3, $4); |
78 |
+ |
&print_pair("packet.disk.p$partition_no.attributes.name", $partition); |
79 |
+ |
&print_pair("packet.disk.p$partition_no.mounted", $mounted); |
80 |
+ |
&print_pair("packet.disk.p$partition_no.blocks", $blocks); |
81 |
+ |
&print_pair("packet.disk.p$partition_no.name", $files); |
82 |
+ |
++$partition_no; |
83 |
+ |
} |
84 |
+ |
} |
85 |
+ |
|
86 |
+ |
} |
87 |
+ |
|
88 |
+ |
# sub to find out the list of all (non-unique) usernames logged |
89 |
+ |
# in to the machine and how many their are. (not |
90 |
|
sub include_users() { |
91 |
|
|
92 |
|
# Find out all users on this machine. |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
+ |
# sub to run a series of regexps on the output of 'top' to |
105 |
+ |
# gather various machine statistics. |
106 |
|
sub include_top() { |
107 |
|
|
108 |
|
# Find out some numbers from top. |
130 |
|
|
131 |
|
} |
132 |
|
|
133 |
+ |
# sub to get details of the machine's operating system. |
134 |
|
sub include_osver() { |
135 |
|
|
136 |
|
# Find out details about the operating system |
137 |
+ |
# If these values remain undefined, then the print_pair |
138 |
+ |
# function shall show the value to be the string "unknown". |
139 |
|
my($os_name) = `uname -s`; |
140 |
|
my($os_release) = `uname -r`; |
141 |
|
my($os_platform) = `uname -m`; |