Merge branch 'ent-2520-api-listar-y-crear-repuestas-de-eventos-6165-eucomm' into 'develop'
Ent 2520 api listar y crear repuestas de eventos 6165 eucomm See merge request artica/pandorafms!1896
This commit is contained in:
commit
b8b43b33d7
|
@ -16,6 +16,8 @@
|
|||
|
||||
global $config;
|
||||
|
||||
include_once($config['homedir'] . "/include/functions_event_responses.php");
|
||||
|
||||
check_login ();
|
||||
|
||||
if (! check_acl($config['id_user'], 0, "PM")) {
|
||||
|
@ -25,14 +27,7 @@ if (! check_acl($config['id_user'], 0, "PM")) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!is_user_admin($config['id_user'])) {
|
||||
$id_groups = array_keys(users_get_groups(false, "PM"));
|
||||
$event_responses = db_get_all_rows_filter('tevent_response',
|
||||
array('id_group' => $id_groups));
|
||||
}
|
||||
else {
|
||||
$event_responses = db_get_all_rows_in_table('tevent_response');
|
||||
}
|
||||
$event_responses = event_responses_get_responses();
|
||||
|
||||
if(empty($event_responses)) {
|
||||
ui_print_info_message ( array('no_close'=>true, 'message'=> __('No responses found') ) );
|
||||
|
|
|
@ -40,24 +40,9 @@ switch($action) {
|
|||
$values['modal_height'] = get_parameter('modal_height');
|
||||
$values['new_window'] = get_parameter('new_window');
|
||||
$values['params'] = get_parameter('params');
|
||||
if (enterprise_installed()) {
|
||||
if ($values['type'] == 'command') {
|
||||
$values['server_to_exec'] = get_parameter('server_to_exec');
|
||||
}
|
||||
else {
|
||||
$values['server_to_exec'] = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$values['server_to_exec'] = 0;
|
||||
}
|
||||
|
||||
if($values['new_window'] == 1) {
|
||||
$values['modal_width'] = 0;
|
||||
$values['modal_height'] = 0;
|
||||
}
|
||||
|
||||
$result = db_process_sql_insert('tevent_response', $values);
|
||||
$values['server_to_exec'] = get_parameter('server_to_exec');
|
||||
|
||||
$result = event_responses_create_response($values);
|
||||
|
||||
if($result) {
|
||||
ui_print_success_message(__('Response added succesfully'));
|
||||
|
@ -78,26 +63,10 @@ switch($action) {
|
|||
$values['modal_height'] = get_parameter('modal_height');
|
||||
$values['new_window'] = get_parameter('new_window');
|
||||
$values['params'] = get_parameter('params');
|
||||
if (enterprise_installed()) {
|
||||
if ($values['type'] == 'command') {
|
||||
$values['server_to_exec'] = get_parameter('server_to_exec');
|
||||
}
|
||||
else {
|
||||
$values['server_to_exec'] = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$values['server_to_exec'] = 0;
|
||||
}
|
||||
|
||||
if($values['new_window'] == 1) {
|
||||
$values['modal_width'] = 0;
|
||||
$values['modal_height'] = 0;
|
||||
}
|
||||
|
||||
$values['server_to_exec'] = get_parameter('server_to_exec');
|
||||
$response_id = get_parameter('id_response',0);
|
||||
|
||||
$result = db_process_sql_update('tevent_response', $values, array('id' => $response_id));
|
||||
|
||||
$result = event_responses_update_response($response_id, $values);
|
||||
|
||||
if($result) {
|
||||
ui_print_success_message(__('Response updated succesfully'));
|
||||
|
|
|
@ -30,6 +30,8 @@ include_once($config['homedir'] . "/include/functions_network_components.php");
|
|||
include_once($config['homedir'] . "/include/functions_netflow.php");
|
||||
include_once($config['homedir'] . "/include/functions_servers.php");
|
||||
include_once($config['homedir'] . "/include/functions_planned_downtimes.php");
|
||||
include_once($config['homedir'] . "/include/functions_db.php");
|
||||
include_once($config['homedir'] . "/include/functions_event_responses.php");
|
||||
enterprise_include_once ('include/functions_local_components.php');
|
||||
enterprise_include_once ('include/functions_events.php');
|
||||
enterprise_include_once ('include/functions_agents.php');
|
||||
|
@ -11468,6 +11470,159 @@ function api_get_modules_id_name_by_cluster_name ($cluster_name){
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $trash1
|
||||
* @param $trash2
|
||||
* @param mixed $trash3
|
||||
* @param $returnType
|
||||
* Example:
|
||||
* api.php?op=get&op2=event_responses&return_type=csv&apipass=1234&user=admin&pass=pandora
|
||||
*/
|
||||
function api_get_event_responses($trash1, $trash2, $trash3, $returnType) {
|
||||
global $config;
|
||||
|
||||
// Error if user cannot read event responses.
|
||||
if (!check_acl($config['id_user'], 0, "PM")) {
|
||||
returnError('forbidden', $returnType);
|
||||
return;
|
||||
}
|
||||
|
||||
$responses = event_responses_get_responses();
|
||||
if (empty($responses)) {
|
||||
returnError('no_data_to_show', $returnType);
|
||||
return;
|
||||
}
|
||||
|
||||
returnData ($returnType, array('type' => 'array', 'data' => $responses));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id_response
|
||||
* @param $trash2
|
||||
* @param mixed $trash3
|
||||
* @param $returnType
|
||||
* Example:
|
||||
* api.php?op=set&op2=delete_event_response&id=7&apipass=1234&user=admin&pass=pandora
|
||||
*/
|
||||
function api_set_delete_event_response($id_response, $trash1, $trash2, $returnType) {
|
||||
global $config;
|
||||
|
||||
// Error if user cannot read event responses.
|
||||
if (!check_acl($config['id_user'], 0, "PM")) {
|
||||
returnError('forbidden', $returnType);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if id exists
|
||||
$event_group = db_get_value('id_group', 'tevent_response','id', $id_response);
|
||||
if ($event_group === false) {
|
||||
returnError('id_not_found', $returnType);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check user if can edit the module
|
||||
if (!check_acl($config['id_user'], $event_group, "PM")) {
|
||||
returnError('forbidden', $returnType);
|
||||
return;
|
||||
}
|
||||
|
||||
$result = db_process_sql_delete('tevent_response', array('id' => $id_response));
|
||||
returnData ($returnType, array('type' => 'string', 'data' => $result));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $trash1
|
||||
* @param $trash2
|
||||
* @param mixed $other. Serialized params
|
||||
* @param $returnType
|
||||
* Example:
|
||||
* api.php?op=set&op2=create_event_response&other=response%7Cdescription%20response%7Ctouch%7Ccommand%7C0%7C650%7C400%7C0%7Cresponse%7C0&other_mode=url_encode_separator_%7C&apipass=1234&user=admin&pass=pandora
|
||||
*/
|
||||
function api_set_create_event_response($trash1, $trash2, $other, $returnType) {
|
||||
global $config;
|
||||
|
||||
// Error if user cannot read event responses.
|
||||
if (!check_acl($config['id_user'], 0, "PM")) {
|
||||
returnError('forbidden', $returnType);
|
||||
return;
|
||||
}
|
||||
|
||||
$values = array();
|
||||
$values['name'] = $other['data'][0];
|
||||
$values['description'] = $other['data'][1];
|
||||
$values['target'] = $other['data'][2];
|
||||
$values['type'] = $other['data'][3];
|
||||
$values['id_group'] = $other['data'][4];
|
||||
$values['modal_width'] = $other['data'][5];
|
||||
$values['modal_height'] = $other['data'][6];
|
||||
$values['new_window'] = $other['data'][7];
|
||||
$values['params'] = $other['data'][8];
|
||||
$values['server_to_exec'] = $other['data'][9];
|
||||
|
||||
// Error if user has not permission for the group.
|
||||
if (!check_acl($config['id_user'], $values['id_group'], "PM")) {
|
||||
returnError('forbidden', $returnType);
|
||||
return;
|
||||
}
|
||||
|
||||
$return = event_responses_create_response($values) ? 1 : 0;
|
||||
|
||||
returnData ($returnType, array('type' => 'string', 'data' => $return));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id_response
|
||||
* @param $trash2
|
||||
* @param mixed $other. Serialized params
|
||||
* @param $returnType
|
||||
* Example:
|
||||
* api.php?op=set&op2=update_event_response&id=7&other=response%7Cdescription%20response%7Ctouch%7Ccommand%7C0%7C650%7C400%7C0%7Cresponse%7C0&other_mode=url_encode_separator_%7C&apipass=1234&user=admin&pass=pandora
|
||||
*/
|
||||
function api_set_update_event_response($id_response, $trash1, $other, $returnType) {
|
||||
global $config;
|
||||
|
||||
// Error if user cannot read event responses.
|
||||
if (!check_acl($config['id_user'], 0, "PM")) {
|
||||
returnError('forbidden', $returnType);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if id exists
|
||||
$event_response = db_get_row('tevent_response','id', $id_response);
|
||||
if ($event_response === false) {
|
||||
returnError('id_not_found', $returnType);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check user if can edit the module
|
||||
if (!check_acl($config['id_user'], $event_response['id_group'], "PM")) {
|
||||
returnError('forbidden', $returnType);
|
||||
return;
|
||||
}
|
||||
|
||||
$values = array();
|
||||
$values['name'] = $other['data'][0] == '' ? $event_response['name'] : $other['data'][0];
|
||||
$values['description'] = $other['data'][1] == '' ? $event_response['description'] : $other['data'][1];
|
||||
$values['target'] = $other['data'][2] == '' ? $event_response['target'] : $other['data'][2];
|
||||
$values['type'] = $other['data'][3] == '' ? $event_response['type'] : $other['data'][3];
|
||||
$values['id_group'] = $other['data'][4] == '' ? $event_response['id_group'] : $other['data'][4];
|
||||
$values['modal_width'] = $other['data'][5] == '' ? $event_response['modal_width'] : $other['data'][5];
|
||||
$values['modal_height'] = $other['data'][6] == '' ? $event_response['modal_height'] : $other['data'][6];
|
||||
$values['new_window'] = $other['data'][7] == '' ? $event_response['new_window'] : $other['data'][7];
|
||||
$values['params'] = $other['data'][8] == '' ? $event_response['params'] : $other['data'][8];
|
||||
$values['server_to_exec'] = $other['data'][9] == '' ? $event_response['server_to_exec'] : $other['data'][9];
|
||||
|
||||
// Error if user has not permission for the group.
|
||||
if (!check_acl($config['id_user'], $values['id_group'], "PM")) {
|
||||
returnError('forbidden', $returnType);
|
||||
return;
|
||||
}
|
||||
|
||||
$return = event_responses_update_response($id_response, $values) ? 1 : 0;
|
||||
|
||||
returnData ($returnType, array('type' => 'string', 'data' => $return));
|
||||
}
|
||||
|
||||
function api_get_cluster_items ($cluster_id){
|
||||
global $config;
|
||||
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2018 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public License
|
||||
// as published by the Free Software Foundation; version 2
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
/**
|
||||
* @package Include
|
||||
* @subpackage Event Responses
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get all event responses with all values that user can access
|
||||
*
|
||||
* @return array With all table values
|
||||
*/
|
||||
function event_responses_get_responses() {
|
||||
global $config;
|
||||
$filter = array();
|
||||
|
||||
// Apply a filter if user cannot see all groups
|
||||
if (!users_can_manage_group_all()) {
|
||||
$id_groups = array_keys(users_get_groups(false, "PM"));
|
||||
$filter = array('id_group' => $id_groups);
|
||||
}
|
||||
return db_get_all_rows_filter('tevent_response', $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the responses data to store in database
|
||||
*
|
||||
* @param array (by reference) Array with values to validate and modify
|
||||
*/
|
||||
function event_responses_validate_data (&$values) {
|
||||
if ($values['type'] != "command" || !enterprise_installed()) {
|
||||
$values['server_to_exec'] = 0;
|
||||
}
|
||||
if ($values['new_window'] == 1) {
|
||||
$values['modal_width'] = 0;
|
||||
$values['modal_height'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an event response
|
||||
*
|
||||
* @param array With all event response data
|
||||
*
|
||||
* @return True if successful insertion
|
||||
*/
|
||||
function event_responses_create_response($values) {
|
||||
event_responses_validate_data($values);
|
||||
return db_process_sql_insert('tevent_response', $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an event response
|
||||
*
|
||||
* @param array With all event response data
|
||||
*
|
||||
* @return True if successful insertion
|
||||
*/
|
||||
function event_responses_update_response($response_id, $values) {
|
||||
event_responses_validate_data($values);
|
||||
return db_process_sql_update(
|
||||
'tevent_response', $values, array('id' => $response_id)
|
||||
);
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue