Subversion Repositories camp_sysinfo_client_3

Rev

Rev 20 | Rev 37 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

#!/usr/bin/env perl
use warnings;
use strict;  

our $VERSION = '1.0';

# Put some comments here on who wrote it and what it does

BEGIN {
   push @INC, shift;
}

use library;

# 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)

# 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;