(plugin) apps::centreon::sql::mode::multiservices - allow host arrays in config file (#4251)
This commit is contained in:
parent
c3949a205a
commit
bdb0c55c06
|
@ -367,6 +367,36 @@ my %map_service_state = (
|
||||||
3 => 'unknown',
|
3 => 'unknown',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
sub manage_query {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
my $query = "SELECT hosts.name, services.description, hosts.state as hstate, services.state as sstate, services.output as soutput
|
||||||
|
FROM centreon_storage.hosts, centreon_storage.services WHERE hosts.host_id=services.host_id
|
||||||
|
AND hosts.name NOT LIKE 'Module%' AND hosts.enabled=1 AND services.enabled=1
|
||||||
|
AND hosts.name = '" . $options{host} . "'
|
||||||
|
AND services.description = '" . $options{service} . "'";
|
||||||
|
|
||||||
|
$self->{sql}->query(query => $query);
|
||||||
|
while ((my $row = $self->{sql}->fetchrow_hashref())) {
|
||||||
|
if (!exists($self->{instance_mode}->{inventory}->{hosts}->{$options{group}}->{$row->{name}})) {
|
||||||
|
push @{$self->{instance_mode}->{inventory}->{groups}->{$options{group}}->{'list_'.$map_host_state{$row->{hstate}}}} ,$row->{name};
|
||||||
|
if (!defined($self->{hosts}->{$options{host}})) {
|
||||||
|
$self->{hosts}->{$options{host}} = 1;
|
||||||
|
$self->{totalhost}->{$map_host_state{$row->{hstate}}}++;
|
||||||
|
$self->{logicalgroups}->{$options{group}}->{$map_host_state{$row->{hstate}}}++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
push @{$self->{instance_mode}->{inventory}->{groups}->{$options{group}}->{'list_'.$map_service_state{$row->{sstate}}}}, $row->{name} . ${config_data}->{formatting}->{host_service_separator} . $row->{description};
|
||||||
|
|
||||||
|
$self->{instance_mode}->{inventory}->{hosts}->{$options{group}}->{$row->{name}} = $row->{hstate};
|
||||||
|
$self->{instance_mode}->{inventory}->{services}{ $row->{name} . ${config_data}->{formatting}->{host_service_separator} . $row->{description} } = { state => $row->{sstate}, output => $row->{soutput} } ;
|
||||||
|
$self->{instance_mode}->{inventory}->{groups}->{$options{group}}->{$row->{name} . ${config_data}->{formatting}->{host_service_separator} . $row->{description}} = { state => $row->{sstate}, output => $row->{soutput} };
|
||||||
|
$self->{totalservice}->{$map_service_state{$row->{sstate}}}++;
|
||||||
|
$self->{logicalgroups}->{$options{group}}->{$map_service_state{$row->{sstate}}}++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
# $options{sql} = sqlmode object
|
# $options{sql} = sqlmode object
|
||||||
|
@ -374,6 +404,7 @@ sub manage_selection {
|
||||||
$self->{sql}->connect();
|
$self->{sql}->connect();
|
||||||
|
|
||||||
$self->{groups} = {};
|
$self->{groups} = {};
|
||||||
|
$self->{hosts} = {};
|
||||||
|
|
||||||
if ($config_data->{counters}->{totalhosts} eq 'true') {
|
if ($config_data->{counters}->{totalhosts} eq 'true') {
|
||||||
push @{$self->{maps_counters_type}}, {
|
push @{$self->{maps_counters_type}}, {
|
||||||
|
@ -435,26 +466,22 @@ sub manage_selection {
|
||||||
up => 0, down => 0, unreachable => 0,
|
up => 0, down => 0, unreachable => 0,
|
||||||
ok => 0, warning => 0, critical => 0, unknown => 0
|
ok => 0, warning => 0, critical => 0, unknown => 0
|
||||||
};
|
};
|
||||||
foreach my $tuple (keys %{$config_data->{selection}->{$group}}) {
|
foreach my $host (keys %{$config_data->{selection}->{$group}}) {
|
||||||
my $query = "SELECT hosts.name, services.description, hosts.state as hstate, services.state as sstate, services.output as soutput
|
if (ref($config_data->{selection}->{$group}->{$host}) eq "ARRAY") {
|
||||||
FROM centreon_storage.hosts, centreon_storage.services WHERE hosts.host_id=services.host_id
|
foreach my $service (@{$config_data->{selection}->{$group}->{$host}}) {
|
||||||
AND hosts.name NOT LIKE 'Module%' AND hosts.enabled=1 AND services.enabled=1
|
$self->manage_query(
|
||||||
AND hosts.name = '" . $tuple . "'
|
group => $group,
|
||||||
AND services.description = '" . $config_data->{selection}->{$group}->{$tuple} . "'";
|
host => $host,
|
||||||
$self->{sql}->query(query => $query);
|
service => $service
|
||||||
while ((my $row = $self->{sql}->fetchrow_hashref())) {
|
);
|
||||||
if (!exists($self->{instance_mode}->{inventory}->{hosts}->{$group}->{$row->{name}})) {
|
|
||||||
push @{$self->{instance_mode}->{inventory}->{groups}->{$group}->{'list_'.$map_host_state{$row->{hstate}}}} ,$row->{name};
|
|
||||||
$self->{totalhost}->{$map_host_state{$row->{hstate}}}++;
|
|
||||||
$self->{logicalgroups}->{$group}->{$map_host_state{$row->{hstate}}}++;
|
|
||||||
}
|
}
|
||||||
push @{$self->{instance_mode}->{inventory}->{groups}->{$group}->{'list_'.$map_service_state{$row->{sstate}}}}, $row->{name} . ${config_data}->{formatting}->{host_service_separator} . $row->{description};
|
|
||||||
|
} else {
|
||||||
$self->{instance_mode}->{inventory}->{hosts}->{$group}->{$row->{name}} = $row->{hstate};
|
$self->manage_query(
|
||||||
$self->{instance_mode}->{inventory}->{services}{ $row->{name} . ${config_data}->{formatting}->{host_service_separator} . $row->{description} } = { state => $row->{sstate}, output => $row->{soutput} } ;
|
group => $group,
|
||||||
$self->{instance_mode}->{inventory}->{groups}->{$group}->{$row->{name} . ${config_data}->{formatting}->{host_service_separator} . $row->{description}} = { state => $row->{sstate}, output => $row->{soutput} };
|
host => $host,
|
||||||
$self->{totalservice}->{$map_service_state{$row->{sstate}}}++;
|
service => $config_data->{selection}->{$group}->{$host}
|
||||||
$self->{logicalgroups}->{$group}->{$map_service_state{$row->{sstate}}}++;
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue