Skip to content

Commit

Permalink
Merge pull request #577 from it-novum/ITC-1115
Browse files Browse the repository at this point in the history
Itc 1115
  • Loading branch information
ZizaL authored Jun 8, 2017
2 parents e7b4d83 + 724574b commit bb77281
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 7 deletions.
65 changes: 61 additions & 4 deletions app/Controller/InstantreportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ private function generateReport($instantReport, $baseStartDate, $baseEndDate, $r
}

$this->loadModel(MONITORING_OBJECTS);
$this->loadModel(MONITORING_STATEHISTORY);
$this->Objects->bindModel([
'hasMany' => [
'Statehistory' => [
Expand Down Expand Up @@ -514,8 +515,8 @@ private function generateReport($instantReport, $baseStartDate, $baseEndDate, $r
],
'conditions' => [
'Statehistory.state_time
BETWEEN "'.$startDateSqlFormat.'"
AND "'.$endDateSqlFormat.'"',
BETWEEN "' . $startDateSqlFormat . '"
AND "' . $endDateSqlFormat . '"',
],
'order' => [
'Statehistory.state_time',
Expand Down Expand Up @@ -545,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 {
Expand Down Expand Up @@ -619,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',
Expand Down Expand Up @@ -648,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 {
Expand Down Expand Up @@ -729,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' => [
Expand All @@ -756,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 {
Expand Down
5 changes: 2 additions & 3 deletions app/Model/Instantreport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -267,8 +266,8 @@ public function generateInstantreportData($totalTime, $timeSlices, $stateHistory
}

//if outage in downtime add time for state "ok"
if ($currentState == $outageState || $isDowntime) {
$evaluationData[$outageState] += $timeSlice['end'] - $time;
if ($currentState == $outageState && $isDowntime) {
$evaluationData[0] += $timeSlice['end'] - $time;
} else {
$evaluationData[$currentState] += $timeSlice['end'] - $time;
}
Expand Down

0 comments on commit bb77281

Please sign in to comment.