Added timeoout option to command event responses

This commit is contained in:
Luis 2019-12-10 11:54:30 +01:00 committed by vgilc
parent 325eff607e
commit 6ba4a26564
8 changed files with 38 additions and 6 deletions

View File

@ -0,0 +1,5 @@
START TRANSACTION;
ALTER TABLE `tevent_response` ADD COLUMN `command_timeout` int(5) unsigned NOT NULL DEFAULT 90;
COMMIT;

View File

@ -1776,6 +1776,7 @@ ALTER TABLE tserver ADD COLUMN exec_proxy tinyint(1) UNSIGNED NOT NULL default 0
-- Table `tevent_response`
-- ---------------------------------------------------------------------
ALTER TABLE tevent_response ADD COLUMN server_to_exec int(10) unsigned NOT NULL DEFAULT 0;
ALTER TABLE tevent_response ADD COLUMN command_timeout int(5) unsigned NOT NULL DEFAULT 90;
-- ---------------------------------------------------------------------
-- Table `tmodule`

View File

@ -52,6 +52,7 @@ if ($event_response_id > 0) {
$event_response['modal_height'] = 0;
$event_response['params'] = '';
$event_response['server_to_exec'] = '';
$event_response['command_timeout'] = 90;
}
$table = new stdClass();
@ -175,6 +176,11 @@ $data[3] = '<div id="server_to_exec_value" style="display:none;">'.html_print_se
$table->data[4] = $data;
$data = [];
$data[0] = '<div id="command_timeout_label" style="display:none;" class="labels">'.__('Command timeout (s)');
$data[1] = '<div id="command_timeout_value" style="display:none;">'.html_print_input_text('command_timeout', $event_response['command_timeout'], '', 4, 5, true);
$table->data[5] = $data;
if ($event_response_id == 0) {
echo '<form method="post" action="index.php?sec=geventos&sec2=godmode/events/events&section=responses&mode=list&action=create_response&amp;pure='.$config['pure'].'">';
html_print_table($table);
@ -214,11 +220,17 @@ $('#type').change(function() {
$('#new_window').attr('disabled','disabled');
$('#server_to_exec_label').css('display','');
$('#server_to_exec_value').css('display','');
$('#command_timeout_label').css('display','');
$('#command_timeout_value').css('display','');
break;
case 'url':
$('#new_window').removeAttr('disabled');
$('#server_to_exec_label').css('display','none');
$('#server_to_exec_value').css('display','none');
$('#command_timeout_label').css('display','none');
$('#command_timeout_value').css('display','none');
break;
}
});

View File

