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