reports: Generalize dates, saved reports
[ninja.git] / modules / reports / libraries / BestStateCalculator.php
blob96d2e7a62238c24440f1164cd8e5bca0a9ae0aeb
1 <?php
3 /**
4 * State calculator for multiple objects that returns the best state at any point in time
5 */
6 class BestStateCalculator extends WorstStateCalculator
8 public function calculate_object_state()
10 if ($this->st_is_service)
11 $states = array(Reports_Model::SERVICE_OK, Reports_Model::SERVICE_WARNING, Reports_Model::SERVICE_CRITICAL, Reports_Model::SERVICE_UNKNOWN, Reports_Model::SERVICE_PENDING, Reports_Model::SERVICE_EXCLUDED);
12 else
13 $states = array(Reports_Model::HOST_UP, Reports_Model::HOST_DOWN, Reports_Model::HOST_UNREACHABLE, Reports_Model::HOST_PENDING, Reports_Model::HOST_EXCLUDED);
15 $final_state = $states[count($states) - 1];
17 foreach ($states as $state) {
18 $keys = array_keys($this->st_sub[$state]);
19 // Sort downtime states outside downtime first
20 sort($keys);
21 foreach ($keys as $in_dt) {
22 if (!empty($this->st_sub[$state][$in_dt])) {
23 $final_state = $state;
24 $this->st_dt_depth = $in_dt;
25 break 2;
30 $this->st_obj_state = $final_state;