@ -42,6 +42,7 @@ switch ($action) {
$values['new_window'] = get_parameter('new_window');
$values['params'] = get_parameter('params');
$values['server_to_exec'] = get_parameter('server_to_exec');
$values['command_timeout'] = get_parameter('command_timeout', 90);
$result = event_responses_create_response($values);
@ -65,6 +66,8 @@ switch ($action) {
$values['params'] = get_parameter('params');
$values['server_to_exec'] = get_parameter('server_to_exec');
$response_id = get_parameter('id_response', 0);
$values['command_timeout'] = get_parameter('command_timeout', '90');
$result = event_responses_update_response($response_id, $values);

View File

@ -921,6 +921,8 @@ if ($perform_event_response) {
$event_response = db_get_row('tevent_response', 'id', $response_id);
$command_timeout = $event_response['command_timeout'];
if (enterprise_installed()) {
if ($event_response['server_to_exec'] != 0 && $event_response['type'] == 'command') {
$commandExclusions = [
@ -952,7 +954,7 @@ if ($perform_event_response) {
break;
}
system('ssh pandora_exec_proxy@'.$server_data['ip_address'].' "'.$timeout_bin.' 90 '.io_safe_output($command).' 2>&1"', $ret_val);
system('ssh pandora_exec_proxy@'.$server_data['ip_address'].' "'.$timeout_bin.' '.$command_timeout.' '.io_safe_output($command).' 2>&1"', $ret_val);
}
} else {
switch (PHP_OS) {
@ -969,7 +971,7 @@ if ($perform_event_response) {
break;
}
system($timeout_bin.' 90 '.io_safe_output($command).' 2>&1');
system($timeout_bin.' '.$command_timeout.' '.io_safe_output($command).' 2>&1', $ret_val);
}
} else {
switch (PHP_OS) {
@ -986,7 +988,13 @@ if ($perform_event_response) {
break;
}
system($timeout_bin.' 90 '.io_safe_output($command).' 2>&1');
system($timeout_bin.' '.$command_timeout.' '.io_safe_output($command).' 2>&1', $ret_val);
}
if ($ret_val != 0) {
echo "<div style='text-align:left'>";
echo __('Error executing response');
echo '</div><br>';
}
return;

View File

@ -14426,7 +14426,7 @@ function api_set_delete_event_response($id_response, $trash1, $trash2, $returnTy
* @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
* api.php?op=set&op2=create_event_response&other=response%7Cdescription%20response%7Ctouch%7Ccommand%7C0%7C650%7C400%7C0%7Cresponse%7C0%7C90&other_mode=url_encode_separator_%7C&apipass=1234&user=admin&pass=pandora
*/
function api_set_create_event_response($trash1, $trash2, $other, $returnType)
{
@ -14449,6 +14449,7 @@ function api_set_create_event_response($trash1, $trash2, $other, $returnType)
$values['new_window'] = $other['data'][7];
$values['params'] = $other['data'][8];
$values['server_to_exec'] = $other['data'][9];
$values['command_timeout'] = $other['data'][10];
// Error if user has not permission for the group.
if (!check_acl($config['id_user'], $values['id_group'], 'PM')) {
@ -14468,7 +14469,7 @@ function api_set_create_event_response($trash1, $trash2, $other, $returnType)
* @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
* api.php?op=set&op2=update_event_response&id=7&other=response%7Cdescription%20response%7Ctouch%7Ccommand%7C0%7C650%7C400%7C0%7Cresponse%7C0%7C90&other_mode=url_encode_separator_%7C&apipass=1234&user=admin&pass=pandora
*/
function api_set_update_event_response($id_response, $trash1, $other, $returnType)
{
@ -14504,6 +14505,7 @@ function api_set_update_event_response($id_response, $trash1, $other, $returnTyp
$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];
$values['command_timeout'] = $other['data'][10] == '' ? $event_response['command_timeout'] : $other['data'][10];
// Error if user has not permission for the group.
if (!check_acl($config['id_user'], $values['id_group'], 'PM')) {

View File

@ -2069,6 +2069,7 @@ CREATE TABLE IF NOT EXISTS `tevent_response` (
`new_window` TINYINT(4) NOT NULL DEFAULT 0,
`params` TEXT NOT NULL,
`server_to_exec` int(10) unsigned NOT NULL DEFAULT 0,
`command_timeout` int(5) unsigned NOT NULL DEFAULT 90,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -1184,7 +1184,7 @@ INSERT INTO `tagent_custom_fields` VALUES (1,'Serial&#x20;Number',0,0,''),(2,'De
INSERT INTO `ttag` VALUES (1,'network','Network&#x20;equipment','http://artica.es','',''),(2,'critical','Critical&#x20;modules','','',''),(3,'dmz','DMZ&#x20;Network&#x20;Zone','','',''),(4,'performance','Performance&#x20;anda&#x20;capacity&#x20;modules','','',''),(5,'configuration','','','','');
INSERT INTO `tevent_response` VALUES (1,'Ping&#x20;to&#x20;host','Ping&#x20;to&#x20;the&#x20;agent&#x20;host','ping&#x20;-c&#x20;5&#x20;_agent_address_','command',0,620,500,0,'',0),(3,'Create&#x20;incident&#x20;from&#x20;event','Create&#x20;a&#x20;incident&#x20;from&#x20;the&#x20;event&#x20;with&#x20;the&#x20;standard&#x20;incidents&#x20;system&#x20;of&#x20;Pandora&#x20;FMS','index.php?sec=workspace&amp;sec2=operation/incidents/incident_detail&amp;insert_form&amp;from_event=_event_id_','url',0,0,0,1,'',0),(5,'Restart&#x20;agent','Restart&#x20;the&#x20;agent&#x20;with&#x20;using&#x20;UDP&#x20;protocol.&#x0d;&#x0a;&#x0d;&#x0a;To&#x20;use&#x20;this&#x20;response&#x20;is&#x20;necessary&#x20;to&#x20;have&#x20;installed&#x20;Pandora&#x20;FMS&#x20;server&#x20;and&#x20;console&#x20;in&#x20;the&#x20;same&#x20;machine.','/usr/share/pandora_server/util/udp_client.pl&#x20;_agent_address_&#x20;41122&#x20;&quot;REFRESH&#x20;AGENT&quot;','command',0,620,500,0,'',0),(6,'Ping&#x20;to&#x20;module&#x20;agent&#x20;host','Ping&#x20;to&#x20;the&#x20;module&#x20;agent&#x20;host','ping&#x20;-c&#x20;5&#x20;_module_address_','command',0,620,500,0,'',0);
INSERT INTO `tevent_response` VALUES (1,'Ping&#x20;to&#x20;host','Ping&#x20;to&#x20;the&#x20;agent&#x20;host','ping&#x20;-c&#x20;5&#x20;_agent_address_','command',0,620,500,0,'',0,90),(3,'Create&#x20;incident&#x20;from&#x20;event','Create&#x20;a&#x20;incident&#x20;from&#x20;the&#x20;event&#x20;with&#x20;the&#x20;standard&#x20;incidents&#x20;system&#x20;of&#x20;Pandora&#x20;FMS','index.php?sec=workspace&amp;sec2=operation/incidents/incident_detail&amp;insert_form&amp;from_event=_event_id_','url',0,0,0,1,'',0,90),(5,'Restart&#x20;agent','Restart&#x20;the&#x20;agent&#x20;with&#x20;using&#x20;UDP&#x20;protocol.&#x0d;&#x0a;&#x0d;&#x0a;To&#x20;use&#x20;this&#x20;response&#x20;is&#x20;necessary&#x20;to&#x20;have&#x20;installed&#x20;Pandora&#x20;FMS&#x20;server&#x20;and&#x20;console&#x20;in&#x20;the&#x20;same&#x20;machine.','/usr/share/pandora_server/util/udp_client.pl&#x20;_agent_address_&#x20;41122&#x20;&quot;REFRESH&#x20;AGENT&quot;','command',0,620,500,0,'',0,90),(6,'Ping&#x20;to&#x20;module&#x20;agent&#x20;host','Ping&#x20;to&#x20;the&#x20;module&#x20;agent&#x20;host','ping&#x20;-c&#x20;5&#x20;_module_address_','command',0,620,500,0,'',0,90);
INSERT INTO `tupdate_settings` VALUES ('current_update', '412'), ('customer_key', 'PANDORA-FREE'), ('updating_binary_path', 'Path where the updated binary files will be stored'), ('updating_code_path', 'Path where the updated code is stored'), ('dbname', ''), ('dbhost', ''), ('dbpass', ''), ('dbuser', ''), ('dbport', ''), ('proxy', ''), ('proxy_port', ''), ('proxy_user', ''), ('proxy_pass', '');