2011-08-01 Tomas Palacios <tomas.palacios@artica.es>

* godmode/alerts: fixed a bug regarding creation
        and updates of alert templates, actions and commands
        with blank or already used name fields.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4658 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Aldrioth 2011-08-01 14:51:38 +00:00
parent cc6afaccac
commit 95b7b0728b
3 changed files with 65 additions and 28 deletions

View File

@ -113,23 +113,29 @@ if ($create_action) {
$field3 = (string) get_parameter ('field3');
$group = (string) get_parameter ('group');
$action_threshold = (int) get_parameter ('action_threshold');
$name_check = db_get_value ('name', 'talert_actions', 'name', $name);
$result = alerts_create_alert_action ($name, $id_alert_command,
array ('field1' => $field1,
'field2' => $field2,
'field3' => $field3,
'id_group' => $group,
'action_threshold' => $action_threshold));
if ($name_check) {
$result = '';
}
else {
$result = alerts_create_alert_action ($name, $id_alert_command,
array ('field1' => $field1,
'field2' => $field2,
'field3' => $field3,
'id_group' => $group,
'action_threshold' => $action_threshold));
$info = 'Name: ' . $name . ' ID alert Command: ' . $id_alert_command .
' Field1: ' . $field1 . ' Field2: ' . $field2 . ' Field3: ' . $field3 . ' Group: ' . $group .
' Action threshold: ' . $action_threshold;
$info = 'Name: ' . $name . ' ID alert Command: ' . $id_alert_command .
' Field1: ' . $field1 . ' Field2: ' . $field2 . ' Field3: ' . $field3 . ' Group: ' . $group .
' Action threshold: ' . $action_threshold;
}
if ($result) {
db_pandora_audit("Command management", "Create alert action " . $result, false, false, $info);
}
else {
db_pandora_audit("Command management", "Fail try to create alert action", false, false, $info);
db_pandora_audit("Command management", "Fail try to create alert action", false, false);
}
ui_print_result_message ($result,
@ -174,13 +180,20 @@ if ($update_action) {
$values['field3'] = $field3;
$values['id_group'] = $group;
$values['action_threshold'] = $action_threshold;
$name_check = db_get_value ('name', 'talert_actions', 'name', $name);
$result = alerts_update_alert_action ($id, $values);
if (!$name || $name_check) {
$result = '';
}
else {
$result = alerts_update_alert_action ($id, $values);
$info = 'Name: ' . $name . ' ID alert Command: ' . $id_alert_command .
' Field1: ' . $field1 . ' Field2: ' . $field2 . ' Field3: ' . $field3 . ' Group: ' . $group .
' Action threshold: ' . $action_threshold;
$info = 'Name: ' . $name . ' ID alert Command: ' . $id_alert_command .
' Field1: ' . $field1 . ' Field2: ' . $field2 . ' Field3: ' . $field3 . ' Group: ' . $group .
' Action threshold: ' . $action_threshold;
}
if ($result) {
db_pandora_audit("Command management", "Update alert action " . $id, false, false, json_encode($values));
}

View File

@ -49,17 +49,23 @@ if ($create_command) {
$name = (string) get_parameter ('name');
$command = (string) get_parameter ('command');
$description = (string) get_parameter ('description');
$result = alerts_create_alert_command ($name, $command,
array ('description' => $description));
$info = 'Name: ' . $name . ' Command: ' . $command . ' Description: ' . $description;
$name_check = db_get_value ('name', 'talert_commands', 'name', $name);
if (!$name_check) {
$result = alerts_create_alert_command ($name, $command,
array ('description' => $description));
$info = 'Name: ' . $name . ' Command: ' . $command . ' Description: ' . $description;
}
else {
$result = '';
}
if ($result) {
db_pandora_audit("Command management", "Create alert command " . $result, false, false, $info);
}
else {
db_pandora_audit("Command management", "Fail try to create alert command", false, false, $info);
db_pandora_audit("Command management", "Fail try to create alert command", false, false);
}
ui_print_result_message ($result,
@ -83,14 +89,21 @@ if ($update_command) {
$values['name'] = $name;
$values['command'] = $command;
$values['description'] = $description;
$result = alerts_update_alert_command ($id, $values);
$name_check = db_get_value ('name', 'talert_commands', 'name', $name);
$info = 'Name: ' . $name . ' Command: ' . $command . ' Description: ' . $description;
if (!$name || $name_check) {
$result = '';
}
else {
$result = alerts_update_alert_command ($id, $values);
$info = 'Name: ' . $name . ' Command: ' . $command . ' Description: ' . $description;
}
if ($result) {
db_pandora_audit("Command management", "Create alert command " . $id, false, false, $info);
}
else {
db_pandora_audit("Command management", "Fail to create alert command " . $id, false, false, $info);
db_pandora_audit("Command management", "Fail to create alert command " . $id, false, false);
}
ui_print_result_message ($result,

View File

@ -178,6 +178,7 @@ function update_template ($step) {
$matches = (bool) get_parameter ('matches_value');
$priority = (int) get_parameter ('priority');
$id_group = get_parameter ("id_group");
$name_check = db_get_value ('name', 'talert_templates', 'name', $name);
$values = array ('name' => $name,
'type' => $type,
@ -188,8 +189,13 @@ function update_template ($step) {
'id_group' => $id_group,
'matches_value' => $matches,
'priority' => $priority);
$result = alerts_update_alert_template ($id,$values);
if (!$name || $name_check) {
$result = '';
}
else {
$result = alerts_update_alert_template ($id,$values);
}
}
elseif ($step == 2) {
$monday = (bool) get_parameter ('monday');
@ -330,6 +336,7 @@ if ($create_template) {
$matches = (bool) get_parameter ('matches_value');
$priority = (int) get_parameter ('priority');
$id_group = get_parameter ("id_group");
$name_check = db_get_value ('name', 'talert_templates', 'name', $name);
switch ($config['dbtype']){
case "mysql":
@ -354,8 +361,12 @@ if ($create_template) {
'field3_recovery' => ' ');
break;
}
$result = alerts_create_alert_template ($name, $type, $values);
if (!$name_check) {
$result = alerts_create_alert_template ($name, $type, $values);
}
else {
$result = '';
}
if ($result) {
db_pandora_audit("Command management", "Create alert command " . $result, false, false, json_encode($values));
}