20 |
rodolico |
1 |
#!/usr/bin/env perl
|
|
|
2 |
use warnings;
|
2 |
rodolico |
3 |
|
20 |
rodolico |
4 |
$main::VERSION = '1.0';
|
2 |
rodolico |
5 |
|
20 |
rodolico |
6 |
# Put some comments here on who wrote it and what it does
|
|
|
7 |
|
2 |
rodolico |
8 |
BEGIN {
|
|
|
9 |
push @INC, shift;
|
|
|
10 |
}
|
|
|
11 |
|
|
|
12 |
use library;
|
|
|
13 |
|
|
|
14 |
# category we will use for all values found
|
|
|
15 |
# see sysinfo for a list of valid categories
|
|
|
16 |
my $CATEGORY = 'system';
|
|
|
17 |
|
20 |
rodolico |
18 |
# run the commands necessary to do whatever you want to do
|
|
|
19 |
# The library entered above has some helper routines
|
|
|
20 |
# validCommandOnSystem -- passed a name, returns the fully qualified path or '' if it does not exist
|
|
|
21 |
# cleanUp - passed a delimiter and a string, does the following (delimiter can be '')
|
|
|
22 |
# chomps the string (removes trailing newlines)
|
|
|
23 |
# removes all text BEFORE the delimiter, the delimiter, and any whitespace
|
|
|
24 |
# thus, the string 'xxI Am x a weird string' with a newline will become
|
|
|
25 |
# 'a weird string' with no newline
|
2 |
rodolico |
26 |
|
20 |
rodolico |
27 |
# now, return the tab delimited output (to STDOUT). $CATEGORY is the first
|
|
|
28 |
# item, name as recognized by sysinfo is the second and the value is
|
|
|
29 |
# the last one. For multiple entries, place on separate lines (ie, newline separated)
|
|
|
30 |
|
|
|
31 |
# Example of getting last_boot and uptime on a Unix system
|
|
|
32 |
|
|
|
33 |
if ( -d '/proc/uptime' ) {
|
2 |
rodolico |
34 |
my $uptime = qx(cat /proc/uptime);
|
|
|
35 |
$uptime =~ m/(\d+)/;
|
|
|
36 |
$uptime = int($1); # uptime now has the up time in seconds
|
|
|
37 |
print "$CATEGORY\tlast_boot\t" . (time - $uptime) . "\n";
|
|
|
38 |
print "$CATEGORY\tuptime\t" . $uptime . "\n";
|
20 |
rodolico |
39 |
exit 0;
|
|
|
40 |
} else {
|
|
|
41 |
exit 1;
|
2 |
rodolico |
42 |
}
|
|
|
43 |
|
20 |
rodolico |
44 |
# if you have not done an exit state above (1 indicating no data), do one
|
|
|
45 |
# here (exit 0 indicates success)
|
|
|
46 |
# NOTE: you can bail early with exit 1 if you can not process anything
|
|
|
47 |
# because it is the wrong system or something
|
2 |
rodolico |
48 |
exit 0;
|