From e06cc90c3e2f9378988fc7f760ee47ce8f3e1e67 Mon Sep 17 00:00:00 2001 From: Laziz Date: Wed, 7 Jun 2017 11:36:01 +0200 Subject: [PATCH 1/2] [-] Fixing bug with Hosts evaluation and consider downtimes ITC-1115 --- app/Controller/InstantreportsController.php | 4 +--- app/Model/Instantreport.php | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/Controller/InstantreportsController.php b/app/Controller/InstantreportsController.php index a6e9d15465..08a1fdab23 100644 --- a/app/Controller/InstantreportsController.php +++ b/app/Controller/InstantreportsController.php @@ -513,9 +513,7 @@ private function generateReport($instantReport, $baseStartDate, $baseEndDate, $r 'object_id', 'state_time', 'state', 'state_type', 'last_state', 'last_hard_state', ], 'conditions' => [ - 'Statehistory.state_time - BETWEEN "'.$startDateSqlFormat.'" - AND "'.$endDateSqlFormat.'"', + "Statehistory.state_time <= '$endDateSqlFormat'", ], 'order' => [ 'Statehistory.state_time', diff --git a/app/Model/Instantreport.php b/app/Model/Instantreport.php index 369050e85f..c23734ee28 100644 --- a/app/Model/Instantreport.php +++ b/app/Model/Instantreport.php @@ -267,7 +267,7 @@ public function generateInstantreportData($totalTime, $timeSlices, $stateHistory } //if outage in downtime add time for state "ok" - if ($currentState == $outageState || $isDowntime) { + if ($currentState == $outageState && $isDowntime) { $evaluationData[$outageState] += $timeSlice['end'] - $time; } else { $evaluationData[$currentState] += $timeSlice['end'] - $time; From 724574b577a53b4695a81bde3ea9a0affec92fb9 Mon Sep 17 00:00:00 2001 From: Laziz Date: Thu, 8 Jun 2017 11:00:59 +0200 Subject: [PATCH 2/2] [-] Fixed isssue with consider downtimes option ITC-1115 --- app/Controller/InstantreportsController.php | 65 ++++++++++++++++++++- app/Model/Instantreport.php | 3 +- 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/app/Controller/InstantreportsController.php b/app/Controller/InstantreportsController.php index 08a1fdab23..bc34fa88be 100644 --- a/app/Controller/InstantreportsController.php +++ b/app/Controller/InstantreportsController.php @@ -474,6 +474,7 @@ private function generateReport($instantReport, $baseStartDate, $baseEndDate, $r } $this->loadModel(MONITORING_OBJECTS); + $this->loadModel(MONITORING_STATEHISTORY); $this->Objects->bindModel([ 'hasMany' => [ 'Statehistory' => [ @@ -513,7 +514,9 @@ private function generateReport($instantReport, $baseStartDate, $baseEndDate, $r 'object_id', 'state_time', 'state', 'state_type', 'last_state', 'last_hard_state', ], 'conditions' => [ - "Statehistory.state_time <= '$endDateSqlFormat'", + 'Statehistory.state_time + BETWEEN "' . $startDateSqlFormat . '" + AND "' . $endDateSqlFormat . '"', ], 'order' => [ 'Statehistory.state_time', @@ -543,6 +546,24 @@ private function generateReport($instantReport, $baseStartDate, $baseEndDate, $r ]); if (!empty($stateHistoryWithObject)) { + if(empty($stateHistoryWithObject[0]['Statehistory'])){ + $stateHistoryWithPrev = $this->Statehistory->find('first', [ + 'recursive' => -1, + 'fields' => ['Statehistory.object_id', 'Statehistory.state_time', 'Statehistory.state', 'Statehistory.state_type', 'Statehistory.last_state', 'Statehistory.last_hard_state'], + 'conditions' => [ + 'AND' => [ + 'Statehistory.object_id' => $stateHistoryWithObject[0]['Objects']['object_id'], + 'Statehistory.state_time <= "'.$startDateSqlFormat.'"' + ], + ], + 'order' => ['Statehistory.state_time' => 'DESC'], + + ]); + } + if(!empty($stateHistoryWithPrev)){ + $stateHistoryWithObject[0]['Statehistory'][0] = $stateHistoryWithPrev['Statehistory']; + } +// debug($stateHistoryWithObject);exit; if ($instantReport['Instantreport']['downtimes'] !== '1') { $timeSlices = $timeSlicesGlobal; } else { @@ -617,7 +638,9 @@ function ($downtimes) { 'object_id', 'state_time', 'state', 'state_type', 'last_state', 'last_hard_state', ], 'conditions' => [ - "Statehistory.state_time <= '$endDateSqlFormat'", + 'Statehistory.state_time + BETWEEN "' . $startDateSqlFormat . '" + AND "' . $endDateSqlFormat . '"', ], 'order' => [ 'Statehistory.state_time', @@ -646,6 +669,23 @@ function ($downtimes) { ], ]); if (!empty($stateHistoryWithObject)) { + if(empty($stateHistoryWithObject[0]['Statehistory'])){ + $stateHistoryWithPrev = $this->Statehistory->find('first', [ + 'recursive' => -1, + 'fields' => ['Statehistory.object_id', 'Statehistory.state_time', 'Statehistory.state', 'Statehistory.state_type', 'Statehistory.last_state', 'Statehistory.last_hard_state'], + 'conditions' => [ + 'AND' => [ + 'Statehistory.object_id' => $stateHistoryWithObject[0]['Objects']['object_id'], + 'Statehistory.state_time <= "'.$startDateSqlFormat.'"' + ], + ], + 'order' => ['Statehistory.state_time' => 'DESC'], + + ]); + } + if(!empty($stateHistoryWithPrev)){ + $stateHistoryWithObject[0]['Statehistory'][0] = $stateHistoryWithPrev['Statehistory']; + } if ($instantReport['Instantreport']['downtimes'] !== '1') { $timeSlices = $timeSlicesGlobal; } else { @@ -727,7 +767,9 @@ function ($downtimes) { 'object_id', 'state_time', 'state', 'state_type', 'last_state', 'last_hard_state', ], 'conditions' => [ - "Statehistory.state_time <= '$endDateSqlFormat'", + 'Statehistory.state_time + BETWEEN "' . $startDateSqlFormat . '" + AND "' . $endDateSqlFormat . '"', ], ], 'Downtime' => [ @@ -754,6 +796,23 @@ function ($downtimes) { ]); if (!empty($stateHistoryWithObject)) { + if(empty($stateHistoryWithObject[0]['Statehistory'])){ + $stateHistoryWithPrev = $this->Statehistory->find('first', [ + 'recursive' => -1, + 'fields' => ['Statehistory.object_id', 'Statehistory.state_time', 'Statehistory.state', 'Statehistory.state_type', 'Statehistory.last_state', 'Statehistory.last_hard_state'], + 'conditions' => [ + 'AND' => [ + 'Statehistory.object_id' => $stateHistoryWithObject[0]['Objects']['object_id'], + 'Statehistory.state_time <= "'.$startDateSqlFormat.'"' + ], + ], + 'order' => ['Statehistory.state_time' => 'DESC'], + + ]); + } + if(!empty($stateHistoryWithPrev)){ + $stateHistoryWithObject[0]['Statehistory'][0] = $stateHistoryWithPrev['Statehistory']; + } if ($instantReport['Instantreport']['downtimes'] !== '1') { $timeSlices = $timeSlicesGlobal; } else { diff --git a/app/Model/Instantreport.php b/app/Model/Instantreport.php index c23734ee28..0191f50723 100644 --- a/app/Model/Instantreport.php +++ b/app/Model/Instantreport.php @@ -229,7 +229,6 @@ public function generateInstantreportData($totalTime, $timeSlices, $stateHistory $outageState = ($objectHost) ? 1 : 2; // 1 for host down and 2 for service critical $setInitialState = false; $currentState = 0; - foreach ($timeSlices as $timeSliceKey => $timeSlice) { $time = $timeSlice['start']; if ($time > strtotime('today 23:59:59')) { // ignore time_slice in the future @@ -268,7 +267,7 @@ public function generateInstantreportData($totalTime, $timeSlices, $stateHistory //if outage in downtime add time for state "ok" if ($currentState == $outageState && $isDowntime) { - $evaluationData[$outageState] += $timeSlice['end'] - $time; + $evaluationData[0] += $timeSlice['end'] - $time; } else { $evaluationData[$currentState] += $timeSlice['end'] - $time; }