Revert "Add CLI/API new function of create modules synthetic. Tiquet: #3034"

This reverts commit c0563a54ed.
This commit is contained in:
m-lopez-f 2015-12-21 15:56:51 +01:00
parent c73764196a
commit 912e087ebd
2 changed files with 0 additions and 207 deletions

View File

@ -33,7 +33,6 @@ include_once($config['homedir'] . "/include/functions_planned_downtimes.php");
enterprise_include_once ('include/functions_local_components.php');
enterprise_include_once ('include/functions_events.php');
enterprise_include_once ('include/functions_agents.php');
enterprise_include_once ('include/functions_modules.php');
/**
* Parse the "other" parameter.
@ -2046,127 +2045,6 @@ function api_set_create_data_module($id, $thrash1, $other, $thrash3) {
}
}
/**
* Create a synthetic module in agent. And return the id_agent_module of new module.
* Note: Only adds database information, this function doesn't alter config file information.
*
* @param string $id Name of agent to add the module.
* @param $thrash1 Don't use.
* @param array $other it's array, $other as param is <name_module><synthetic_type><AgentName;Operation;NameModule> OR <AgentName;NameModule> OR <Operation;Value>in this order
* and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_<separator>)
* example:
*
* api.php?op=set&op2=create_synthetic_module&id=pepito&other=prueba|average|Agent%20Name;AVG;Name%20Module|Agent%20Name2;AVG;Name%20Module2&other_mode=url_encode_separator_|
*
* @param $thrash3 Don't use
*/
function api_set_create_synthetic_module($id, $thrash1, $other, $thrash3) {
if (defined ('METACONSOLE')) {
return;
}
$agentName = $id;
io_safe_input_array($other);
if ($other['data'][0] == "") {
returnError('error_create_data_module', __('Error in creation synthetic module. Module_name cannot be left blank.'));
return;
}
$idAgent = agents_get_agent_id(io_safe_output($agentName),true);
if (!$idAgent) {
returnError('error_create_data_module', __('Error in creation synthetic module. Agent name doesn\'t exists.'));
return;
}
$name = io_safe_output($other['data'][0]);
$name = io_safe_input($name);
$values = array(
'id_agente' => $idAgent,
'id_modulo' => 5,
'custom_integer_1' => 0,
'custom_integer_2' => 0,
'prediction_module' => 3,
);
if ( ! $values['descripcion'] ) {
$values['descripcion'] = ''; // Column 'descripcion' cannot be null
}
$idModule = modules_create_agent_module($idAgent, $name, $values, true);
if (is_error($idModule)) {
// TODO: Improve the error returning more info
returnError('error_create_data_module', __('Error in creation data module.'));
}
else {
$synthetic_type = $other['data'][1];
unset($other['data'][0]);
unset($other['data'][1]);
$filterdata = array();
foreach ($other['data'] as $data) {
$data = str_replace(array('ADD','SUB','MUL','DIV'),array('+','-','*','/'),$data);
$split_data = explode(';',$data);
if ( preg_match("/[x\/+*-]/",$split_data[0]) && strlen($split_data[0]) == 1 ) {
if ( preg_match("/[\/|+|*|-]/",$split_data[0]) && $synthetic_type === 'average' ) {
returnError("","[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n");
}
$operator = $split_data[0] == 'x' ? 'avg' : $split_data[0];
$data_module = array("",$operator,$split_data[1]);
$text_data = implode('_',$data_module);
array_push($filterdata,$text_data);
}
else {
if (count($split_data) == 2) {
$idAgent = agents_get_agent_id(io_safe_output($split_data[0]),true);
$data_module = array($idAgent,'',$split_data[1]);
$text_data = implode('_',$data_module);
array_push($filterdata,$text_data);
}
else {
if (strlen($split_data[1]) > 1 ) {
returnError("","[ERROR] You can only use +, -, *, / or x, and you use this: @split_data[1] \n\n");
}
if ( preg_match("/[\/|+|*|-]/",$split_data[1]) && $synthetic_type === 'average' ) {
returnError("","[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n");
}
$idAgent = agents_get_agent_id(io_safe_output($split_data[0]),true);
$operator = $split_data[1] == 'x' ? 'avg' : $split_data[1];
$data_module = array($idAgent,$operator,$split_data[2]);
$text_data = implode('_',$data_module);
array_push($filterdata,$text_data);
}
}
}
$serialize_ops = implode(',',$filterdata);
//modules_create_synthetic_operations
$synthetic = enterprise_hook('modules_create_synthetic_operations',
array($idModule, $serialize_ops));
if ($synthetic === ENTERPRISE_NOT_HOOK) {
returnError('error_policy_modules', 'Error Synthetic modules.');
return;
}
else {
returnData('string', array('type' => 'string', 'data' => __('Synthetic module created ID: ' . $idModule)));
}
//enterprise
}
}
/**
* Update a data module in agent. And return a message with the result of the operation.
*

View File

@ -132,7 +132,6 @@ sub help_screen{
help_screen_line('--update_module', '<module_name> <agent_name> <field_to_change> <new_value>', 'Update a module field');
help_screen_line('--get_agents_module_current_data', '<module_name>', "Get the agent and current data \n\t of all the modules with a given name");
help_screen_line('--create_network_module_from_component', '<agent_name> <component_name>', "Create a new network \n\t module from a network component");
help_screen_line('--create_synthetic', "<module_name> <synthetic_type> <agent_name> <source_agent1>,<operation>,<source_module1>|<source_agent1>,<source_module1> \n\t [ <operation>,<fixed_value> | <source agent2>,<operation>,<source_module2> ]", "Create a new Synthetic module");
print "\nALERTS:\n\n" unless $param ne '';
help_screen_line('--create_template_module', '<template_name> <module_name> <agent_name>', 'Add alert template to module');
help_screen_line('--delete_template_module', '<template_name> <module_name> <agent_name>', 'Delete alert template from module');
@ -3185,90 +3184,6 @@ sub cli_get_agent_modules() {
}
}
sub cli_create_synthetic() {
my $name_module = @ARGV[2];
my $synthetic_type = @ARGV[3];
my $agent_name = @ARGV[4];
my @module_data = @ARGV[5..$#ARGV];
my $module;
my (@filterdata,@data_module);
if ($synthetic_type ne 'arithmetic' && $synthetic_type ne 'average') {
print("[ERROR] Type of syntethic module doesn't exists \n\n");
exit 1;
}
$module->{'custom_integer_1'} = 0;
$module->{'custom_integer_2'} = 0;
$module->{'prediction_module'} = 3; # Synthetic code is 3
my $id_agent = int(get_agent_id($dbh,$agent_name));
if ($id_agent > 0) {
foreach my $data (@module_data) {
my @split_data = split(',',$data);
if (@split_data[0] =~ m/(x|\/|\+|\*|\-)/ && length(@split_data[0]) == 1 ) {
if ( @split_data[0] =~ m/(\/|\+|\*|\-)/ && $synthetic_type eq 'average' ) {
print("[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n");
exit 1;
}
@data_module = ("",@split_data[0],@split_data[1]);
my $text_data = join(',',@data_module);
push (@filterdata,$text_data);
}
else {
if (scalar(@split_data) == 2) {
@data_module = (safe_output(@split_data[0]),'',safe_output(@split_data[1]));
my $text_data = join(',',@data_module);
push (@filterdata,$text_data);
}
else {
if (length(@split_data[1]) > 1 ) {
print("[ERROR] You can only use +, -, *, / or x, and you use this: @split_data[1] \n\n");
exit 1;
}
if ( @split_data[1] =~ m/(\/|\+|\*|\-)/ && $synthetic_type eq 'average' ) {
print("[ERROR] With this type: $synthetic_type only be allow use this operator: 'x' \n\n");
exit 1;
}
@data_module = (safe_output(@split_data[0]),@split_data[1],safe_output(@split_data[2]));
my $text_data = join(',',@data_module);
push (@filterdata,$text_data);
}
}
}
my $module_exists = get_agent_module_id($dbh, $name_module, $id_agent);
non_exist_check($module_exists, 'module name', $name_module);
$module->{'id_agente'} = $id_agent;
$module->{'nombre'} = safe_input($name_module);
$module->{'id_modulo'} = 5;
my $id_module = db_process_insert($dbh, 'id_agente_modulo', 'tagente_modulo', $module);
if ($id_module) {
my $result = enterprise_hook('create_synthetic_operations',
[$dbh,int($id_module), @filterdata]);
if ($result) {
print("[OK] The modules are creating ID: $id_module \n\n");
}
else {
print("[ERROR] Problems with creating data module. \n\n");
}
}
else {
print("[INFO] Problems with creating module \n\n");
}
}
else {
print( "[INFO] The agent '$agent_name' doesn't exists\n\n");
}
}
########################################################################
# Show all the modules of a policy
# Related option: --get_policy_modules