File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ BEGIN
136136 LEAVE read_loop;
137137 END IF;
138138
139- IF row_previous_hard_state = 99 THEN
139+ IF last_hard_state = 99 OR row_previous_hard_state = 99 THEN
140140 SET total_time = total_time - (row_event_time - last_event_time);
141141 ELSEIF ((in_service_id IS NULL AND last_hard_state > 0 ) OR (in_service_id IS NOT NULL AND last_hard_state > 1 ))
142142 AND last_hard_state != 99
@@ -156,7 +156,11 @@ BEGIN
156156 END LOOP;
157157 CLOSE cur;
158158
159- SET result = 100 * (total_time - problem_time) / total_time;
159+ -- prevents division by zero crashes
160+ IF total_time > 0 THEN
161+ SET result = 100 * (total_time - problem_time) / total_time;
162+ END IF; -- else no data available to be reported
163+
160164 RETURN result;
161165END//
162166DELIMITER ;
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ DECLARE
3939 problem_time biguint := 0 ;
4040 total_time biguint;
4141 row record;
42+ result decimal (7 , 4 );
4243BEGIN
4344 IF in_end_time <= in_start_time THEN
4445 RAISE ' end time must be greater than start time' ;
@@ -138,7 +139,7 @@ BEGIN
138139 )
139140 ORDER BY event_time, event_prio
140141 LOOP
141- IF row .previous_hard_state = 99 THEN
142+ IF last_hard_state = 99 OR row .previous_hard_state = 99 THEN
142143 total_time := total_time - (row .event_time - last_event_time);
143144 ELSEIF ((in_service_id IS NULL AND last_hard_state > 0 ) OR (in_service_id IS NOT NULL AND last_hard_state > 1 ))
144145 AND last_hard_state != 99
@@ -157,7 +158,12 @@ BEGIN
157158 END IF;
158159 END LOOP;
159160
160- RETURN 100 * (total_time - problem_time) / total_time;
161+ -- prevents division by zero crashes
162+ IF total_time > 0 THEN
163+ result := 100 * (total_time - problem_time) / total_time;
164+ END IF; -- else no data available to be reported
165+
166+ RETURN result;
161167END;
162168$$;
163169
You can’t perform that action at this time.
0 commit comments