Rev 154 | Rev 244 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
#!/usr/bin/env perl
use warnings;
use strict;
# Description: Basic template for modules. Do NOT enable
our $VERSION = '1.2';
exit 1;
# Put some comments here on who wrote it and what it does
# find our location and use it for searching for libraries
BEGIN {
use FindBin;
use File::Spec;
use lib File::Spec->catdir($FindBin::Bin);
eval( 'use library;' );
eval( 'use Data::Dumper;' );
}
# category we will use for all values found
# see sysinfo for a list of valid categories
my $CATEGORY = 'system';
# run the commands necessary to do whatever you want to do
# The library entered above has some helper routines
# validCommandOnSystem -- passed a name, returns the fully qualified path or '' if it does not exist
# cleanUp - passed a delimiter and a string, does the following (delimiter can be '')
# chomps the string (removes trailing newlines)
# removes all text BEFORE the delimiter, the delimiter, and any whitespace
# thus, the string 'xxI Am x a weird string' with a newline will become
# 'a weird string' with no newline
# now, return the tab delimited output (to STDOUT). $CATEGORY is the first
# item, name as recognized by sysinfo is the second and the value is
# the last one. For multiple entries, place on separate lines (ie, newline separated)
# check for commands we want to run
my %commands = (
'sysctl' => ''
);
# check the commands for validity
foreach my $command ( keys %commands ) {
$commands{$command} = &validCommandOnSystem( $command );
}
# bail if we don't have the commands we need
exit 1 unless $commands{'sysctl'};
# Example of getting last_boot and uptime on a Unix system
if ( -d '/proc/uptime' ) {
my $uptime = qx(cat /proc/uptime);
$uptime =~ m/(\d+)/;
$uptime = int($1); # uptime now has the up time in seconds
print "$CATEGORY\tlast_boot\t" . (time - $uptime) . "\n";
print "$CATEGORY\tuptime\t" . $uptime . "\n";
exit 0;
} else {
exit 1;
}
# if you have not done an exit state above (1 indicating no data), do one
# here (exit 0 indicates success)
# NOTE: you can bail early with exit 1 if you can not process anything
# because it is the wrong system or something
exit 0;