����JFIF��x�x����'403WebShell
403Webshell
Server IP : 78.140.185.180  /  Your IP : 18.117.241.170
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_solusvm_free_res
#!/usr/bin/env perl
use extreme;
use Carp;
use List::Util qw(min);
use Getopt::Long;
use SolusVmAPI::Client;

my ( $warn, $crit, $limits, @w_incidents, @c_incidents );
my $TOP_VM_CONFIG = { disk => 180, mem => 8192 };

sub help {
    print <<EOT;
$0 [-w/--warn 1,2 -c/--crit 3,4]

Plugin accepts three value for warn and crit to detect insufficient resources in each location:
first param: amount of top vms that can be created per location
second param: amount of any vms that can be created per location

Default values:
warn: 3,30
crit: 1,10

Allowed formats:
--warn 1
--crit 1,2

For any unspecified params, corresponding default will be used
EOT
    exit 3;
}

sub parse_args {
    GetOptions(
        'h|help'   => \&help,
        'w|warn=s' => \$warn,
        'c|crit=s' => \$crit
    );
    help() if $warn && $warn !~ /\d+,?/;
    help() if $crit && $crit !~ /\d+,?/;

    $warn //= '';
    $crit //= '';

    ( $limits->{w}{topvm}, $limits->{w}{vm} )
      = ( $1, $2 )
      if $warn =~ /(\d+),?(\d+)?/;
    ( $limits->{c}{topvm}, $limits->{c}{vm} )
      = ( $1, $2 )
      if $crit =~ /(\d+),?(\d+)?/;

    $limits->{w}{topvm}   //= 3;
    $limits->{w}{vm}      //= 30;
    $limits->{c}{topvm}   //= 1;
    $limits->{c}{vm}      //= 10;
}

parse_args();

my $svmapi     = SolusVmAPI::Client->new();
my $nodes_data = $svmapi->get('solusvm-resources')->{'solusvm-resources'};

my $result;

# calculate diff between real resource usage and node limit and how many vms
# can be created
for my $node ( keys $nodes_data->%* ) {
    my $location = $1  if $node =~ /^solusvm\d+\.(.)\.fozzy\.com?/;
    $nodes_data->{$node}{vps} //= '0';
    croak "Can't determine location from $node" if !$location;
    my @top_vms_amount;
    for my $res (qw(mem disk)) {
        $nodes_data->{$node}{$res} //= '0';
        my $diff
          = $nodes_data->{$node}{"max$res"} - $nodes_data->{$node}{$res};
        push @top_vms_amount, int $diff / $TOP_VM_CONFIG->{$res};
    }
    $result->{$location}{topvm} += min(@top_vms_amount);
    $result->{$location}{vm}
      += $nodes_data->{$node}{maxvps} - $nodes_data->{$node}{vps};
}

# determine critical and warning incidents if any
for my $location ( keys $result->%* ) {
    for my $limit ( keys $result->{$location}->%* ) {
        my $incident_msg
          = "$location location has left resources for $result->{$location}{$limit} $limit";
        push @c_incidents, $incident_msg
          if $result->{$location}{$limit} <= $limits->{c}{$limit};
        push @w_incidents, $incident_msg
          if $result->{$location}{$limit} <= $limits->{w}{$limit};
    }
}

if (@c_incidents) {
    say join( "\n", @c_incidents );
    exit 2;
}

if (@w_incidents) {
    say join( "\n", @w_incidents );
    exit 1;
}

say "OK";

for my $location ( sort keys $result->%* ) {
    print "$location: left resources for ";
    for my $limit ( sort keys $result->{$location}->%* ) {
        print "$result->{$location}{$limit} $limit ";
    }
    print "\n";
}

Youez - 2016 - github.com/yon3zu
LinuXploit