Skip to content

Commit

Permalink
schema: Fix sla report inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Jan 26, 2023
1 parent 4ed4db3 commit b997831
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 6 additions & 3 deletions schema/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,9 @@ BEGIN
LEAVE read_loop;
END IF;

IF row_previous_hard_state = 99 THEN
IF last_hard_state = 99 OR row_previous_hard_state = 99 THEN
SET total_time = total_time - (row_event_time - last_event_time);
ELSEIF ((in_service_id IS NULL AND last_hard_state > 0) OR (in_service_id IS NOT NULL AND last_hard_state > 1))
AND last_hard_state != 99
AND active_downtimes = 0
THEN
SET problem_time = problem_time + row_event_time - last_event_time;
Expand All @@ -156,7 +155,11 @@ BEGIN
END LOOP;
CLOSE cur;

SET result = 100 * (total_time - problem_time) / total_time;
-- prevents division by zero crashes
IF total_time > 0 THEN
SET result = 100 * (total_time - problem_time) / total_time;
END IF; -- else no data available to be reported

RETURN result;
END//
DELIMITER ;
Expand Down
11 changes: 8 additions & 3 deletions schema/pgsql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ DECLARE
problem_time biguint := 0;
total_time biguint;
row record;
result decimal(7, 4);
BEGIN
IF in_end_time <= in_start_time THEN
RAISE 'end time must be greater than start time';
Expand Down Expand Up @@ -138,10 +139,9 @@ BEGIN
)
ORDER BY event_time, event_prio
LOOP
IF row.previous_hard_state = 99 THEN
IF last_hard_state = 99 OR row.previous_hard_state = 99 THEN
total_time := total_time - (row.event_time - last_event_time);
ELSEIF ((in_service_id IS NULL AND last_hard_state > 0) OR (in_service_id IS NOT NULL AND last_hard_state > 1))
AND last_hard_state != 99
AND active_downtimes = 0
THEN
problem_time := problem_time + row.event_time - last_event_time;
Expand All @@ -157,7 +157,12 @@ BEGIN
END IF;
END LOOP;

RETURN 100 * (total_time - problem_time) / total_time;
-- prevents division by zero crashes
IF total_time > 0 THEN
result := 100 * (total_time - problem_time) / total_time;
END IF; -- else no data available to be reported

RETURN result;
END;
$$;

Expand Down

0 comments on commit b997831

Please sign in to comment.