Subversion Repositories camp_sysinfo_client_3

Rev

Rev 69 | Go to most recent revision | 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
 
2 rodolico 13
BEGIN {
14
   push @INC, shift;
15
}
16
 
17
use library;
18
 
19
# category we will use for all values found
20
# see sysinfo for a list of valid categories
21
my $CATEGORY = 'system';
22
 
20 rodolico 23
# run the commands necessary to do whatever you want to do
24
# The library entered above has some helper routines
25
# validCommandOnSystem -- passed a name, returns the fully qualified path or '' if it does not exist
26
# cleanUp - passed a delimiter and a string, does the following (delimiter can be '')
27
#           chomps the string (removes trailing newlines)
28
#           removes all text BEFORE the delimiter, the delimiter, and any whitespace
29
#           thus, the string 'xxI Am x  a weird string' with a newline will become
30
#           'a weird string' with no newline
2 rodolico 31
 
20 rodolico 32
# now, return the tab delimited output (to STDOUT). $CATEGORY is the first
33
# item, name as recognized by sysinfo is the second and the value is
34
# the last one. For multiple entries, place on separate lines (ie, newline separated)
35
 
57 rodolico 36
# check for commands we want to run
37
my %commands = ( 
38
                  'sysctl' => ''
39
               );
40
 
41
# check the commands for validity
42
foreach my $command ( keys %commands ) {
43
   $commands{$command} = &validCommandOnSystem( $command );
44
}
45
 
46
# bail if we don't have the commands we need
47
exit 1 unless $commands{'sysctl'};
48
 
49
 
20 rodolico 50
# Example of getting last_boot and uptime on a Unix system
51
 
52
if ( -d '/proc/uptime' ) {
2 rodolico 53
   my $uptime = qx(cat /proc/uptime);
54
   $uptime =~ m/(\d+)/;
55
   $uptime = int($1); # uptime now has the up time in seconds
56
   print "$CATEGORY\tlast_boot\t" . (time - $uptime) . "\n";
57
   print "$CATEGORY\tuptime\t" . $uptime . "\n";
20 rodolico 58
   exit 0;
59
} else {
60
   exit 1;
2 rodolico 61
}
62
 
20 rodolico 63
# if you have not done an exit state above (1 indicating no data), do one
64
# here (exit 0 indicates success)
65
# NOTE: you can bail early with exit 1 if you can not process anything
66
# because it is the wrong system or something
2 rodolico 67
exit 0;