Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gorgone-mbi): wrong order execution for events calculation #1692

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions gorgone/gorgone/modules/centreon/mbi/etl/class.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ sub new {
$connector->{config}->{cbis_profile} : '/etc/centreon-bi/cbis-profile.xml';
$connector->{reports_profile} = (defined($connector->{config}->{reports_profile}) && $connector->{config}->{reports_profile} ne '') ?
$connector->{config}->{reports_profile} : '/etc/centreon-bi/reports-profile.xml';
$connector->{max_exec} = (defined($connector->{config}->{max_exec}) && $connector->{config}->{max_exec} !~ /([0-9]+)/) ?
$1 : 8;
$connector->{current_exec} = 0;

$connector->{run} = { status => NONE };

Expand All @@ -85,7 +88,7 @@ sub handle_HUP {

sub handle_TERM {
my $self = shift;
$self->{logger}->writeLogDebug("[nodes] $$ Receiving order to stop...");
$self->{logger}->writeLogDebug("[" . $self->{module_id} . "] $$ Receiving order to stop...");
$self->{stop} = 1;
}

Expand Down Expand Up @@ -200,6 +203,8 @@ sub execute_action {
$content->{options} = $self->{run}->{options};
}

$self->{current_exec}++;

$self->send_internal_action({
action => $options{action},
token => $self->{module_id} . '-' . $self->{run}->{token} . '-' . $options{substep},
Expand All @@ -214,6 +219,7 @@ sub watch_etl_event {
my ($self, %options) = @_;

if (defined($options{indexes})) {
$self->{current_exec}--;
$self->{run}->{schedule}->{event}->{substeps_executed}++;
my ($idx, $idx2) = split(/-/, $options{indexes});
$self->{run}->{schedule}->{event}->{stages}->[$idx]->[$idx2]->{status} = FINISHED;
Expand All @@ -230,9 +236,9 @@ sub watch_etl_event {

my $stage = $self->{run}->{schedule}->{event}->{current_stage};
my $stage_finished = 0;
while ($stage <= 2) {
while ($stage <= 3) {
while (my ($idx, $val) = each(@{$self->{run}->{schedule}->{event}->{stages}->[$stage]})) {
if (!defined($val->{status})) {
if (!defined($val->{status}) && $self->{current_exec} < $self->{max_exec}) {
$self->{logger}->writeLogDebug("[mbi-etl] execute substep event-$stage-$idx");
$self->{run}->{schedule}->{event}->{substeps_execute}++;
$self->execute_action(
Expand All @@ -243,14 +249,15 @@ sub watch_etl_event {
params => $self->{run}->{schedule}->{event}->{stages}->[$stage]->[$idx]
);
$self->{run}->{schedule}->{event}->{stages}->[$stage]->[$idx]->{status} = RUNNING;
} elsif ($val->{status} == FINISHED) {
} elsif (defined($val->{status}) && $val->{status} == FINISHED) {
$stage_finished++;
}
}

if ($stage_finished >= scalar(@{$self->{run}->{schedule}->{event}->{stages}->[$stage]})) {
$self->{run}->{schedule}->{event}->{current_stage}++;
$stage = $self->{run}->{schedule}->{event}->{current_stage};
$stage_finished = 0;
} else {
last;
}
Expand All @@ -261,6 +268,7 @@ sub watch_etl_perfdata {
my ($self, %options) = @_;

if (defined($options{indexes})) {
$self->{current_exec}--;
$self->{run}->{schedule}->{perfdata}->{substeps_executed}++;
my ($idx, $idx2) = split(/-/, $options{indexes});
$self->{run}->{schedule}->{perfdata}->{stages}->[$idx]->[$idx2]->{status} = FINISHED;
Expand All @@ -279,7 +287,7 @@ sub watch_etl_perfdata {
my $stage_finished = 0;
while ($stage <= 2) {
while (my ($idx, $val) = each(@{$self->{run}->{schedule}->{perfdata}->{stages}->[$stage]})) {
if (!defined($val->{status})) {
if (!defined($val->{status}) && $self->{current_exec} < $self->{max_exec}) {
$self->{logger}->writeLogDebug("[mbi-etl] execute substep perfdata-$stage-$idx");
$self->{run}->{schedule}->{perfdata}->{substeps_execute}++;
$self->execute_action(
Expand All @@ -290,7 +298,7 @@ sub watch_etl_perfdata {
params => $self->{run}->{schedule}->{perfdata}->{stages}->[$stage]->[$idx]
);
$self->{run}->{schedule}->{perfdata}->{stages}->[$stage]->[$idx]->{status} = RUNNING;
} elsif ($val->{status} == FINISHED) {
} elsif (defined($val->{status}) && $val->{status} == FINISHED) {
$stage_finished++;
}
}
Expand All @@ -309,6 +317,7 @@ sub watch_etl_dimensions {

if (defined($options{indexes})) {
$self->{run}->{schedule}->{dimensions}->{substeps_executed}++;
$self->{current_exec}--;
}

return if (!$self->check_stopped_ko());
Expand Down Expand Up @@ -337,6 +346,7 @@ sub watch_etl_import {
if (defined($options{indexes})) {
$self->{run}->{schedule}->{import}->{substeps_executed}++;
my ($idx, $idx2) = split(/-/, $options{indexes});
$self->{current_exec}--;
if (defined($idx) && defined($idx2)) {
$self->{run}->{schedule}->{import}->{actions}->[$idx]->{actions}->[$idx2]->{status} = FINISHED;
} else {
Expand All @@ -355,7 +365,7 @@ sub watch_etl_import {
}

while (my ($idx, $val) = each(@{$self->{run}->{schedule}->{import}->{actions}})) {
if (!defined($val->{status})) {
if (!defined($val->{status}) && $self->{current_exec} < $self->{max_exec}) {
$self->{logger}->writeLogDebug("[mbi-etl] execute substep import-$idx");
$self->{run}->{schedule}->{import}->{substeps_execute}++;
$self->{run}->{schedule}->{import}->{actions}->[$idx]->{status} = RUNNING;
Expand All @@ -370,9 +380,9 @@ sub watch_etl_import {
message => $val->{message}
}
);
} elsif ($val->{status} == FINISHED) {
} elsif (defined($val->{status}) && $val->{status} == FINISHED) {
while (my ($idx2, $val2) = each(@{$val->{actions}})) {
next if (defined($val2->{status}));
next if (defined($val2->{status}) || $self->{current_exec} >= $self->{max_exec});

$self->{logger}->writeLogDebug("[mbi-etl] execute substep import-$idx-$idx2");
$self->{run}->{schedule}->{import}->{substeps_execute}++;
Expand Down Expand Up @@ -439,7 +449,7 @@ sub run_etl_event {
$self->{run}->{schedule}->{event}->{substeps_execute} = 0;
$self->{run}->{schedule}->{event}->{substeps_executed} = 0;
$self->{run}->{schedule}->{event}->{substeps_total} =
scalar(@{$self->{run}->{schedule}->{event}->{stages}->[0]}) + scalar(@{$self->{run}->{schedule}->{event}->{stages}->[1]}) + scalar(@{$self->{run}->{schedule}->{event}->{stages}->[2]});
scalar(@{$self->{run}->{schedule}->{event}->{stages}->[0]}) + scalar(@{$self->{run}->{schedule}->{event}->{stages}->[1]}) + scalar(@{$self->{run}->{schedule}->{event}->{stages}->[2]}) + scalar(@{$self->{run}->{schedule}->{event}->{stages}->[3]});

$self->{logger}->writeLogDebug("[mbi-etl] event substeps " . $self->{run}->{schedule}->{event}->{substeps_total});

Expand Down Expand Up @@ -666,13 +676,15 @@ sub action_centreonmbietlrun {

$self->check_basic_options(%{$options{data}->{content}});

$self->{current_exec} = 0;

$self->{run}->{schedule} = {
steps_total => 0,
steps_executed => 0,
planned => NOTDONE,
import => { status => UNPLANNED, actions => [] },
dimensions => { status => UNPLANNED },
event => { status => UNPLANNED, stages => [ [], [], [] ] },
event => { status => UNPLANNED, stages => [ [], [], [], [] ] },
perfdata => { status => UNPLANNED, stages => [ [], [], [] ] }
};
$self->{run}->{status} = RUNNING;
Expand Down
12 changes: 6 additions & 6 deletions gorgone/gorgone/modules/centreon/mbi/etl/event/main.pm
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ sub processByDay {

while (my ($liveserviceName, $liveserviceId) = each (%$liveServices)) {
if (!defined($etl->{run}->{options}->{service_only}) || $etl->{run}->{options}->{service_only} == 0) {
push @{$etl->{run}->{schedule}->{event}->{stages}->[1]}, {
push @{$etl->{run}->{schedule}->{event}->{stages}->[2]}, {
type => 'availability_day_hosts',
liveserviceName => $liveserviceName,
liveserviceId => $liveserviceId,
Expand All @@ -158,7 +158,7 @@ sub processByDay {
}

if (!defined($etl->{run}->{options}->{host_only}) || $etl->{run}->{options}->{host_only} == 0) {
push @{$etl->{run}->{schedule}->{event}->{stages}->[1]}, {
push @{$etl->{run}->{schedule}->{event}->{stages}->[2]}, {
type => 'availability_day_services',
liveserviceName => $liveserviceName,
liveserviceId => $liveserviceId,
Expand All @@ -174,14 +174,14 @@ sub processHostgroupAvailability {

$time->insertTimeEntriesForPeriod($start, $end);
if (!defined($etl->{run}->{options}->{service_only}) || $etl->{run}->{options}->{service_only} == 0) {
push @{$etl->{run}->{schedule}->{event}->{stages}->[2]}, {
push @{$etl->{run}->{schedule}->{event}->{stages}->[3]}, {
type => 'availability_month_services',
start => $start,
end => $end
};
}
if (!defined($etl->{run}->{options}->{host_only}) || $etl->{run}->{options}->{host_only} == 0) {
push @{$etl->{run}->{schedule}->{event}->{stages}->[2]}, {
push @{$etl->{run}->{schedule}->{event}->{stages}->[3]}, {
type => 'availability_month_hosts',
start => $start,
end => $end
Expand Down Expand Up @@ -228,7 +228,7 @@ sub dailyProcessing {
processHostgroupAvailability($etl, $utils->subtractDateMonths($end, 1), $utils->subtractDateDays($end, 1));
}

push @{$etl->{run}->{schedule}->{event}->{stages}->[0]},
push @{$etl->{run}->{schedule}->{event}->{stages}->[1]},
{ type => 'events', services => 1, start => $start, end => $end }, { type => 'events', hosts => 1, start => $start, end => $end };
}

Expand Down Expand Up @@ -270,7 +270,7 @@ sub rebuildProcessing {
}

if (!defined($etl->{run}->{options}->{availability_only}) || $etl->{run}->{options}->{availability_only} == 0) {
push @{$etl->{run}->{schedule}->{event}->{stages}->[0]},
push @{$etl->{run}->{schedule}->{event}->{stages}->[1]},
{ type => 'events', services => 1, start => $start, end => $end }, { type => 'events', hosts => 1, start => $start, end => $end };
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,4 @@ sub prepare {
}
}

1;
1;
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ sub processEventsHosts {
$etlwk->{messages}->writeLog("INFO", "[HOST] Loading calculated events in reporting table");
$etlwk->{dbbi_centstorage_con}->query({ query => $request });

if ($options{options}->{rebuild} == 1 && $options{options}->{rebuild} == 0) {
if ($options{options}->{rebuild} == 1) {
$etlwk->{messages}->writeLog("DEBUG", "[HOST] Creating index");
$etlwk->{dbbi_centstorage_con}->query({ query => 'ALTER TABLE mod_bi_hoststateevents ADD INDEX `modbihost_id` (`modbihost_id`,`modbiliveservice_id`,`state`,`start_time`,`end_time`)' });
$etlwk->{dbbi_centstorage_con}->query({ query => 'ALTER TABLE mod_bi_hoststateevents ADD INDEX `state` (`state`,`modbiliveservice_id`,`start_time`,`end_time`)' });
Expand Down Expand Up @@ -153,7 +153,7 @@ sub processEventsServices {
$etlwk->{messages}->writeLog("INFO", "[SERVICE] Loading calculated events in reporting table");
$etlwk->{dbbi_centstorage_con}->query({ query => $request });

if ($options{options}->{rebuild} == 1 && $options{options}->{rebuild} == 0) {
if ($options{options}->{rebuild} == 1) {
$etlwk->{messages}->writeLog("DEBUG", "[SERVICE] Creating index");
$etlwk->{dbbi_centstorage_con}->query({ query => 'ALTER TABLE mod_bi_servicestateevents ADD INDEX `modbiservice_id` (`modbiservice_id`,`modbiliveservice_id`,`state`,`start_time`,`end_time`)' });
$etlwk->{dbbi_centstorage_con}->query({ query => 'ALTER TABLE mod_bi_servicestateevents ADD INDEX `state` (`state`,`modbiliveservice_id`,`start_time`,`end_time`)' });
Expand Down
22 changes: 14 additions & 8 deletions gorgone/gorgone/modules/centreon/mbi/libs/centreon/Service.pm
Original file line number Diff line number Diff line change
Expand Up @@ -147,27 +147,33 @@ sub getServicesWithHostAndCategory {
}

sub getServicesTemplatesCategories {
my $self = shift;
my $db = $self->{"centreon"};
my %results = ();
my $self = shift;
my $db = $self->{"centreon"};
my %results = ();

my $query = "SELECT service_id, service_description, service_template_model_stm_id FROM service WHERE service_register = '0'";
my $sth = $db->query({ query => $query });
my $query = "SELECT service_id, service_description, service_template_model_stm_id FROM service WHERE service_register = '0'";
my $sth = $db->query({ query => $query });
while(my $row = $sth->fetchrow_hashref()) {
my $loop_services = { $row->{service_id} => 1 };
my $currentTemplate = $row->{"service_id"};
my $categories = $self->getServiceCategories($row->{"service_id"});
my $parentId = $row->{"service_template_model_stm_id"};
if (defined($parentId)) {
my $hasParent = 1;
# getting all parent templates category relations
while ($hasParent) {
if (defined($loop_services->{$parentId})) {
last;
}
$loop_services->{$parentId} = 1;

my $parentQuery = "SELECT service_id, service_template_model_stm_id ";
$parentQuery .= "FROM service ";
$parentQuery .= "WHERE service_register = '0' and service_id=".$parentId;
my $sthparentQuery = $db->query({ query => $parentQuery });
if(my $parentQueryRow = $sthparentQuery->fetchrow_hashref()) {
if (my $parentQueryRow = $sthparentQuery->fetchrow_hashref()) {
my $newCategories = $self->getServiceCategories($parentQueryRow->{"service_id"});
while(my ($sc_id, $sc_name) = each(%$newCategories)) {
while (my ($sc_id, $sc_name) = each(%$newCategories)) {
if (!defined($categories->{$sc_id})) {
$categories->{$sc_id} = $sc_name;
}
Expand All @@ -178,7 +184,7 @@ sub getServicesTemplatesCategories {
}
$parentId = $parentQueryRow->{'service_template_model_stm_id'};
$sthparentQuery->finish();
}else {
} else {
$hasParent = 0;
}
}
Expand Down