function type_other($type = 'average') { global $DB; $pmService = new PluginMonitoringService(); $pmServiceevent = new PluginMonitoringServiceevent(); $pmComponent = new PluginMonitoringComponent(); $pmPerfdataDetail = new PluginMonitoringPerfdataDetail(); $a_date = PluginMonitoringCustomitem_Common::getTimeRange($this->fields); $val = 0; $a_val = array(); $nb_val = 0; $a_tocheck = array('warn' => 0, 'crit' => 0, 'limit' => 0); $a_types = array('warn', 'crit', 'limit'); for ($i = 0; $i < count($a_types); $i++) { if (is_numeric($this->fields['aggregate_' . $a_types[$i]])) { $a_ret[$a_types[$i]] = $this->fields['aggregate_' . $a_types[$i]]; } else { $a_ret[$a_types[$i]] = 0; $a_tocheck[$a_types[$i]] = 1; } } $items = importArrayFromDB($this->fields['aggregate_items']); foreach ($items as $itemtype => $data) { switch ($itemtype) { case 'PluginMonitoringService': foreach ($data as $items_id => $data2) { $pmService->getFromDB($items_id); $_SESSION['plugin_monitoring_checkinterval'] = PluginMonitoringComponent::getTimeBetween2Checks($pmService->fields['plugin_monitoring_components_id']); $pmComponent->getFromDB($pmService->fields['plugin_monitoring_components_id']); $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n WHERE `plugin_monitoring_services_id`='" . $items_id . "'\n AND `date` >= '" . $a_date['begin'] . "'\n ORDER BY `date`"; $result = $DB->query($query); $ret = $pmServiceevent->getData($result, $pmComponent->fields['graph_template'], $a_date['begin'], $a_date['end']); foreach ($data2 as $a_perfdatadetails) { $pmPerfdataDetail->getFromDB($a_perfdatadetails['perfdatadetails_id']); $nb_val += count($ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); $val += array_sum($ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); $a_val = array_merge($a_val, $ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); } // for manage warn, crit and limit foreach ($a_tocheck as $other_type => $num_type) { if ($num_type == 1) { $other_items = importArrayFromDB($this->fields['aggregate_' . $other_type]); foreach ($other_items[$itemtype][$items_id] as $a_perfdatadetails) { $pmPerfdataDetail->getFromDB($a_perfdatadetails['perfdatadetails_id']); $a_ret[$other_type] += array_sum($ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); } } } } break; case 'PluginMonitoringComponentscatalog': $pmComponentscatalog = new PluginMonitoringComponentscatalog(); foreach ($data as $items_id => $data2) { $ret = $pmComponentscatalog->getInfoOfCatalog(str_replace('id', '', $items_id)); $a_hosts = $ret[6]; foreach ($data2['PluginMonitoringComponent'] as $items_id_components => $data4) { $query = "SELECT * FROM `glpi_plugin_monitoring_services`\n WHERE `plugin_monitoring_components_id`='" . str_replace('id', '', $items_id_components) . "'\n AND `plugin_monitoring_componentscatalogs_hosts_id` IN\n ('" . implode("','", $a_hosts) . "')\n AND `entities_id` IN (" . $_SESSION['glpiactiveentities_string'] . ")"; $result = $DB->query($query); while ($dataq = $DB->fetch_array($result)) { $pmService->getFromDB($dataq['id']); $_SESSION['plugin_monitoring_checkinterval'] = PluginMonitoringComponent::getTimeBetween2Checks($pmService->fields['plugin_monitoring_components_id']); $pmComponent->getFromDB($dataq['plugin_monitoring_components_id']); $query = "SELECT * FROM `glpi_plugin_monitoring_serviceevents`\n WHERE `plugin_monitoring_services_id`='" . $dataq['id'] . "'\n AND `date` >= '" . $a_date['begin'] . "'\n ORDER BY `date`"; $result = $DB->query($query); $ret = $pmServiceevent->getData($result, $pmComponent->fields['graph_template'], $a_date['begin'], $a_date['end']); foreach ($data4 as $a_perfdatadetails) { $pmPerfdataDetail->getFromDB($a_perfdatadetails['perfdatadetails_id']); $nb_val += count($ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); $val += array_sum($ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); $a_val = array_merge($a_val, $ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); } // for manage warn, crit and limit foreach ($a_tocheck as $other_type => $num_type) { if ($num_type == 1) { $other_items = importArrayFromDB($this->fields['aggregate_' . $other_type]); foreach ($other_items[$itemtype][$items_id]['PluginMonitoringComponent'][$items_id_components] as $a_perfdatadetails) { $pmPerfdataDetail->getFromDB($a_perfdatadetails['perfdatadetails_id']); $a_ret[$other_type] += array_sum($ret[0][$pmPerfdataDetail->fields['dsname' . $a_perfdatadetails['perfdatadetails_dsname']]]); } } } } } } break; } } if ($nb_val != 0) { if ($type == 'average') { $val = $val / $nb_val; } else { if ($type == 'median') { sort($a_val); $count = count($a_val); //total numbers in array $middleval = floor(($count - 1) / 2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $a_val[$middleval]; } else { // even number, calculate avg of 2 medians $low = $arr[$middleval]; $high = $arr[$middleval + 1]; $median = ($low + $high) / 2; } $val = $median; } } } foreach ($a_tocheck as $other_type => $num_type) { if ($num_type == 1) { $a_ret[$other_type] = $a_ret[$other_type] / $nb_val; } } $a_ret['val'] = $val; return $a_ret; }