Subversion Repositories camp_sysinfo_client_3

Rev

Rev 244 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 rodolico 1
#!/usr/bin/env perl
2
use warnings;
26 rodolico 3
use strict;  
2 rodolico 4
 
37 rodolico 5
# Description: Basic template for modules. Do NOT enable
2 rodolico 6
 
37 rodolico 7
our $VERSION = '1.2';
8
 
9
exit 1;
10
 
20 rodolico 11
# Put some comments here on who wrote it and what it does
12
 
165 rodolico 13
# find our location and use it for searching for libraries
2 rodolico 14
BEGIN {
165 rodolico 15
   use FindBin;
16
   use File::Spec;
17
   use lib File::Spec->catdir($FindBin::Bin);
18
   eval( 'use library;' );
19
   eval( 'use Data::Dumper;' );
2 rodolico 20
}
21
 
22
# category we will use for all values found
23
# see sysinfo for a list of valid categories
24
my $CATEGORY = 'system';
25
 
20 rodolico 26
# run the commands necessary to do whatever you want to do
27
# The library entered above has some helper routines
28
# validCommandOnSystem -- passed a name, returns the fully qualified path or '' if it does not exist
29
# cleanUp - passed a delimiter and a string, does the following (delimiter can be '')
30
#           chomps the string (removes trailing newlines)
31
#           removes all text BEFORE the delimiter, the delimiter, and any whitespace
32
#           thus, the string 'xxI Am x  a weird string' with a newline will become
33
#           'a weird string' with no newline
2 rodolico 34
 
20 rodolico 35
# now, return the tab delimited output (to STDOUT). $CATEGORY is the first
36
# item, name as recognized by sysinfo is the second and the value is
37
# the last one. For multiple entries, place on separate lines (ie, newline separated)
38
 
57 rodolico 39
# check for commands we want to run
40
my %commands = ( 
41
                  'sysctl' => ''
42
               );
43
 
44
# check the commands for validity
45
foreach my $command ( keys %commands ) {
46
   $commands{$command} = &validCommandOnSystem( $command );
47
}
48
 
49
# bail if we don't have the commands we need
50
exit 1 unless $commands{'sysctl'};
51
 
52
 
20 rodolico 53
# Example of getting last_boot and uptime on a Unix system
54
 
55
if ( -d '/proc/uptime' ) {
2 rodolico 56
   my $uptime = qx(cat /proc/uptime);
57
   $uptime =~ m/(\d+)/;
58
   $uptime = int($1); # uptime now has the up time in seconds
59
   print "$CATEGORY\tlast_boot\t" . (time - $uptime) . "\n";
60
   print "$CATEGORY\tuptime\t" . $uptime . "\n";
20 rodolico 61
   exit 0;
62
} else {
63
   exit 1;
2 rodolico 64
}
65
 
20 rodolico 66
# if you have not done an exit state above (1 indicating no data), do one
67
# here (exit 0 indicates success)
68
# NOTE: you can bail early with exit 1 if you can not process anything
69
# because it is the wrong system or something
2 rodolico 70
exit 0;