Use a new separator ('~' by default). (permits to use regexp for filters)
git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@71 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
parent
81933cfa69
commit
3929e91a7c
|
@ -6,9 +6,10 @@ use IO::Socket;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
|
|
||||||
my $PROGNAME = $0;
|
my $PROGNAME = $0;
|
||||||
my $VERSION = "1.4.1";
|
my $VERSION = "1.5.0";
|
||||||
my %ERRORS = ('OK' => 0, 'WARNING' => 1, 'CRITICAL' => 2, 'UNKNOWN' => 3, 'DEPENDENT' => 4);
|
my %ERRORS = (OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3, DEPENDENT => 4);
|
||||||
my $socket;
|
my $socket;
|
||||||
|
my $separatorin = '~';
|
||||||
|
|
||||||
sub print_help();
|
sub print_help();
|
||||||
sub print_usage();
|
sub print_usage();
|
||||||
|
@ -59,14 +60,14 @@ GetOptions(
|
||||||
"critical2=i" => \$OPTION{'critical2'},
|
"critical2=i" => \$OPTION{'critical2'},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (defined($OPTION{'version'})) {
|
if (defined($OPTION{version})) {
|
||||||
print_revision($PROGNAME, $VERSION);
|
print_revision($PROGNAME, $VERSION);
|
||||||
exit $ERRORS{'OK'};
|
exit $ERRORS{OK};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined($OPTION{'help'})) {
|
if (defined($OPTION{help})) {
|
||||||
print_help();
|
print_help();
|
||||||
exit $ERRORS{'OK'};
|
exit $ERRORS{OK};
|
||||||
}
|
}
|
||||||
|
|
||||||
#############
|
#############
|
||||||
|
@ -218,7 +219,7 @@ sub myconnect {
|
||||||
PeerAddr => $OPTION{'esxd-host'},
|
PeerAddr => $OPTION{'esxd-host'},
|
||||||
PeerPort => $OPTION{'esxd-port'}))) {
|
PeerPort => $OPTION{'esxd-port'}))) {
|
||||||
print "Cannot connect to on '$OPTION{'esxd-host'}': $!\n";
|
print "Cannot connect to on '$OPTION{'esxd-host'}': $!\n";
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
$socket->autoflush(1);
|
$socket->autoflush(1);
|
||||||
}
|
}
|
||||||
|
@ -231,116 +232,121 @@ sub maintenancehost_check_arg {
|
||||||
if (!defined($OPTION{'esx-host'})) {
|
if (!defined($OPTION{'esx-host'})) {
|
||||||
print "Option --esx-host is required\n";
|
print "Option --esx-host is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub maintenancehost_get_str {
|
sub maintenancehost_get_str {
|
||||||
return "maintenancehost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'};
|
return join($separatorin,
|
||||||
|
('maintenancehost', $OPTION{vsphere}, $OPTION{'esx-host'}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub statushost_check_arg {
|
sub statushost_check_arg {
|
||||||
if (!defined($OPTION{'esx-host'})) {
|
if (!defined($OPTION{'esx-host'})) {
|
||||||
print "Option --esx-host is required\n";
|
print "Option --esx-host is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub statushost_get_str {
|
sub statushost_get_str {
|
||||||
return "statushost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'};
|
return join($separatorin,
|
||||||
|
('statushost', $OPTION{vsphere}, $OPTION{'esx-host'}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub healthhost_check_arg {
|
sub healthhost_check_arg {
|
||||||
if (!defined($OPTION{'esx-host'})) {
|
if (!defined($OPTION{'esx-host'})) {
|
||||||
print "Option --esx-host is required\n";
|
print "Option --esx-host is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub healthhost_get_str {
|
sub healthhost_get_str {
|
||||||
return "healthhost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'};
|
return join($separatorin,
|
||||||
|
('healthhost', $OPTION{vsphere}, $OPTION{'esx-host'}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub datastoreusage_check_arg {
|
sub datastoreusage_check_arg {
|
||||||
if (!defined($OPTION{'datastore'})) {
|
if (!defined($OPTION{datastore})) {
|
||||||
print "Option --datastore is required\n";
|
print "Option --datastore is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warning'})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{'warning'} = 80;
|
$OPTION{warning} = 80;
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical'})) {
|
if (!defined($OPTION{critical})) {
|
||||||
$OPTION{'critical'} = 90;
|
$OPTION{critical} = 90;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub datastoreusage_get_str {
|
sub datastoreusage_get_str {
|
||||||
return "datastore-usage|" . $OPTION{'vsphere'} . "|" . $OPTION{'datastore'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
return join($separatorin,
|
||||||
|
('datastore-usage', $OPTION{vsphere}, $OPTION{datastore}, $OPTION{warning}, $OPTION{critical}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub datastoreio_check_arg {
|
sub datastoreio_check_arg {
|
||||||
if (!defined($OPTION{'datastore'})) {
|
if (!defined($OPTION{'datastore'})) {
|
||||||
print "Option --datastore is required\n";
|
print "Option --datastore is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warning'})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{'warning'} = '';
|
$OPTION{warning} = '';
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical'})) {
|
if (!defined($OPTION{critical})) {
|
||||||
$OPTION{'critical'} = '';
|
$OPTION{critical} = '';
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub datastoreio_get_str {
|
sub datastoreio_get_str {
|
||||||
return "datastore-io|" . $OPTION{'vsphere'} . "|" . $OPTION{'datastore'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
return join($separatorin,
|
||||||
|
('datastore-io', $OPTION{vsphere}, $OPTION{datastore}, $OPTION{warning}, $OPTION{critical}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub datastoresnapshots_check_arg {
|
sub datastoresnapshots_check_arg {
|
||||||
if (!defined($OPTION{'datastore'})) {
|
if (!defined($OPTION{datastore})) {
|
||||||
print "Option --datastore is required\n";
|
print "Option --datastore is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warning'})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{'warning'} = '';
|
$OPTION{warning} = '';
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical'})) {
|
if (!defined($OPTION{critical})) {
|
||||||
$OPTION{'critical'} = '';
|
$OPTION{critical} = '';
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warning2'})) {
|
if (!defined($OPTION{warning2})) {
|
||||||
$OPTION{'warning2'} = '';
|
$OPTION{warning2} = '';
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical2'})) {
|
if (!defined($OPTION{critical2})) {
|
||||||
$OPTION{'critical2'} = '';
|
$OPTION{critical2} = '';
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub datastoresnapshots_get_str {
|
sub datastoresnapshots_get_str {
|
||||||
return "datastore-snapshots|" . $OPTION{'vsphere'} . "|" . $OPTION{'datastore'}
|
return join($separatorin,
|
||||||
. "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'} . "|" . $OPTION{'warning2'} . "|" . $OPTION{'critical2'};
|
('datastore-snapshots', $OPTION{vsphere}, $OPTION{datastore}, $OPTION{warning}, $OPTION{critical}, $OPTION{warning2}, $OPTION{critical2}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub cpuhost_check_arg {
|
sub cpuhost_check_arg {
|
||||||
if (!defined($OPTION{'esx-host'})) {
|
if (!defined($OPTION{'esx-host'})) {
|
||||||
print "Option --esx-host is required\n";
|
print "Option --esx-host is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warning'})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{'warning'} = 80;
|
$OPTION{warning} = 80;
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical'})) {
|
if (!defined($OPTION{critical})) {
|
||||||
$OPTION{'critical'} = 90;
|
$OPTION{critical} = 90;
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'light-perfdata'})) {
|
if (!defined($OPTION{'light-perfdata'})) {
|
||||||
$OPTION{'light-perfdata'} = 0;
|
$OPTION{'light-perfdata'} = 0;
|
||||||
|
@ -349,20 +355,21 @@ sub cpuhost_check_arg {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub cpuhost_get_str {
|
sub cpuhost_get_str {
|
||||||
return "cpuhost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'} . "|" . $OPTION{'light-perfdata'};
|
return join($separatorin,
|
||||||
|
('cpuhost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{warning}, $OPTION{critical}, $OPTION{'light-perfdata'}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub datastoreshost_check_arg {
|
sub datastoreshost_check_arg {
|
||||||
if (!defined($OPTION{'esx-host'})) {
|
if (!defined($OPTION{'esx-host'})) {
|
||||||
print "Option --esx-host is required\n";
|
print "Option --esx-host is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warning'})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{'warning'} = '';
|
$OPTION{warning} = '';
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical'})) {
|
if (!defined($OPTION{critical})) {
|
||||||
$OPTION{'critical'} = '';
|
$OPTION{critical} = '';
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'filter-datastores'})) {
|
if (!defined($OPTION{'filter-datastores'})) {
|
||||||
$OPTION{'filter-datastores'} = '';
|
$OPTION{'filter-datastores'} = '';
|
||||||
|
@ -371,244 +378,257 @@ sub datastoreshost_check_arg {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub datastoreshost_get_str {
|
sub datastoreshost_get_str {
|
||||||
return "datastoreshost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'} . "|" . $OPTION{'filter-datastores'};
|
return join($separatorin,
|
||||||
|
('datastoreshost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{warning}, $OPTION{critical} , $OPTION{'filter-datastores'}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub memhost_check_arg {
|
sub memhost_check_arg {
|
||||||
if (!defined($OPTION{'esx-host'})) {
|
if (!defined($OPTION{'esx-host'})) {
|
||||||
print "Option --esx-host is required\n";
|
print "Option --esx-host is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warning'})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{'warning'} = 80;
|
$OPTION{warning} = 80;
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical'})) {
|
if (!defined($OPTION{critical})) {
|
||||||
$OPTION{'critical'} = 90;
|
$OPTION{critical} = 90;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub memhost_get_str {
|
sub memhost_get_str {
|
||||||
return "memhost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
return join($separatorin,
|
||||||
|
('memhost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{warning}, $OPTION{critical}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub swaphost_check_arg {
|
sub swaphost_check_arg {
|
||||||
if (!defined($OPTION{'esx-host'})) {
|
if (!defined($OPTION{'esx-host'})) {
|
||||||
print "Option --esx-host is required\n";
|
print "Option --esx-host is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warning'})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{'warning'} = 0.8;
|
$OPTION{warning} = 0.8;
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical'})) {
|
if (!defined($OPTION{critical})) {
|
||||||
$OPTION{'critical'} = 1;
|
$OPTION{critical} = 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub swaphost_get_str {
|
sub swaphost_get_str {
|
||||||
return "swaphost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
return join($separatorin,
|
||||||
|
('swaphost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{warning}, $OPTION{critical}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub nethost_check_arg {
|
sub nethost_check_arg {
|
||||||
if (!defined($OPTION{'esx-host'})) {
|
if (!defined($OPTION{'esx-host'})) {
|
||||||
print "Option --esx-host is required\n";
|
print "Option --esx-host is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'nic'})) {
|
if (!defined($OPTION{nic})) {
|
||||||
print "Option --nic is required\n";
|
print "Option --nic is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warning'})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{'warning'} = 80;
|
$OPTION{warning} = 80;
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical'})) {
|
if (!defined($OPTION{critical})) {
|
||||||
$OPTION{'critical'} = 90;
|
$OPTION{critical} = 90;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub nethost_get_str {
|
sub nethost_get_str {
|
||||||
return "nethost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'} . "|" . $OPTION{'nic'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
return join($separatorin,
|
||||||
|
('nethost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{nic}, $OPTION{warning}, $OPTION{critical}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub countvmhost_check_arg {
|
sub countvmhost_check_arg {
|
||||||
if (!defined($OPTION{'esx-host'})) {
|
if (!defined($OPTION{'esx-host'})) {
|
||||||
print "Option --esx-host is required\n";
|
print "Option --esx-host is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warning'})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{'warning'} = '';
|
$OPTION{warning} = '';
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical'})) {
|
if (!defined($OPTION{critical})) {
|
||||||
$OPTION{'critical'} = '';
|
$OPTION{critical} = '';
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub countvmhost_get_str {
|
sub countvmhost_get_str {
|
||||||
return "countvmhost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
return join($separatorin,
|
||||||
|
('countvmhost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{warning}, $OPTION{critical}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub uptimehost_check_arg {
|
sub uptimehost_check_arg {
|
||||||
if (!defined($OPTION{'esx-host'})) {
|
if (!defined($OPTION{'esx-host'})) {
|
||||||
print "Option --esx-host is required\n";
|
print "Option --esx-host is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub uptimehost_get_str {
|
sub uptimehost_get_str {
|
||||||
return "uptimehost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'};
|
return join($separatorin,
|
||||||
|
('uptimehost', $OPTION{vsphere}, $OPTION{'esx-host'}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub cpuvm_check_arg {
|
sub cpuvm_check_arg {
|
||||||
if (!defined($OPTION{'vm'})) {
|
if (!defined($OPTION{vm})) {
|
||||||
print "Option --vm is required\n";
|
print "Option --vm is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warning'})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{'warning'} = 80;
|
$OPTION{warning} = 80;
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical'})) {
|
if (!defined($OPTION{critical})) {
|
||||||
$OPTION{'critical'} = 90;
|
$OPTION{critical} = 90;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub cpuvm_get_str {
|
sub cpuvm_get_str {
|
||||||
return "cpuvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
return join($separatorin,
|
||||||
|
('cpuvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{warning}, $OPTION{critical}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub toolsvm_check_arg {
|
sub toolsvm_check_arg {
|
||||||
if (!defined($OPTION{'vm'})) {
|
if (!defined($OPTION{vm})) {
|
||||||
print "Option --vm is required\n";
|
print "Option --vm is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub toolsvm_get_str {
|
sub toolsvm_get_str {
|
||||||
return "toolsvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'};
|
return join($separatorin,
|
||||||
|
('toolsvm', $OPTION{vsphere}, $OPTION{vm}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub snapshotvm_check_arg {
|
sub snapshotvm_check_arg {
|
||||||
if (!defined($OPTION{'vm'})) {
|
if (!defined($OPTION{vm})) {
|
||||||
print "Option --vm is required\n";
|
print "Option --vm is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'older'})) {
|
if (!defined($OPTION{older})) {
|
||||||
$OPTION{'older'} = '';
|
$OPTION{older} = '';
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warn'})) {
|
if (!defined($OPTION{warn})) {
|
||||||
$OPTION{'warn'} = 0;
|
$OPTION{warn} = 0;
|
||||||
} else {
|
} else {
|
||||||
$OPTION{'warn'} = 1;
|
$OPTION{warn} = 1;
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'crit'})) {
|
if (!defined($OPTION{crit})) {
|
||||||
$OPTION{'crit'} = 0;
|
$OPTION{crit} = 0;
|
||||||
} else {
|
} else {
|
||||||
$OPTION{'crit'} = 1;
|
$OPTION{crit} = 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub snapshotvm_get_str {
|
sub snapshotvm_get_str {
|
||||||
return "snapshotvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'older'} . "|" . $OPTION{'warn'} . "|" . $OPTION{'crit'};
|
return join($separatorin,
|
||||||
|
('snapshotvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{older}, $OPTION{warn}, $OPTION{crit}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub datastoresvm_check_arg {
|
sub datastoresvm_check_arg {
|
||||||
if (!defined($OPTION{'vm'})) {
|
if (!defined($OPTION{vm})) {
|
||||||
print "Option --vm is required\n";
|
print "Option --vm is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warning'})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{'warning'} = '';
|
$OPTION{warning} = '';
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical'})) {
|
if (!defined($OPTION{critical})) {
|
||||||
$OPTION{'critical'} = '';
|
$OPTION{critical} = '';
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub datastoresvm_get_str {
|
sub datastoresvm_get_str {
|
||||||
return "datastoresvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
return join($separatorin,
|
||||||
|
('datastoresvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{warning}, $OPTION{critical}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub memvm_check_arg {
|
sub memvm_check_arg {
|
||||||
if (!defined($OPTION{'vm'})) {
|
if (!defined($OPTION{vm})) {
|
||||||
print "Option --vm is required\n";
|
print "Option --vm is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warning'})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{'warning'} = 80;
|
$OPTION{warning} = 80;
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical'})) {
|
if (!defined($OPTION{critical})) {
|
||||||
$OPTION{'critical'} = 90;
|
$OPTION{critical} = 90;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub memvm_get_str {
|
sub memvm_get_str {
|
||||||
return "memvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
return join($separatorin,
|
||||||
|
('memvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{warning}, $OPTION{critical}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub swapvm_check_arg {
|
sub swapvm_check_arg {
|
||||||
if (!defined($OPTION{'vm'})) {
|
if (!defined($OPTION{vm})) {
|
||||||
print "Option --vm is required\n";
|
print "Option --vm is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warning'})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{'warning'} = 0.8;
|
$OPTION{warning} = 0.8;
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical'})) {
|
if (!defined($OPTION{critical})) {
|
||||||
$OPTION{'critical'} = 1;
|
$OPTION{critical} = 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub swapvm_get_str {
|
sub swapvm_get_str {
|
||||||
return "swapvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
return join($separatorin,
|
||||||
|
('swapvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{warning}, $OPTION{critical}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub thinprovisioningvm_check_arg {
|
sub thinprovisioningvm_check_arg {
|
||||||
if (!defined($OPTION{'vm'})) {
|
if (!defined($OPTION{vm})) {
|
||||||
print "Option --vm is required\n";
|
print "Option --vm is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'on'})) {
|
if (!defined($OPTION{on})) {
|
||||||
$OPTION{'on'} = 0;
|
$OPTION{on} = 0;
|
||||||
} else {
|
} else {
|
||||||
$OPTION{'on'} = 1;
|
$OPTION{on} = 1;
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'warn'})) {
|
if (!defined($OPTION{warn})) {
|
||||||
$OPTION{'warn'} = 0;
|
$OPTION{warn} = 0;
|
||||||
} else {
|
} else {
|
||||||
$OPTION{'warn'} = 1;
|
$OPTION{warn} = 1;
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'crit'})) {
|
if (!defined($OPTION{crit})) {
|
||||||
$OPTION{'crit'} = 0;
|
$OPTION{crit} = 0;
|
||||||
} else {
|
} else {
|
||||||
$OPTION{'crit'} = 1;
|
$OPTION{crit} = 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub thinprovisioningvm_get_str {
|
sub thinprovisioningvm_get_str {
|
||||||
return "thinprovisioningvm|" . $OPTION{'vsphere'} . "|" . $OPTION{'vm'} . "|" . $OPTION{'on'} . "|" . $OPTION{'warn'} . "|" . $OPTION{'crit'};
|
return join($separatorin,
|
||||||
|
('thinprovisioningvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{on}, $OPTION{warn}, $OPTION{crit}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -617,7 +637,8 @@ sub listhost_check_arg {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub listhost_get_str {
|
sub listhost_get_str {
|
||||||
return "listhost|" . $OPTION{'vsphere'};
|
return join($separatorin,
|
||||||
|
('listhost', $OPTION{vsphere}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub listdatastore_check_arg {
|
sub listdatastore_check_arg {
|
||||||
|
@ -625,20 +646,22 @@ sub listdatastore_check_arg {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub listdatastore_get_str {
|
sub listdatastore_get_str {
|
||||||
return "listdatastore|" . $OPTION{'vsphere'};
|
return join($separatorin,
|
||||||
|
('listdatastore', $OPTION{vsphere}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub listnichost_check_arg {
|
sub listnichost_check_arg {
|
||||||
if (!defined($OPTION{'esx-host'})) {
|
if (!defined($OPTION{'esx-host'})) {
|
||||||
print "Option --esx-host is required\n";
|
print "Option --esx-host is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub listnichost_get_str {
|
sub listnichost_get_str {
|
||||||
return "listnichost|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'};
|
return join($separatorin,
|
||||||
|
('listnichost', $OPTION{vsphere}, $OPTION{'esx-host'}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getmap_check_arg {
|
sub getmap_check_arg {
|
||||||
|
@ -649,21 +672,23 @@ sub getmap_check_arg {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getmap_get_str {
|
sub getmap_get_str {
|
||||||
return "getmap|" . $OPTION{'vsphere'} . "|" . $OPTION{'esx-host'};
|
return join($separatorin,
|
||||||
|
('getmap', $OPTION{vsphere}, $OPTION{'esx-host'}));
|
||||||
}
|
}
|
||||||
|
|
||||||
sub stats_check_arg {
|
sub stats_check_arg {
|
||||||
if (!defined($OPTION{'warning'})) {
|
if (!defined($OPTION{warning})) {
|
||||||
$OPTION{'warning'} = "";
|
$OPTION{warning} = "";
|
||||||
}
|
}
|
||||||
if (!defined($OPTION{'critical'})) {
|
if (!defined($OPTION{critical})) {
|
||||||
$OPTION{'critical'} = "";
|
$OPTION{critical} = "";
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub stats_get_str {
|
sub stats_get_str {
|
||||||
return "stats||" . $OPTION{'warning'} . "|" . $OPTION{'critical'};
|
return join($separatorin,
|
||||||
|
('stats', $OPTION{warning}, $OPTION{critical}));
|
||||||
}
|
}
|
||||||
|
|
||||||
#################
|
#################
|
||||||
|
@ -672,18 +697,18 @@ sub stats_get_str {
|
||||||
if (!defined($OPTION{'esxd-host'})) {
|
if (!defined($OPTION{'esxd-host'})) {
|
||||||
print "Option -H (--esxd-host) is required\n";
|
print "Option -H (--esxd-host) is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!defined($OPTION{'usage'})) {
|
if (!defined($OPTION{usage})) {
|
||||||
print "Option -u (--usage) is required\n";
|
print "Option -u (--usage) is required\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
if ($OPTION{'usage'} !~ /^(healthhost|datastore-usage|datastore-io|datastore-snapshots|maintenancehost|statushost|cpuhost|datastoreshost|nethost|memhost|swaphost|countvmhost|uptimehost|cpuvm|toolsvm|snapshotvm|datastoresvm|memvm|swapvm|thinprovisioningvm|listhost|listdatastore|listnichost|getmap|stats)$/) {
|
if ($OPTION{usage} !~ /^(healthhost|datastore-usage|datastore-io|datastore-snapshots|maintenancehost|statushost|cpuhost|datastoreshost|nethost|memhost|swaphost|countvmhost|uptimehost|cpuvm|toolsvm|snapshotvm|datastoresvm|memvm|swapvm|thinprovisioningvm|listhost|listdatastore|listnichost|getmap|stats)$/) {
|
||||||
print "Usage value is unknown\n";
|
print "Usage value is unknown\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
exit $ERRORS{'UNKNOWN'};
|
exit $ERRORS{UNKNOWN};
|
||||||
}
|
}
|
||||||
|
|
||||||
$OPTION{'usage'} =~ s/-//g;
|
$OPTION{'usage'} =~ s/-//g;
|
||||||
|
|
|
@ -20,7 +20,7 @@ BEGIN {
|
||||||
use base qw(centreon::script);
|
use base qw(centreon::script);
|
||||||
use vars qw(%centreonesxd_config);
|
use vars qw(%centreonesxd_config);
|
||||||
|
|
||||||
my %handlers = ('TERM' => {}, 'HUP' => {}, 'CHLD' => {});
|
my %handlers = (TERM => {}, HUP => {}, CHLD => {});
|
||||||
my @load_modules = ('centreon::esxd::cmdcountvmhost',
|
my @load_modules = ('centreon::esxd::cmdcountvmhost',
|
||||||
'centreon::esxd::cmdcpuhost',
|
'centreon::esxd::cmdcpuhost',
|
||||||
'centreon::esxd::cmdcpuvm',
|
'centreon::esxd::cmdcpuvm',
|
||||||
|
@ -103,10 +103,11 @@ sub new {
|
||||||
$self->{counter} = 0;
|
$self->{counter} = 0;
|
||||||
$self->{global_id} = undef;
|
$self->{global_id} = undef;
|
||||||
$self->{whoaim} = undef; # to know which vsphere to connect
|
$self->{whoaim} = undef; # to know which vsphere to connect
|
||||||
|
$self->{separatorin} = '~';
|
||||||
$self->{filenos} = {};
|
$self->{filenos} = {};
|
||||||
$self->{module_date_parse_loaded} = 0;
|
$self->{module_date_parse_loaded} = 0;
|
||||||
$self->{modules_registry} = {};
|
$self->{modules_registry} = {};
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +215,7 @@ sub handle_CHLD {
|
||||||
my $child_pid;
|
my $child_pid;
|
||||||
|
|
||||||
while (($child_pid = waitpid(-1, &WNOHANG)) > 0) {
|
while (($child_pid = waitpid(-1, &WNOHANG)) > 0) {
|
||||||
$self->{return_child}{$child_pid} = {'status' => 1, 'rtime' => time()};
|
$self->{return_child}{$child_pid} = {status => 1, rtime => time()};
|
||||||
}
|
}
|
||||||
$SIG{CHLD} = \&class_handle_CHLD;
|
$SIG{CHLD} = \&class_handle_CHLD;
|
||||||
}
|
}
|
||||||
|
@ -239,15 +240,15 @@ sub load_module {
|
||||||
sub verify_child {
|
sub verify_child {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $progress = 0;
|
my $progress = 0;
|
||||||
my $handle_writer_pipe = ${$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'writer_one'}};
|
my $handle_writer_pipe = ${$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{writer_one}};
|
||||||
|
|
||||||
# Verify process
|
# Verify process
|
||||||
foreach (keys %{$self->{child_proc}}) {
|
foreach (keys %{$self->{child_proc}}) {
|
||||||
# Check ctime
|
# Check ctime
|
||||||
if (time() - $self->{child_proc}->{$_}->{'ctime'} > $self->{centreonesxd_config}->{timeout}) {
|
if (time() - $self->{child_proc}->{$_}->{ctime} > $self->{centreonesxd_config}->{timeout}) {
|
||||||
my $handle = ${$self->{child_proc}->{$_}->{'reading'}};
|
my $handle = ${$self->{child_proc}->{$_}->{reading}};
|
||||||
print $handle_writer_pipe "$_|-1|Timeout Process.\n";
|
print $handle_writer_pipe "$_|-1|Timeout Process.\n";
|
||||||
kill('INT', $self->{child_proc}->{$_}->{'pid'});
|
kill('INT', $self->{child_proc}->{$_}->{pid});
|
||||||
$self->{read_select}->remove($handle);
|
$self->{read_select}->remove($handle);
|
||||||
close $handle;
|
close $handle;
|
||||||
delete $self->{child_proc}->{$_};
|
delete $self->{child_proc}->{$_};
|
||||||
|
@ -257,7 +258,7 @@ sub verify_child {
|
||||||
}
|
}
|
||||||
# Clean old hash CHILD (security)
|
# Clean old hash CHILD (security)
|
||||||
foreach (keys %{$self->{return_child}}) {
|
foreach (keys %{$self->{return_child}}) {
|
||||||
if (time() - $self->{return_child}->{$_}->{'rtime'} > 600) {
|
if (time() - $self->{return_child}->{$_}->{rtime} > 600) {
|
||||||
$self->{logger}->writeLogInfo("Clean Old return_child list = " . $_);
|
$self->{logger}->writeLogInfo("Clean Old return_child list = " . $_);
|
||||||
delete $self->{return_child}->{$_};
|
delete $self->{return_child}->{$_};
|
||||||
}
|
}
|
||||||
|
@ -270,9 +271,9 @@ sub vsphere_handler {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $timeout_process;
|
my $timeout_process;
|
||||||
|
|
||||||
my $handle_reader_pipe = ${$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'reader_two'}};
|
my $handle_reader_pipe = ${$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{reader_two}};
|
||||||
my $fileno_reader = fileno($handle_reader_pipe);
|
my $fileno_reader = fileno($handle_reader_pipe);
|
||||||
my $handle_writer_pipe = ${$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'writer_one'}};
|
my $handle_writer_pipe = ${$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{writer_one}};
|
||||||
$self->{read_select} = new IO::Select();
|
$self->{read_select} = new IO::Select();
|
||||||
$self->{read_select}->add($handle_reader_pipe);
|
$self->{read_select}->add($handle_reader_pipe);
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -284,7 +285,7 @@ sub vsphere_handler {
|
||||||
if ($self->{stop} && $timeout_process > $self->{centreonesxd_config}->{timeout_kill}) {
|
if ($self->{stop} && $timeout_process > $self->{centreonesxd_config}->{timeout_kill}) {
|
||||||
$self->{logger}->writeLogError("'" . $self->{whoaim} . "' Kill child not gently.");
|
$self->{logger}->writeLogError("'" . $self->{whoaim} . "' Kill child not gently.");
|
||||||
foreach (keys %{$self->{child_proc}}) {
|
foreach (keys %{$self->{child_proc}}) {
|
||||||
kill('INT', $self->{child_proc}->{$_}->{'pid'});
|
kill('INT', $self->{child_proc}->{$_}->{pid});
|
||||||
}
|
}
|
||||||
$progress = 0;
|
$progress = 0;
|
||||||
}
|
}
|
||||||
|
@ -313,9 +314,9 @@ sub vsphere_handler {
|
||||||
$self->{whoaim},
|
$self->{whoaim},
|
||||||
$self->{centreonesxd_config}->{timeout_vsphere},
|
$self->{centreonesxd_config}->{timeout_vsphere},
|
||||||
\$self->{session1},
|
\$self->{session1},
|
||||||
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'url'},
|
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{url},
|
||||||
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'username'},
|
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{username},
|
||||||
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'password'})) {
|
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{password})) {
|
||||||
$self->{logger}->writeLogInfo("'" . $self->{whoaim} . "' Vsphere connection ok");
|
$self->{logger}->writeLogInfo("'" . $self->{whoaim} . "' Vsphere connection ok");
|
||||||
$self->{logger}->writeLogInfo("'" . $self->{whoaim} . "' Create perf counters cache in progress");
|
$self->{logger}->writeLogInfo("'" . $self->{whoaim} . "' Create perf counters cache in progress");
|
||||||
if (!centreon::esxd::common::cache_perf_counters($self)) {
|
if (!centreon::esxd::common::cache_perf_counters($self)) {
|
||||||
|
@ -372,7 +373,7 @@ sub vsphere_handler {
|
||||||
my ($id) = split(/\|/, $data_element);
|
my ($id) = split(/\|/, $data_element);
|
||||||
if ($self->{vsphere_connected}) {
|
if ($self->{vsphere_connected}) {
|
||||||
$self->{logger}->writeLogInfo("vpshere '" . $self->{whoaim} . "' handler asking: $data_element");
|
$self->{logger}->writeLogInfo("vpshere '" . $self->{whoaim} . "' handler asking: $data_element");
|
||||||
$self->{child_proc}->{$id} = {'ctime' => time()};
|
$self->{child_proc}->{$id} = {ctime => time()};
|
||||||
|
|
||||||
my $reader;
|
my $reader;
|
||||||
my $writer;
|
my $writer;
|
||||||
|
@ -380,15 +381,15 @@ sub vsphere_handler {
|
||||||
$writer->autoflush(1);
|
$writer->autoflush(1);
|
||||||
|
|
||||||
$self->{read_select}->add($reader);
|
$self->{read_select}->add($reader);
|
||||||
$self->{child_proc}->{$id}->{'reading'} = \*$reader;
|
$self->{child_proc}->{$id}->{reading} = \*$reader;
|
||||||
$self->{child_proc}->{$id}->{'pid'} = fork;
|
$self->{child_proc}->{$id}->{pid} = fork;
|
||||||
if (!$self->{child_proc}->{$id}->{'pid'}) {
|
if (!$self->{child_proc}->{$id}->{pid}) {
|
||||||
# Child
|
# Child
|
||||||
close $reader;
|
close $reader;
|
||||||
open STDOUT, '>&', $writer;
|
open STDOUT, '>&', $writer;
|
||||||
# Can't print on stdout
|
# Can't print on stdout
|
||||||
$self->{logger}->{log_mode} = 1 if ($self->{logger}->{log_mode} == 0);
|
$self->{logger}->{log_mode} = 1 if ($self->{logger}->{log_mode} == 0);
|
||||||
my ($id, $name, @args) = split /\|/, $data_element;
|
my ($id, $name, @args) = split /\Q$self->{separatorin}\E/, $data_element;
|
||||||
$self->{global_id} = $id;
|
$self->{global_id} = $id;
|
||||||
$self->{modules_registry}->{$name}->initArgs(@args);
|
$self->{modules_registry}->{$name}->initArgs(@args);
|
||||||
$self->{modules_registry}->{$name}->run();
|
$self->{modules_registry}->{$name}->run();
|
||||||
|
@ -408,11 +409,11 @@ sub vsphere_handler {
|
||||||
$output =~ s/^(.*?)\|//;
|
$output =~ s/^(.*?)\|//;
|
||||||
my $lid = $1;
|
my $lid = $1;
|
||||||
if ($output =~ /^-1/) {
|
if ($output =~ /^-1/) {
|
||||||
$self->{last_time_check} = $self->{child_proc}->{$lid}->{'ctime'};
|
$self->{last_time_check} = $self->{child_proc}->{$lid}->{ctime};
|
||||||
}
|
}
|
||||||
chomp $output;
|
chomp $output;
|
||||||
print $handle_writer_pipe "$lid|$output\n";
|
print $handle_writer_pipe "$lid|$output\n";
|
||||||
delete $self->{return_child}->{$self->{child_proc}->{$lid}->{'pid'}};
|
delete $self->{return_child}->{$self->{child_proc}->{$lid}->{pid}};
|
||||||
delete $self->{child_proc}->{$lid};
|
delete $self->{child_proc}->{$lid};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -450,27 +451,27 @@ sub run {
|
||||||
$writer_pipe_one->autoflush(1);
|
$writer_pipe_one->autoflush(1);
|
||||||
$writer_pipe_two->autoflush(1);
|
$writer_pipe_two->autoflush(1);
|
||||||
|
|
||||||
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'reader_one'} = \*$reader_pipe_one;
|
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{reader_one} = \*$reader_pipe_one;
|
||||||
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'writer_one'} = \*$writer_pipe_one;
|
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{writer_one} = \*$writer_pipe_one;
|
||||||
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'reader_two'} = \*$reader_pipe_two;
|
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{reader_two} = \*$reader_pipe_two;
|
||||||
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'writer_two'} = \*$writer_pipe_two;
|
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{writer_two} = \*$writer_pipe_two;
|
||||||
$self->{child_vpshere_pid} = fork();
|
$self->{child_vpshere_pid} = fork();
|
||||||
if (!$self->{child_vpshere_pid}) {
|
if (!$self->{child_vpshere_pid}) {
|
||||||
close $self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'reader_one'};
|
close $self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{reader_one};
|
||||||
close $self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'writer_two'};
|
close $self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{writer_two};
|
||||||
$self->vsphere_handler();
|
$self->vsphere_handler();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'running'} = 1;
|
$self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{running} = 1;
|
||||||
close $self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'writer_one'};
|
close $self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{writer_one};
|
||||||
close $self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{'reader_two'};
|
close $self->{centreonesxd_config}->{vsphere_server}->{$self->{whoaim}}->{reader_two};
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{read_select} = new IO::Select();
|
$self->{read_select} = new IO::Select();
|
||||||
$self->{read_select}->add($server);
|
$self->{read_select}->add($server);
|
||||||
foreach (keys %{$self->{centreonesxd_config}->{vsphere_server}}) {
|
foreach (keys %{$self->{centreonesxd_config}->{vsphere_server}}) {
|
||||||
$self->{filenos}->{fileno(${$self->{centreonesxd_config}->{vsphere_server}->{$_}->{'reader_one'}})} = 1;
|
$self->{filenos}->{fileno(${$self->{centreonesxd_config}->{vsphere_server}->{$_}->{reader_one}})} = 1;
|
||||||
$self->{read_select}->add(${$self->{centreonesxd_config}->{vsphere_server}->{$_}->{'reader_one'}});
|
$self->{read_select}->add(${$self->{centreonesxd_config}->{vsphere_server}->{$_}->{reader_one}});
|
||||||
}
|
}
|
||||||
my $socket_fileno = fileno($server);
|
my $socket_fileno = fileno($server);
|
||||||
$self->{logger}->writeLogInfo("[Server accepting clients]");
|
$self->{logger}->writeLogInfo("[Server accepting clients]");
|
||||||
|
@ -479,7 +480,7 @@ sub run {
|
||||||
if ($self->{stop} == 1) {
|
if ($self->{stop} == 1) {
|
||||||
foreach (keys %{$self->{centreonesxd_config}->{vsphere_server}}) {
|
foreach (keys %{$self->{centreonesxd_config}->{vsphere_server}}) {
|
||||||
$self->{logger}->writeLogInfo("Send STOP command to '$_' child.");
|
$self->{logger}->writeLogInfo("Send STOP command to '$_' child.");
|
||||||
my $writer_handle = $self->{centreonesxd_config}->{vsphere_server}->{$_}->{'writer_two'};
|
my $writer_handle = $self->{centreonesxd_config}->{vsphere_server}->{$_}->{writer_two};
|
||||||
print $writer_handle "STOP\n";
|
print $writer_handle "STOP\n";
|
||||||
}
|
}
|
||||||
$self->{stop} = 2;
|
$self->{stop} = 2;
|
||||||
|
@ -503,10 +504,10 @@ sub run {
|
||||||
# We have to wait all childs
|
# We have to wait all childs
|
||||||
my ($name, $which_one) = split(/\|/, $data_element);
|
my ($name, $which_one) = split(/\|/, $data_element);
|
||||||
$self->{logger}->writeLogInfo("Thread vsphere '$which_one' has stopped");
|
$self->{logger}->writeLogInfo("Thread vsphere '$which_one' has stopped");
|
||||||
$self->{centreonesxd_config}->{vsphere_server}->{$which_one}->{'running'} = 0;
|
$self->{centreonesxd_config}->{vsphere_server}->{$which_one}->{running} = 0;
|
||||||
my $to_stop_or_not = 1;
|
my $to_stop_or_not = 1;
|
||||||
foreach (keys %{$self->{centreonesxd_config}->{vsphere_server}}) {
|
foreach (keys %{$self->{centreonesxd_config}->{vsphere_server}}) {
|
||||||
$to_stop_or_not = 0 if ($self->{centreonesxd_config}->{vsphere_server}->{$_}->{'running'} == 1);
|
$to_stop_or_not = 0 if ($self->{centreonesxd_config}->{vsphere_server}->{$_}->{running} == 1);
|
||||||
}
|
}
|
||||||
if ($to_stop_or_not == 1) {
|
if ($to_stop_or_not == 1) {
|
||||||
# We quit
|
# We quit
|
||||||
|
@ -517,23 +518,23 @@ sub run {
|
||||||
}
|
}
|
||||||
my @results = split(/\|/, $data_element);
|
my @results = split(/\|/, $data_element);
|
||||||
my ($id, $counter) = split(/\./, $results[0]);
|
my ($id, $counter) = split(/\./, $results[0]);
|
||||||
if (!defined($self->{sockets}->{$id}) || $counter != $self->{sockets}->{$id}->{'counter'}) {
|
if (!defined($self->{sockets}->{$id}) || $counter != $self->{sockets}->{$id}->{counter}) {
|
||||||
$self->{logger}->writeLogInfo("Too much time to get response.");
|
$self->{logger}->writeLogInfo("Too much time to get response.");
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{logger}->writeLogInfo("response = $data_element");
|
$self->{logger}->writeLogInfo("response = $data_element");
|
||||||
$data_element =~ s/^.*?\|//;
|
$data_element =~ s/^.*?\|//;
|
||||||
${$self->{sockets}->{$id}->{'obj'}}->send($data_element . "\n");
|
${$self->{sockets}->{$id}->{obj}}->send($data_element . "\n");
|
||||||
$self->{read_select}->remove(${$self->{sockets}->{$id}->{"obj"}});
|
$self->{read_select}->remove(${$self->{sockets}->{$id}->{obj}});
|
||||||
close ${$self->{sockets}->{$id}->{"obj"}};
|
close ${$self->{sockets}->{$id}->{obj}};
|
||||||
delete $self->{sockets}->{$id};
|
delete $self->{sockets}->{$id};
|
||||||
} else {
|
} else {
|
||||||
# Socket
|
# Socket
|
||||||
my $line = <$rh>;
|
my $line = <$rh>;
|
||||||
if (defined($line) && $line ne "") {
|
if (defined($line) && $line ne "") {
|
||||||
chomp $line;
|
chomp $line;
|
||||||
my ($name, $vsphere_name, @args) = split /\|/, $line;
|
my ($name, $vsphere_name, @args) = split /\Q$self->{separatorin}\E/, $line;
|
||||||
|
|
||||||
if ($name eq 'stats') {
|
if ($name eq 'stats') {
|
||||||
centreon::esxd::common::stats_info($self, $rh, $current_fileno, \@args);
|
centreon::esxd::common::stats_info($self, $rh, $current_fileno, \@args);
|
||||||
|
@ -554,8 +555,8 @@ sub run {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $tmp_handle = ${$self->{centreonesxd_config}->{vsphere_server}->{$vsphere_name}->{'writer_two'}};
|
my $tmp_handle = ${$self->{centreonesxd_config}->{vsphere_server}->{$vsphere_name}->{writer_two}};
|
||||||
print $tmp_handle $current_fileno . "." . $self->{sockets}->{$current_fileno}->{'counter'} . "|$name|" . join('|', @args) . "\n";
|
print $tmp_handle $current_fileno . "." . $self->{sockets}->{$current_fileno}->{counter} . $self->{separatorin} . $name . $self->{separatorin} . join($self->{separatorin}, @args) . "\n";
|
||||||
} else {
|
} else {
|
||||||
centreon::esxd::common::response_client1($self, $rh, $current_fileno, "3|Need arguments\n");
|
centreon::esxd::common::response_client1($self, $rh, $current_fileno, "3|Need arguments\n");
|
||||||
}
|
}
|
||||||
|
@ -564,11 +565,11 @@ sub run {
|
||||||
|
|
||||||
# Verify socket
|
# Verify socket
|
||||||
foreach (keys %{$self->{sockets}}) {
|
foreach (keys %{$self->{sockets}}) {
|
||||||
if (time() - $self->{sockets}->{$_}->{'ctime'} > $self->{centreonesxd_config}->{timeout}) {
|
if (time() - $self->{sockets}->{$_}->{ctime} > $self->{centreonesxd_config}->{timeout}) {
|
||||||
$self->{logger}->writeLogInfo("Timeout returns.");
|
$self->{logger}->writeLogInfo("Timeout returns.");
|
||||||
${$self->{sockets}->{$_}->{'obj'}}->send("3|TIMEOUT\n");
|
${$self->{sockets}->{$_}->{obj}}->send("3|TIMEOUT\n");
|
||||||
$self->{read_select}->remove(${$self->{sockets}->{$_}->{"obj"}});
|
$self->{read_select}->remove(${$self->{sockets}->{$_}->{obj}});
|
||||||
close ${$self->{sockets}->{$_}->{"obj"}};
|
close ${$self->{sockets}->{$_}->{obj}};
|
||||||
delete $self->{sockets}->{$_};
|
delete $self->{sockets}->{$_};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue