#!/usr/bin/env perl # Copyright (c) 2025, R. W. Rodolico # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # template.basic # Sensor template for sysinfo v3.8.0 sensors. # # Revision History: # 2025-04-02 RWR v4.0.0 r? expanded module checks # 2026-10-11 Copilot v3.8.0 r? exit-code contract and parser function pattern # 2026-10-12 Copilot v3.8.1 r? added full license header and sub comment block format # 2026-10-13 Claude v3.8.2 r? exit codes per Documentation/README.md (1 wrong os, 2 not applicable, 4 error); no qx package your_module_name_here; use warnings; use strict; use version; our $VERSION = version->declare('v3.8.2'); BEGIN { use FindBin; use File::Spec; use lib File::Spec->catdir($FindBin::Bin), File::Spec->catdir("$FindBin::Bin/.."), File::Spec->catdir("$FindBin::Bin/../.."); eval('use library qw(:all);'); die sprintf("Could not find library.pm in %s, INC is %s\n", __FILE__, join("\n", @INC)) if $@; } my $commandsList = { 'uname' => undef, }; my $osList = { 'linux' => undef, 'freebsd' => undef, }; my $CATEGORY = 'system'; ####################################################### # # parseCommandOutput( $text ) # # Converts command output text into tab-delimited report # lines for this sensor's category. # # Parameters: # $text - command output text # # Returns: # array reference of report output lines # # Side Effects: # none # ####################################################### ## parseCommandOutput # Converts command output text into an arrayref of report lines. sub parseCommandOutput { my $text = shift; my @out; chomp $text; push @out, "$CATEGORY\tkernel\t$text" if $text ne ''; return \@out; } ####################################################### # # main() # # Executes sensor checks, prints output lines to STDOUT, # and returns exit status per sensor contract. # # Parameters: # none # # Returns: # integer exit code # # Side Effects: # runs external command and writes to STDOUT/STDERR # ####################################################### ## main # Executes checks, emits tab lines on STDOUT, and exits with status contract. sub main { if (!checkOS($osList)) { print STDERR "unsupported os\n"; return 1; } if (!validCommandOnSystem($commandsList)) { print STDERR "missing command\n"; return 2; } my $output = runCommand('uname', '-r'); if ($? != 0) { print STDERR "uname -r failed\n"; return 4; } my $lines = parseCommandOutput($output); print join("\n", @{$lines}), "\n" if @{$lines}; return 0; } exit main() unless caller; 1;