����JFIF��x�x����'
Server IP : 78.140.185.180 / Your IP : 18.119.0.207 Web Server : LiteSpeed System : Linux cpanel13.v.fozzy.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : builderbox ( 1072) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /lib64/nagios/plugins/extra/ |
Upload File : |
#!/usr/bin/env perl use strict; use warnings; use Getopt::Long; use LWP::Simple qw(getstore); use Carp qw(croak); use Regexp::Common qw(URI); use IPC::Run qw(run); use Time::Piece; use feature qw(say); my ( $opt_u, $opt_h, $opt_t, $opt_w, $opt_c ); my $exitcode = '0'; GetOptions( "u|urls=s" => \$opt_u, "h|help" => \$opt_h, "w|warning=i" => \$opt_w, "c|critical=i" => \$opt_c, ); if ($opt_h) { my $help_text = <<"END"; Usage: $0 -u url1,url2,... [ --timeout 10 ] Checks the GPG key expiration using the given URLs list -u|--urls List of URLs for gpg keys, separated by comma -w|--warning Warning threshold in days, default is 14 -c|--critical Critical threshold in days, default is 7 -h|--help (--help) END say $help_text; exit; } croak 'The list of URLs not passed!' if !$opt_u; $opt_w //= '14'; $opt_c //= '7'; croak 'The warning threshold cannot be less than critical!' if $opt_w <= $opt_c; my @incidents; for ( split( ',', $opt_u ) ) { my $url = 'http://' . $_; croak "$url is not an URL!" if $url !~ /^$RE{URI}{HTTP}$/; my $tempfile = '/var/tmp/check_repo_keys'; getstore( $url, $tempfile ); my $data = run_cmd( 'gpg', '-v', '--with-colons', $tempfile ); my @subkey_info = ( map { $_ } grep { $_ =~ /^sub/ } split( "\n", $data ) ); my $expire_epoch = ( split( ":", $subkey_info[0] ) )[6]; if ( !$data || !$expire_epoch || $expire_epoch !~ /^\d+$/ ) { unlink $tempfile if -f $tempfile; push @incidents, "Cannot acquire expiration date for $url!"; $exitcode = '1'; next; } my $cur_epoch = time(); my $warn_epoch = $opt_w * 86400; my $crit_epoch = $opt_c * 86400; my $diff_epoch = $expire_epoch - $cur_epoch; if ( $diff_epoch <= $warn_epoch ) { $exitcode = '1'; $exitcode = '2' if $diff_epoch <= $crit_epoch; my $time = Time::Piece->new($expire_epoch); my $expire_date = $time->strftime('%Y-%m-%d'); push @incidents, "The key at $url is about to expire on $expire_date!"; } unlink $tempfile if -f $tempfile; } @incidents ? say join( "\n", @incidents ) : say 'OK'; exit $exitcode; # subs sub run_cmd { my @cmd = @_; my ( $out, $err ); run \@cmd, \undef, \$out, \$err; chomp $out; return $out; }