92 lines
2.1 KiB
Perl
Executable file
92 lines
2.1 KiB
Perl
Executable file
#!/usr/bin/perl -w
|
|
|
|
use strict;
|
|
use Socket;
|
|
use PVE::Utils;
|
|
use PVE::Cluster;
|
|
use PVE::ConfigServer;
|
|
use PVE::AtomicFile;
|
|
use Getopt::Std;
|
|
use File::Path;
|
|
use Data::Dumper;
|
|
|
|
my $cinfo = PVE::Cluster::clusterinfo();
|
|
my $secret = PVE::Utils::load_auth_secret();
|
|
my $ticket = PVE::Utils::create_auth_ticket ($secret, 'root', 'root');
|
|
|
|
my @listcrit;
|
|
my @listwarn;
|
|
my @listok;
|
|
my $warning_level = 80;
|
|
my $critical_level = 90;
|
|
my $return_status = 0;
|
|
my @listperfdata;
|
|
|
|
# Récupération des options
|
|
my %options=();
|
|
getopts("hw:c:", \%options);
|
|
|
|
if (defined $options{h}) {
|
|
print STDERR "Ce script sert à vérifier l'occupation mémoire des machines hôtes du cluster Proxmox.\n";
|
|
print STDERR "USAGE: script [-c critical_level] [-w warning_level]\n";
|
|
exit 0;
|
|
}
|
|
if (defined $options{w}) {
|
|
$warning_level = $options{w};
|
|
}
|
|
if (defined $options{c}) {
|
|
$critical_level = $options{c};
|
|
}
|
|
|
|
|
|
foreach my $ni (@{$cinfo->{nodes}}) {
|
|
my $state = '-';
|
|
my $conn;
|
|
my $status;
|
|
my $mem;
|
|
|
|
eval {
|
|
$conn = PVE::ConfigClient::connect ($ticket, $cinfo, $ni->{cid});
|
|
if ($status = $conn->ping()->result) {
|
|
$state = 'A';
|
|
}
|
|
};
|
|
|
|
my $err = $@;
|
|
|
|
if ($err) {
|
|
push(@listcrit, $ni->{cid} . ":(down)");
|
|
} else {
|
|
$mem = int (0.5 + ($status->{meminfo}->{mbmemused}*100/$status->{meminfo}->{mbmemtotal}));
|
|
if ($mem >= $critical_level) {
|
|
push(@listcrit, $ni->{cid} . ":$mem");
|
|
} else {
|
|
if ($mem >= $warning_level) {
|
|
push(@listwarn, $ni->{cid} . ":$mem");
|
|
} else {
|
|
push(@listok, $ni->{cid} . ":$mem");
|
|
}
|
|
}
|
|
|
|
push (@listperfdata, $ni->{name} . "_mem="
|
|
. $status->{meminfo}->{mbmemused} . "MB;"
|
|
. ($status->{meminfo}->{mbmemtotal} * $warning_level / 100) . ";"
|
|
. ($status->{meminfo}->{mbmemtotal} * $critical_level / 100) . ";"
|
|
. "0;"
|
|
. $status->{meminfo}->{mbmemtotal});
|
|
}
|
|
}
|
|
|
|
if (scalar(@listcrit) != 0) {
|
|
print "CRITICAL : " . join(", ", @listcrit);
|
|
$return_status = 2;
|
|
} else {
|
|
if (scalar(@listwarn) != 0) {
|
|
print "WARNING : " . join(", ", @listwarn);
|
|
$return_status = 1;
|
|
} else {
|
|
print "OK : " . join(", ", @listok);
|
|
}
|
|
}
|
|
print "|" . join(" ", @listperfdata) . "\n";
|
|
exit $return_status;
|