Merge branch 'ent-2561-llamadas-api-para-modulos-de-politicas' into 'develop'

minor changes

See merge request artica/pandorafms!3779
This commit is contained in:
Daniel Rodriguez 2021-03-25 09:57:53 +00:00
commit 1d374fca46
4 changed files with 55 additions and 110 deletions

View File

@ -149,7 +149,7 @@ function agents_locate_agent(string $field)
*
* @param string $alias Agent alias.
*
* @return integer Id from the agent.
* @return array|boolean Agents ids or false if error.
*/
function agents_get_agent_id_by_alias($alias)
{

View File

@ -6992,114 +6992,6 @@ function api_set_planned_downtimes_additem($id, $thrash1, $other, $thrash3)
}
/**
* Add data module to policy. And return id from new module.
*
* @param string $id Id of the target policy.
* @param $thrash1 Don't use.
* @param array $other it's array, $other as param is <module_name>;<id_module_type>;<description>;
* <id_module_group>;<min>;<max>;<post_process>;<module_interval>;<min_warning>;<max_warning>;<str_warning>;
* <min_critical>;<max_critical>;<str_critical>;<history_data>;<configuration_data>;
* <disabled_types_event>;<module_macros>;<ff_threshold>;<each_ff>;<ff_threshold_normal>;
* <ff_threshold_warning>;<ff_threshold_critical>;<ff_timeout> in this order
* and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_<separator>)
* example:
*
* example:
*
* api.php?op=set&op2=add_data_module_policy&id=1&other=data_module_policy_example_name~2~data%20module%20created%20by%20Api~2~0~0~50.00~10~20~180~~21~35~~1~module_begin%0dmodule_name%20pandora_process%0dmodule_type%20generic_data%0dmodule_exec%20ps%20aux%20|%20grep%20pandora%20|%20wc%20-l%0dmodule_end&other_mode=url_encode_separator_~
*
* @param $thrash3 Don't use
*/
function api_set_add_data_module_policy($id, $thrash1, $other, $thrash3)
{
if (defined('METACONSOLE')) {
return;
}
if ($id == '') {
returnError('The data module could not be added to policy. Id_policy cannot be left blank.');
return;
}
if (enterprise_hook('policies_check_user_policy', [$id]) === false) {
returnError('forbidden', 'string');
return;
}
if ($other['data'][0] == '') {
returnError('The data module could not be added to policy. Module_name cannot be left blank.');
return;
}
// Check if the module is already in the policy
$name_module_policy = enterprise_hook('policies_get_modules', [$id, ['name' => $other['data'][0]], 'name']);
if ($name_module_policy === ENTERPRISE_NOT_HOOK) {
returnError('The data module could not be added to policy.');
return;
}
$disabled_types_event = [];
$disabled_types_event[EVENTS_GOING_UNKNOWN] = (int) !$other['data'][16];
$disabled_types_event = json_encode($disabled_types_event);
$values = [];
$values['id_tipo_modulo'] = $other['data'][1];
$values['description'] = $other['data'][2];
$values['id_module_group'] = $other['data'][3];
$values['min'] = $other['data'][4];
$values['max'] = $other['data'][5];
$values['post_process'] = $other['data'][6];
$values['module_interval'] = $other['data'][7];
$values['min_warning'] = $other['data'][8];
$values['max_warning'] = $other['data'][9];
$values['str_warning'] = $other['data'][10];
$values['min_critical'] = $other['data'][11];
$values['max_critical'] = $other['data'][12];
$values['str_critical'] = $other['data'][13];
$values['history_data'] = $other['data'][14];
$values['configuration_data'] = $other['data'][15];
$values['disabled_types_event'] = $disabled_types_event;
$values['module_macros'] = $other['data'][17];
$values['min_ff_event'] = $other['data'][18];
$values['each_ff'] = $other['data'][19];
$values['min_ff_event_normal'] = $other['data'][20];
$values['min_ff_event_warning'] = $other['data'][21];
$values['min_ff_event_critical'] = $other['data'][22];
$values['ff_timeout'] = $other['data'][23];
$values['ff_type'] = $other['data'][24];
if ($name_module_policy !== false) {
if ($name_module_policy[0]['name'] == $other['data'][0]) {
returnError(
'The data module could not be added to policy. The module is already in the policy.'
);
return;
}
}
$success = enterprise_hook(
'policies_create_module',
[
$other['data'][0],
$id,
1,
$values,
false,
]
);
if ($success) {
// returnData('string', array('type' => 'string', 'data' => __('Data module added to policy. Is necessary to apply the policy in order to changes take effect.')));
returnData('string', ['type' => 'string', 'data' => $success]);
} else {
returnError('The data module could not be added to policy.');
}
}
/**
* Update data module in policy. And return id from new module.
*

View File

@ -163,7 +163,10 @@ abstract class Entity
{
// Prioritize written methods over dynamic ones.
if (method_exists($this, $methodName) === true) {
return $this->{$methodName}($params);
return call_user_func_array(
$this->{$methodName},
$params
);
}
// Enterprise capabilities.

View File

@ -91,4 +91,54 @@ class ModuleType extends Entity
}
/**
* Validate id_module and id_module_type pair.
*
* @param integer $id_module_type Id module_type.
* @param integer $id_modulo Id modulo.
*
* @return boolean True success, false if not.
*/
public static function validate(int $id_module_type, int $id_modulo)
{
switch ($id_modulo) {
case MODULE_PLUGIN:
case MODULE_PREDICTION:
case MODULE_DATA:
case MODULE_WMI:
if (($id_module_type < 6 || $id_module_type > 18) === false
&& ($id_module_type < 29 || $id_module_type > 34) === false
&& ($id_module_type === 25)
) {
return false;
}
break;
case MODULE_NETWORK:
case MODULE_SNMP:
if ($id_module_type < 6 || $id_module_type > 18) {
return false;
}
break;
case MODULE_WEB:
if ($id_module_type !== 25) {
return false;
}
break;
case MODULE_WUX:
if ($id_module_type < 29 || $id_module_type > 34) {
return false;
}
break;
default:
return false;
}
return true;
}
}