| 48 |
rodolico |
1 |
#!/usr/bin/env perl
|
|
|
2 |
use warnings;
|
|
|
3 |
use strict;
|
|
|
4 |
|
|
|
5 |
# Description: Gets information on Unix based systems
|
|
|
6 |
|
|
|
7 |
our $VERSION = '1.0';
|
|
|
8 |
|
|
|
9 |
# Basic Unix module for sysinfo client
|
|
|
10 |
# Author: R. W. Rodolico
|
|
|
11 |
# Date: 2016-04-08
|
|
|
12 |
|
| 51 |
rodolico |
13 |
# gets additional systems information on BSD machine using some standard
|
| 48 |
rodolico |
14 |
# utilities
|
|
|
15 |
|
|
|
16 |
|
| 251 |
rodolico |
17 |
# find our location and use it for searching for libraries
|
| 48 |
rodolico |
18 |
BEGIN {
|
| 251 |
rodolico |
19 |
use FindBin;
|
|
|
20 |
use File::Spec;
|
|
|
21 |
use lib File::Spec->catdir($FindBin::Bin);
|
|
|
22 |
eval( 'use library;' ); die "Could not find library.pm in the code directory\n" if $@;
|
|
|
23 |
eval( 'use Data::Dumper;' );
|
| 48 |
rodolico |
24 |
}
|
|
|
25 |
|
| 251 |
rodolico |
26 |
# check for valid OS.
|
|
|
27 |
exit 1 unless &checkOS( { 'freebsd' => undef } );
|
| 48 |
rodolico |
28 |
|
| 251 |
rodolico |
29 |
# check for required commands, return 2 if they don't exist. Enter an full list of all commands required. If one doesn't exist
|
|
|
30 |
# script returns a 2
|
|
|
31 |
foreach my $command ( 'grep', 'dmesg', 'uname', 'sysctl' ) {
|
|
|
32 |
exit 2 unless &validCommandOnSystem( $command );
|
| 48 |
rodolico |
33 |
}
|
|
|
34 |
|
|
|
35 |
# category we will use for all values found
|
|
|
36 |
# see sysinfo for a list of valid categories
|
|
|
37 |
my $CATEGORY = 'system';
|
|
|
38 |
|
|
|
39 |
my $temp;
|
|
|
40 |
|
| 153 |
rodolico |
41 |
# following removed as they are now gotten through dmidecode module
|
|
|
42 |
#$temp = getSysctlParameter( $commands{ 'sysctl' }, 'hw.ncpu' );
|
|
|
43 |
#print "$CATEGORY\tnum_cpu\t$temp\n" if $temp;
|
| 48 |
rodolico |
44 |
|
| 153 |
rodolico |
45 |
#$temp = getSysctlParameter( $commands{ 'sysctl' }, 'hw.clockrate' );
|
|
|
46 |
#print "$CATEGORY\tcpu_speed\t$temp\n" if $temp;;
|
| 48 |
rodolico |
47 |
|
| 153 |
rodolico |
48 |
#$temp = getSysctlParameter( $commands{ 'sysctl' }, 'hw.model' );
|
|
|
49 |
#print "$CATEGORY\tcpu\t$temp\n" if $temp;
|
| 48 |
rodolico |
50 |
|
|
|
51 |
# all this needs is uname
|
| 153 |
rodolico |
52 |
#print "$CATEGORY\tcpu_sub\t" . &cleanUp('', qx(uname -m)) . "\n" if $commands{'uname'};
|
|
|
53 |
#print "$CATEGORY\tcpu_type\tUNK\n";
|
| 48 |
rodolico |
54 |
|
| 153 |
rodolico |
55 |
#$temp = getSysctlParameter( $commands{ 'sysctl' }, 'hw.realmem' );
|
|
|
56 |
#$temp /= 1024;
|
|
|
57 |
#print "$CATEGORY\tmemory\t$temp\n";
|
| 48 |
rodolico |
58 |
|
| 251 |
rodolico |
59 |
$temp = getSysctlParameter( 'sysctl', 'kern.boottime' );
|
| 55 |
rodolico |
60 |
$temp =~ m/sec = (\d+),/;
|
|
|
61 |
$temp = $1;
|
|
|
62 |
print "$CATEGORY\tlast_boot\t$temp\n";
|
|
|
63 |
|
|
|
64 |
$temp = time - $temp;
|
|
|
65 |
print "$CATEGORY\tuptime\t$temp\n";
|
|
|
66 |
|
|
|
67 |
|
|
|
68 |
|
| 48 |
rodolico |
69 |
exit 0;
|