| Line 1... |
Line 1... |
| 1 |
#!/usr/bin/env perl
|
1 |
#!/usr/bin/env perl
|
| 2 |
use warnings;
|
2 |
use warnings;
|
| 3 |
use strict;
|
3 |
use strict;
|
| 4 |
|
4 |
|
| 5 |
# Description: Get Kernel, distro, etc... on Unix systems
|
5 |
use version ; our $VERSION = 'v1.0.0';
|
| 6 |
|
6 |
|
| 7 |
our $VERSION = '1.1';
|
- |
|
| 8 |
|
- |
|
| 9 |
# Linux module for sysinfo client
|
7 |
# Template for modules to be used in sysinfo
|
| 10 |
# Author: R. W. Rodolico
|
8 |
# Author: R. W. Rodolico
|
| 11 |
# Date: 2016-04-08
|
9 |
# Date: 2025-04-02
|
| 12 |
|
10 |
#
|
| 13 |
# gets information on linux systems with lsb on them
|
11 |
# Enter some information about system here
|
| - |
|
12 |
#
|
| - |
|
13 |
# Revision History
|
| - |
|
14 |
#
|
| - |
|
15 |
# 20250402 v4.0.0 Rodolico
|
| - |
|
16 |
# Modified for v4 of sysinfo_client, using extended tests for modules, files used and operating systems
|
| - |
|
17 |
# Underlying code remains unchanged
|
| - |
|
18 |
#
|
| 14 |
|
19 |
|
| 15 |
# find our location and use it for searching for libraries
|
20 |
# find our location and use it for searching for libraries. library.pm must be in the same directory as the calling script
|
| - |
|
21 |
# or, if run interactively, in the parent of the modules
|
| 16 |
BEGIN {
|
22 |
BEGIN {
|
| 17 |
use FindBin;
|
23 |
use FindBin;
|
| 18 |
use File::Spec;
|
24 |
use File::Spec;
|
| 19 |
use lib File::Spec->catdir($FindBin::Bin);
|
25 |
# prepend the bin directory and its parent
|
| 20 |
eval( 'use library;' ); die "Could not find library.pm in the code directory\n" if $@;
|
26 |
use lib File::Spec->catdir($FindBin::Bin), File::Spec->catdir("$FindBin::Bin/..");
|
| 21 |
eval( 'use Data::Dumper;' );
|
27 |
eval( 'use library;' );
|
| - |
|
28 |
die sprintf( "Could not find library.pm in %s, INC is %s\n", __FILE__, join( "\n", @INC ) ) if $@;
|
| 22 |
}
|
29 |
}
|
| 23 |
|
30 |
|
| - |
|
31 |
#####
|
| - |
|
32 |
##### Change these to match your needs
|
| - |
|
33 |
#####
|
| - |
|
34 |
|
| - |
|
35 |
# Make this a list of all the modules we are going to use. You can replace undef with the version you need, if you like
|
| - |
|
36 |
my $modulesList = {
|
| - |
|
37 |
'Data::Dumper' => undef,
|
| - |
|
38 |
};
|
| - |
|
39 |
|
| - |
|
40 |
# hash of commands that are needed for the system. key is the name of the command and, in some cases, the value will become
|
| - |
|
41 |
# the full path (from which or where)
|
| - |
|
42 |
my $commandsList = {
|
| - |
|
43 |
'lsb_release' => undef,
|
| 24 |
# check for valid OS.
|
44 |
'uname' => undef,
|
| - |
|
45 |
};
|
| - |
|
46 |
|
| - |
|
47 |
# list of operating systems this module can be used on.
|
| - |
|
48 |
my $osList = {
|
| - |
|
49 |
# 'mswin32' => undef,
|
| - |
|
50 |
# 'freebsd' => undef,
|
| 25 |
exit 1 unless &checkOS( { 'linux' => undef } );
|
51 |
'linux' => undef,
|
| - |
|
52 |
};
|
| 26 |
|
53 |
|
| 27 |
# check for required commands, return 2 if they don't exist. Enter an full list of all commands required. If one doesn't exist
|
- |
|
| 28 |
# script returns a 2
|
- |
|
| 29 |
foreach my $command ( 'lsb_release', 'uname' ) {
|
- |
|
| 30 |
exit 2 unless &validCommandOnSystem( $command );
|
54 |
# the category the return data should go into. See sysinfo for a list
|
| 31 |
}
|
- |
|
| 32 |
my $CATEGORY = 'operatingsystem';
|
55 |
my $CATEGORY = 'operatingsystem';
|
| 33 |
|
56 |
|
| - |
|
57 |
#####
|
| - |
|
58 |
##### End of required
|
| - |
|
59 |
#####
|
| - |
|
60 |
|
| - |
|
61 |
# some variables needed for our system
|
| - |
|
62 |
my $errorPrepend = 'error: in ' . __FILE__; # this is prepended to any error messages
|
| - |
|
63 |
my @out; # temporary location for each line of output
|
| - |
|
64 |
|
| - |
|
65 |
# Try to load the modules we need. If we can not, then make a list of missing modules for error message.
|
| - |
|
66 |
for my $module ( keys %$modulesList ) {
|
| - |
|
67 |
eval ( "use $module;" );
|
| - |
|
68 |
push @out, "$errorPrepend Could not load $module" if $@;
|
| - |
|
69 |
}
|
| - |
|
70 |
|
| - |
|
71 |
if ( ! @out && ! checkOS ( $osList ) ) { # check if we are on an acceptible operating system
|
| - |
|
72 |
push @out, "$errorPrepend Invalid Operating System";
|
| - |
|
73 |
}
|
| - |
|
74 |
if ( !@out && ! validCommandOnSystem ( $commandsList ) ) {
|
| - |
|
75 |
push @out, "$errorPrepend Can not find some commands needed";
|
| - |
|
76 |
}
|
| - |
|
77 |
if ( !@out ) { # we made it, we have everything, so do the processing
|
| - |
|
78 |
#####
|
| - |
|
79 |
##### Your code starts here. Remember to push all output onto @out
|
| 34 |
my $command = 'lsb_release';
|
80 |
my $command = 'lsb_release';
|
| 35 |
print "$CATEGORY\tdistribution\t" . &cleanUp(':', qx($command -i)) . "\n";
|
81 |
push @out, "$CATEGORY\tdistribution\t" . &cleanUp(':', qx($command -i));
|
| 36 |
print "$CATEGORY\tdescription\t" . &cleanUp(':', qx($command -d)) . "\n";
|
82 |
push @out, "$CATEGORY\tdescription\t" . &cleanUp(':', qx($command -d));
|
| 37 |
print "$CATEGORY\trelease\t" . &cleanUp(':', qx($command -r)) . "\n";
|
83 |
push @out, "$CATEGORY\trelease\t" . &cleanUp(':', qx($command -r));
|
| 38 |
print "$CATEGORY\tcodename\t" . &cleanUp(':', qx($command -c)) . "\n";
|
84 |
push @out, "$CATEGORY\tcodename\t" . &cleanUp(':', qx($command -c));
|
| 39 |
|
85 |
|
| 40 |
$command = 'uname';
|
86 |
$command = 'uname';
|
| 41 |
print "$CATEGORY\tos_name\t" . &cleanUp('', qx($command -s)) . "\n";
|
87 |
push @out, "$CATEGORY\tos_name\t" . &cleanUp('', qx($command -s));
|
| 42 |
print "$CATEGORY\tkernel\t" . &cleanUp('', qx($command -r)) . "\n";
|
88 |
push @out, "$CATEGORY\tkernel\t" . &cleanUp('', qx($command -r));
|
| - |
|
89 |
|
| - |
|
90 |
push @out, "$CATEGORY\tos_version\t" . &cleanUp('', qx(cat /proc/version)) if -e '/proc/version';
|
| - |
|
91 |
#####
|
| - |
|
92 |
##### Your code ends here.
|
| - |
|
93 |
#####
|
| - |
|
94 |
}
|
| - |
|
95 |
|
| - |
|
96 |
# If we are testing from the command line (caller is undef), print the results for debugging
|
| - |
|
97 |
print join( "\n", @out ) . "\n" unless caller;
|
| - |
|
98 |
# called by do, which has a value of the last assignment made, so make the assignment. The equivilent of a return
|
| - |
|
99 |
my $return = join( "\n", @out );
|
| 43 |
|
100 |
|
| 44 |
print "$CATEGORY\tos_version\t" . &cleanUp('', qx(cat /proc/version)) . "\n" if -e '/proc/version';
|
- |
|