2009-01-16 Evi Vanoost <vanooste@rcbi.rochester.edu>
* godmode/alerts/configure_alert_template.php: Some aesthetic fixes and non-init variable fixes * include/functions_db.php: Added get_moduletypes since I needed it and fixed the documentation tags for 2 functions. Reparsed all documentation * include/functions_reporting.php: Fixed get_group_stats to work faster and now correctly returns the status even if data modules report 0.00 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1355 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
1ec6ddb585
commit
37ef8e58de
|
@ -1,3 +1,14 @@
|
|||
2009-01-16 Evi Vanoost <vanooste@rcbi.rochester.edu>
|
||||
|
||||
* godmode/alerts/configure_alert_template.php: Some aesthetic fixes and
|
||||
non-init variable fixes
|
||||
|
||||
* include/functions_db.php: Added get_moduletypes since I needed it and
|
||||
fixed the documentation tags for 2 functions. Reparsed all documentation
|
||||
|
||||
* include/functions_reporting.php: Fixed get_group_stats to work faster
|
||||
and now correctly returns the status even if data modules report 0.00
|
||||
|
||||
2009-01-16 Raul Mateos <raulofpandora@gmail.com>
|
||||
|
||||
* index.php: Updated year in header. Solved small notice error.
|
||||
|
|
|
@ -271,6 +271,7 @@ $threshold = 300;
|
|||
$recovery_notify = false;
|
||||
$field2_recovery = '';
|
||||
$field3_recovery = '';
|
||||
$matches = true;
|
||||
|
||||
if ($create_template) {
|
||||
$name = (string) get_parameter ('name');
|
||||
|
@ -280,6 +281,7 @@ if ($create_template) {
|
|||
$max = (float) get_parameter ('max');
|
||||
$min = (float) get_parameter ('min');
|
||||
|
||||
|
||||
$result = create_alert_template ($name, $type,
|
||||
array ('description' => $description,
|
||||
'value' => $value,
|
||||
|
@ -493,7 +495,7 @@ if ($step == 2) {
|
|||
$table->data[2][1] = print_select (get_alert_templates_types (), 'type',
|
||||
$type, '', __('Select'), 0, true, false, false);
|
||||
$table->data[2][1] .= '<span id="matches_value" '.($show_matches ? '' : 'style="display: none"').'>';
|
||||
$table->data[2][1] .= print_checkbox ('matches_value', 1, $matches, true);
|
||||
$table->data[2][1] .= ' '.print_checkbox ('matches_value', 1, $matches, true);
|
||||
$table->data[2][1] .= print_label (__('Trigger when matches the value'),
|
||||
'checkbox-matches_value', true);
|
||||
$table->data[2][1] .= '</span>';
|
||||
|
@ -501,7 +503,7 @@ if ($step == 2) {
|
|||
$table->data['value'][0] = __('Value');
|
||||
$table->data['value'][1] = print_input_text ('value', $value, '',
|
||||
35, 255, true);
|
||||
$table->data['value'][1] .= '<span id="regex_ok">';
|
||||
$table->data['value'][1] .= ' <span id="regex_ok">';
|
||||
$table->data['value'][1] .= print_image ('images/suc.png', true,
|
||||
array ('style' => 'display:none',
|
||||
'id' => 'regex_good',
|
||||
|
@ -512,11 +514,12 @@ if ($step == 2) {
|
|||
'title' => __('The regular expression is not valid')));
|
||||
$table->data['value'][1] .= '</span>';
|
||||
|
||||
$table->data['max'][0] = __('Max.');
|
||||
$table->data['max'][1] = print_input_text ('max', $max, '', 5, 255, true);
|
||||
|
||||
//Min first, then max, that's more logical
|
||||
$table->data['min'][0] = __('Min.');
|
||||
$table->data['min'][1] = print_input_text ('min', $min, '', 5, 255, true);
|
||||
|
||||
$table->data['max'][0] = __('Max.');
|
||||
$table->data['max'][1] = print_input_text ('max', $max, '', 5, 255, true);
|
||||
|
||||
$table->data['example'][1] = print_alert_template_example ($id, true);
|
||||
$table->colspan['example'][1] = 2;
|
||||
|
|
|
@ -747,6 +747,43 @@ function get_moduletype_name ($id_type) {
|
|||
return (string) get_db_value ('nombre', 'ttipo_modulo', 'id_tipo', (int) $id_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with all module types (default) or if "remote" or "agent"
|
||||
* is passed it will return only remote (ICMP, SNMP, TCP...) module types
|
||||
* otherwise the full list + the column you specify
|
||||
*
|
||||
* @param string Specifies which type to return (will return an array with id's)
|
||||
* @param string Which rows to select (defaults to nombre)
|
||||
*
|
||||
* @return array Either the full table or if a type is specified, an array with id's
|
||||
*/
|
||||
function get_moduletypes ($type = "all", $rows = "nombre") {
|
||||
$return = array ();
|
||||
$rows = (array) $rows; //Cast as array
|
||||
$row_cnt = count ($rows);
|
||||
if ($type == "remote") {
|
||||
return array_merge (range (6,18), (array) 100);
|
||||
} elseif ($type == "agent") {
|
||||
return array_merge (range (1,4), range (19,24));
|
||||
}
|
||||
|
||||
$sql = sprintf ("SELECT id_tipo,%s FROM ttipo_modulo", implode (",", $rows));
|
||||
$result = get_db_all_rows_sql ($sql);
|
||||
if ($result === false) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
foreach ($result as $type) {
|
||||
if ($row_cnt > 1) {
|
||||
$return[$type["id_tipo"]] = $type;
|
||||
} else {
|
||||
$return[$type["id_tipo"]] = $type[reset ($rows)];
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated Use get_agent_group ($id) now (fully compatible)
|
||||
*/
|
||||
|
@ -2297,7 +2334,7 @@ function get_modulegroup_name ($modulegroup_id) {
|
|||
* @param mixed A single row or array of rows to insert to
|
||||
* @param mixed A single value or array of values to insert (can be a multiple amount of rows)
|
||||
*
|
||||
* @result mixed False in case of error or invalid values passed. Affected rows otherwise
|
||||
* @return mixed False in case of error or invalid values passed. Affected rows otherwise
|
||||
*/
|
||||
function process_sql_insert ($table, $rows, $values) {
|
||||
if (empty ($rows) || empty ($values)) { //Empty rows or values not processed
|
||||
|
@ -2374,7 +2411,7 @@ process_sql_update ('table', array ('field' => 2), 'id in (1, 2, 3) OR id > 10')
|
|||
* between the fields. "AND" operator will be use by default. Other values might
|
||||
* be "OR", "AND NOT", "XOR"
|
||||
*
|
||||
* @result mixed False in case of error or invalid values passed. Affected rows otherwise
|
||||
* @return mixed False in case of error or invalid values passed. Affected rows otherwise
|
||||
*/
|
||||
function process_sql_update ($table, $values, $where = false, $where_join = 'AND') {
|
||||
$query = sprintf ("UPDATE `%s` SET ", $table);
|
||||
|
|
|
@ -118,27 +118,6 @@ function get_agent_module_sla ($id_agent_module, $period, $min_value, $max_value
|
|||
* @return array
|
||||
*/
|
||||
function get_group_stats ($id_group) {
|
||||
$groups = array_keys (get_user_groups ());
|
||||
if ($id_group > 0 && in_array ($groups, $id_group)) {
|
||||
//If a group is selected, and we have permissions to it then we don't need to look for them
|
||||
$groups = array ();
|
||||
$groups[0] = $id_group;
|
||||
}
|
||||
|
||||
//Select all modules in group
|
||||
$sql = sprintf ("SELECT tagente.id_agente, tagente_estado.estado, tagente_estado.datos, tagente_estado.current_interval, tagente_estado.utimestamp,
|
||||
tagente_estado.id_agente_modulo, tagente_modulo.id_tipo_modulo
|
||||
FROM tagente, tagente_estado, tagente_modulo
|
||||
WHERE tagente.disabled = 0 AND tagente.id_grupo IN (%s)
|
||||
AND tagente.id_agente = tagente_estado.id_agente
|
||||
AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo
|
||||
AND tagente_modulo.disabled = 0",
|
||||
implode (",",$groups));
|
||||
$result = get_db_all_rows_sql ($sql);
|
||||
|
||||
if ($result === false)
|
||||
$result = array ();
|
||||
|
||||
$data = array ();
|
||||
$data["monitor_checks"] = 0;
|
||||
$data["monitor_not_init"] = 0;
|
||||
|
@ -156,12 +135,54 @@ function get_group_stats ($id_group) {
|
|||
$data["data_alerts"] = 0;
|
||||
$data["data_alerts_fired"] = 0;
|
||||
$data["data_alerts_fire_count"] = 0;
|
||||
|
||||
$data["total_agents"] = 0;
|
||||
$data["total_checks"] = 0;
|
||||
$data["total_ok"] = 0;
|
||||
$data["total_alerts"] = 0;
|
||||
$data["total_alerts_fired"] = 0;
|
||||
$data["total_alerts_fire_count"] = 0;
|
||||
$data["monitor_bad"] = 0;
|
||||
$data["data_bad"] = 0;
|
||||
$data["total_bad"] = 0;
|
||||
$data["total_not_init"] = 0;
|
||||
$data["total_down"] = 0;
|
||||
$data["monitor_health"] = 100;
|
||||
$data["data_health"] = 100;
|
||||
$data["global_health"] = 100;
|
||||
$data["alert_level"] = 100;
|
||||
$data["module_sanity"] = 100;
|
||||
$data["server_sanity"] = 100;
|
||||
$cur_time = get_system_time ();
|
||||
|
||||
$groups = array_keys (get_user_groups ());
|
||||
if ($id_group > 0 && in_array ($groups, $id_group)) {
|
||||
//If a group is selected, and we have permissions to it then we don't need to look for them
|
||||
$groups = array ();
|
||||
$groups[0] = $id_group;
|
||||
}
|
||||
|
||||
//Select all modules in group
|
||||
$agents = get_group_agents ($groups);
|
||||
$modules = array ();
|
||||
$module_ids = array ();
|
||||
|
||||
if (empty ($agents)) {
|
||||
//No agents in this group, means no data
|
||||
return $data;
|
||||
}
|
||||
|
||||
$sql = sprintf ("SELECT tagente_estado.id_agente_modulo, tagente_modulo.id_tipo_modulo, estado, datos, current_interval, utimestamp FROM tagente_estado, tagente_modulo WHERE tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.id_agente IN (%s)", implode (",", array_keys ($agents)));
|
||||
$result = get_db_all_rows_sql ($sql);
|
||||
|
||||
if ($result === false) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
$module_remote = get_moduletypes ("remote");
|
||||
|
||||
foreach ($result as $row) {
|
||||
$last_update = $cur_time - $row["utimestamp"];
|
||||
if ($row["estado"] != 100) {
|
||||
if (in_array ($row["id_tipo_modulo"], $module_remote)) {
|
||||
//This module is a monitor (remote)
|
||||
$data["monitor_checks"]++;
|
||||
|
||||
|
@ -172,12 +193,10 @@ function get_group_stats ($id_group) {
|
|||
} elseif ($last_update >= ($row["current_interval"] * 2)) {
|
||||
//The utimestamp is greater than 2x the interval (it has timed out)
|
||||
$data["monitor_unknown"]++;
|
||||
} elseif ($row["datos"] != 0) {
|
||||
//Status is something
|
||||
$data["monitor_ok"]++;
|
||||
} else {
|
||||
//Otherwise it's down
|
||||
} elseif ($row["estado"] == 1 || $row["estado"] == 2) {
|
||||
$data["monitor_down"]++;
|
||||
} else {
|
||||
$data["monitor_ok"]++;
|
||||
}
|
||||
|
||||
$sql = sprintf ("SELECT times_fired FROM talerta_agente_modulo WHERE id_agente_modulo = %d", $row["id_agente_modulo"]);
|
||||
|
@ -200,12 +219,10 @@ function get_group_stats ($id_group) {
|
|||
} elseif ($last_update >= ($row["current_interval"] * 2)) {
|
||||
//The utimestamp is greater than 2x the interval (it has timed out)
|
||||
$data["data_unknown"]++;
|
||||
} elseif ($row["datos"]) {
|
||||
//Status is something
|
||||
$data["data_ok"]++;
|
||||
} else {
|
||||
//Otherwise it's down
|
||||
} elseif ($row["estado"] == 1 || $row["estado"] == 2) {
|
||||
$data["data_down"]++;
|
||||
} else {
|
||||
$data["data_ok"]++;
|
||||
}
|
||||
|
||||
$sql = sprintf ("SELECT times_fired FROM talerta_agente_modulo WHERE id_agente_modulo = %d", $row["id_agente_modulo"]);
|
||||
|
@ -220,7 +237,7 @@ function get_group_stats ($id_group) {
|
|||
} //End module check
|
||||
} //End foreach module
|
||||
|
||||
$data["total_agents"] = count (get_group_agents ($groups, false, "none"));
|
||||
$data["total_agents"] = count ($agents);
|
||||
$data["total_checks"] = $data["data_checks"] + $data["monitor_checks"];
|
||||
$data["total_ok"] = $data["data_ok"] + $data["monitor_ok"];
|
||||
$data["total_alerts"] = $data["data_alerts"] + $data["monitor_alerts"];
|
||||
|
@ -242,7 +259,7 @@ function get_group_stats ($id_group) {
|
|||
Server Sanity 0% Uninitialized modules
|
||||
|
||||
*/
|
||||
if ($data["monitor_bad"] > 0 && $data["monitor_checks"]) {
|
||||
if ($data["monitor_bad"] > 0 && $data["monitor_checks"] > 0) {
|
||||
$data["monitor_health"] = format_numeric (100 - ($data["monitor_bad"] / ($data["monitor_checks"] / 100)), 1);
|
||||
} else {
|
||||
$data["monitor_health"] = 100;
|
||||
|
|
Loading…
Reference in New Issue