diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index f4e5afa138..69cc8b1d51 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,8 @@ +2013-08-01 Hirofumi Kosaka + + * include/functions_api.php: Added new API function + 'api_set_enable_disable_agent'. + 2013-08-01 Miguel de Dios * operation/events/events_list.php, extensions/agents_modules.php: diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index dc3ec05786..987ecad9b0 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -6046,4 +6046,61 @@ function api_get_pandora_servers($trash1, $trash2, $other, $returnType) { returnData($returnType, $data, $separator); return; } + +/** + * Enable/disable agent given an id + * + * @param string $id String Agent ID + * @param $thrash2 not used. + * @param array $other it's array, $other as param is in this order and separator char + * (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_) + * example: + * + * example 1 (Enable agent 'example_id') + * + * api.php?op=set&op2=enable_disable_agent&id=example_id&other=0&other_mode=url_encode_separator_| + * + * example 2 (Disable agent 'example_id') + * + * api.php?op=set&op2=enable_disable_agent&id=example_id16&other=1&other_mode=url_encode_separator_| + * + * @param $thrash3 Don't use. + */ + +function api_set_enable_disable_agent ($id, $thrash2, $other, $thrash3) { + + if ($id == ""){ + returnError('error_enable_disable_agent', 'Error enable/disable agent. Id_agent cannot be left blank.'); + return; + } + + + if ($other['data'][0] != "0" and $other['data'][0] != "1"){ + returnError('error_enable_disable_agent', 'Error enable/disable agent. Enable/disable value cannot be left blank.'); + return; + } + + if (agents_get_name($id) == false){ + returnError('error_enable_disable_agent', 'Error enable/disable agent. The agent doesn\'t exists.'); + return; + } + + $disabled = ( $other['data'][0] ? 0 : 1 ); + + $result = db_process_sql_update('tagente', array('disabled' => $disabled), array('id_agente' => $id)); + + if (is_error($result)) { + // TODO: Improve the error returning more info + returnError('error_enable_disable_agent', __('Error in agent enabling/disabling.')); + } + else { + if ($disabled == 0){ + returnData('string', array('type' => 'string', 'data' => __('Enabled agent.'))); + } + else { + returnData('string', array('type' => 'string', 'data' => __('Disabled agent.'))); + } + } +} + ?>