Subversion Repositories camp_sysinfo_client_3

Rev

Rev 165 | Rev 254 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 165 Rev 251
Line 4... Line 4...
4
 
4
 
5
# Description: Basic template for modules. Do NOT enable
5
# Description: Basic template for modules. Do NOT enable
6
 
6
 
7
our $VERSION = '1.2';
7
our $VERSION = '1.2';
8
 
8
 
9
exit 1;
9
exit 1; # remove this before using
10
 
10
 
11
# Put some comments here on who wrote it and what it does
11
# Put some comments here on who wrote it and what it does
12
 
12
 
13
# find our location and use it for searching for libraries
13
# find our location and use it for searching for libraries
14
BEGIN {
14
BEGIN {
15
   use FindBin;
15
   use FindBin;
16
   use File::Spec;
16
   use File::Spec;
17
   use lib File::Spec->catdir($FindBin::Bin);
17
   use lib File::Spec->catdir($FindBin::Bin);
18
   eval( 'use library;' );
18
   eval( 'use library;' );
-
 
19
   die "Could not find library.pm in the code directory\n" if $@;
19
   eval( 'use Data::Dumper;' );
20
   eval( 'use Data::Dumper;' );
20
}
21
}
21
 
22
 
-
 
23
# check for valid OS. 
-
 
24
exit 1 unless &checkOS( { 'linux' => undef, 'freebsd' => undef, 'mswin32' => undef } );
-
 
25
 
-
 
26
# check for required commands, return 2 if they don't exist. Enter an full list of all commands required. If one doesn't exist
-
 
27
# script returns a 2
-
 
28
foreach my $command ( 'sysctl', 'df' ) {
-
 
29
   exit 2 unless &validCommandOnSystem( $command );
-
 
30
}
-
 
31
 
22
# category we will use for all values found
32
# category we will use for all values found
23
# see sysinfo for a list of valid categories
33
# see sysinfo for a list of valid categories
24
my $CATEGORY = 'system';
34
my $CATEGORY = 'system';
25
 
35
 
26
# run the commands necessary to do whatever you want to do
36
# run the commands necessary to do whatever you want to do
Line 34... Line 44...
34
 
44
 
35
# now, return the tab delimited output (to STDOUT). $CATEGORY is the first
45
# 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
46
# 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)
47
# the last one. For multiple entries, place on separate lines (ie, newline separated)
38
 
48
 
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
 
-
 
53
# Example of getting last_boot and uptime on a Unix system
49
# Example of getting last_boot and uptime on a Unix system
54
 
-
 
-
 
50
# exit status of 3 or greater means we could not get data for some reason
55
if ( -d '/proc/uptime' ) {
51
if ( -d '/proc/uptime' ) {
56
   my $uptime = qx(cat /proc/uptime);
52
   my $uptime = qx(cat /proc/uptime);
57
   $uptime =~ m/(\d+)/;
53
   $uptime =~ m/(\d+)/;
58
   $uptime = int($1); # uptime now has the up time in seconds
54
   $uptime = int($1); # uptime now has the up time in seconds
59
   print "$CATEGORY\tlast_boot\t" . (time - $uptime) . "\n";
55
   print "$CATEGORY\tlast_boot\t" . (time - $uptime) . "\n";
60
   print "$CATEGORY\tuptime\t" . $uptime . "\n";
56
   print "$CATEGORY\tuptime\t" . $uptime . "\n";
61
   exit 0;
57
   exit 0;
62
} else {
58
} else {
63
   exit 1;
59
   exit 3;
64
}
60
}
65
 
61
 
66
# if you have not done an exit state above (1 indicating no data), do one
62
# if you have not done an exit state above (1 indicating wrong operating system, 2 meaning the commands do not exist), do one
67
# here (exit 0 indicates success)
63
# 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
-
 
70
exit 0;
64
exit 0;