ITSM pandora_enterprise#11471

This commit is contained in:
daniel 2023-08-25 14:15:32 +02:00
parent a7baab0aba
commit ecfa71b43c
11 changed files with 266 additions and 130 deletions

View File

@ -26,6 +26,8 @@
* ============================================================================ * ============================================================================
*/ */
use PandoraFMS\ITSM\ITSM;
global $config; global $config;
check_login(); check_login();
@ -44,59 +46,9 @@ if (! check_acl($config['id_user'], $id_grupo, 'AW', $id_agente)) {
return; return;
} }
\ui_require_css_file('pandoraitsm');
\ui_require_javascript_file('ITSM');
$agent = db_get_row('tagente', 'id_agente', $id_agente, false, false);
try { try {
$columns = [ $ITSM = new ITSM();
'idIncidence', echo $ITSM->getTableIncidencesForAgent($id_agente);
'title',
'groupCompany',
'statusResolution',
'priority',
'updateDate',
'startDate',
'idCreator',
'owner',
];
$column_names = [
__('ID'),
__('Title'),
__('Group').'/'.__('Company'),
__('Status').'/'.__('Resolution'),
__('Priority'),
__('Updated'),
__('Started'),
__('Creator'),
__('Owner'),
];
ui_print_datatable(
[
'id' => 'itms_list_tickets',
'class' => 'info_table',
'style' => 'width: 99%',
'columns' => $columns,
'column_names' => $column_names,
'ajax_url' => 'operation/ITSM/itsm',
'ajax_data' => [
'method' => 'getListTickets',
'externalIdLike' => $config['metaconsole_node_id'].'-'.$agent['id_agente'],
],
'no_sortable_columns' => [
2,
3,
-1,
],
'order' => [
'field' => 'updateDate',
'direction' => 'desc',
],
]
);
} catch (Exception $e) { } catch (Exception $e) {
echo $e->getMessage(); echo $e->getMessage();
} }

View File

@ -39,6 +39,7 @@ ui_require_javascript_file('encode_decode_base64');
ui_require_css_file('agent_manager'); ui_require_css_file('agent_manager');
use PandoraFMS\Event; use PandoraFMS\Event;
use PandoraFMS\ITSM\ITSM;
check_login(); check_login();
@ -605,20 +606,6 @@ if ($id_agente) {
$agent_wizard['active'] = false; $agent_wizard['active'] = false;
} }
// Incident tab.
if ((bool) $config['ITSM_enabled'] === true) {
$incidenttab['text'] = html_print_menu_button(
[
'href' => 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=incident&id_agente='.$id_agente,
'image' => 'images/logs@svg.svg',
'title' => __('Incidents'),
],
true
);
$incidenttab['active'] = ($tab === 'incident');
}
if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') === true) { if (check_acl_one_of_groups($config['id_user'], $all_groups, 'AW') === true) {
if ($has_remote_conf !== false) { if ($has_remote_conf !== false) {
$agent_name = agents_get_name($id_agente); $agent_name = agents_get_name($id_agente);

View File

@ -800,12 +800,13 @@ $(document).ready (function () {
old_recovery_value = '<?php echo io_safe_output($config['incident_status']); ?>'; old_recovery_value = '<?php echo io_safe_output($config['incident_status']); ?>';
} }
} else if (i === 7) { } else if (i === 7) {
var text = '<?php echo $config['incident_content']; ?>';
if(!old_value) { if(!old_value) {
old_value = '<?php echo io_safe_output($config['incident_content']); ?>'; old_value = text;
} }
if(!old_recovery_value) { if(!old_recovery_value) {
old_recovery_value = '<?php echo io_safe_output($config['incident_content']); ?>'; old_recovery_value = text;
} }
} }
} }

View File

@ -1979,15 +1979,15 @@ function config_update_config()
$text_incident_content = (string) get_parameter('incident_content', $config['incident_content']); $text_incident_content = (string) get_parameter('incident_content', $config['incident_content']);
if (empty($text_incident_content) === true) { if (empty($text_incident_content) === true) {
$text_incident_content = sprintf( $text_incident_content = sprintf(
'Hello, 'Hello, %s %s A new ticket has been created due a problem in monitoring. %s %s Agent : _agent_ %s Module: _module_ %s %s Regards, %s Your %s server.',
PHP_EOL,
A new ticket has been created due a problem in monitoring. PHP_EOL,
PHP_EOL,
Agent : _agent_ PHP_EOL,
Module: _module_ PHP_EOL,
PHP_EOL,
Regards, PHP_EOL,
Your %s server.', PHP_EOL,
get_product_name() get_product_name()
); );
} }

View File

@ -257,6 +257,10 @@ class ITSM
$path = '/customSearch/'.$id; $path = '/customSearch/'.$id;
break; break;
case 'inventory':
$path = '/inventory/'.$id;
break;
default: default:
// Not posible. // Not posible.
break; break;
@ -436,4 +440,99 @@ class ITSM
} }
/**
* List incidences.
*
* @param integer $idAgent Agent id.
*
* @return array list Incidences.
*/
public function listIncidenceAgents(int $idAgent): array
{
global $config;
$listIncidences = $this->callApi(
'listTickets',
[
'page' => 0,
'sizePage' => 0,
],
['externalIdLike' => $config['metaconsole_node_id'].'-'.$idAgent]
);
return $listIncidences['data'];
}
/**
* Get table incicidences for agent.
*
* @param integer $idAgent Id agent.
* @param boolean|null $mini visual mode mini.
* @param integer|null $blocked Blocked.
*
* @return string Html output.
*/
public function getTableIncidencesForAgent(int $idAgent, ?bool $mini=false, ?int $blocked=null)
{
\ui_require_css_file('pandoraitsm');
\ui_require_javascript_file('ITSM');
global $config;
$columns = [
'idIncidence',
'title',
'groupCompany',
'statusResolution',
'priority',
'updateDate',
'startDate',
'idCreator',
'owner',
];
$column_names = [
__('ID'),
__('Title'),
__('Group').'/'.__('Company'),
__('Status').'/'.__('Resolution'),
__('Priority'),
__('Updated'),
__('Started'),
__('Creator'),
__('Owner'),
];
$options = [
'id' => 'itms_list_tickets',
'class' => 'info_table',
'style' => 'width: 99%',
'columns' => $columns,
'column_names' => $column_names,
'ajax_url' => 'operation/ITSM/itsm',
'ajax_data' => [
'method' => 'getListTickets',
'externalIdLike' => $config['metaconsole_node_id'].'-'.$idAgent,
'blocked' => $blocked,
],
'no_sortable_columns' => [
2,
3,
-1,
],
'order' => [
'field' => 'updateDate',
'direction' => 'desc',
],
'return' => true,
];
if ($mini === true) {
$options['csv'] = 0;
$options['dom_elements'] = 'frtip';
}
return ui_print_datatable($options);
}
} }

View File

@ -325,6 +325,7 @@ class Manager
$users = null; $users = null;
$priorities = null; $priorities = null;
$priorityDiv = null; $priorityDiv = null;
$inventories = null;
$ITSM = new ITSM(); $ITSM = new ITSM();
try { try {
if (empty($idIncidence) === false) { if (empty($idIncidence) === false) {
@ -390,7 +391,16 @@ class Manager
$users = $this->getUsers($ITSM, $usersInvolved); $users = $this->getUsers($ITSM, $usersInvolved);
$inventories = [];
$priorityDiv = $this->priorityDiv($incidence['priority'], $priorities[$incidence['priority']]); $priorityDiv = $this->priorityDiv($incidence['priority'], $priorities[$incidence['priority']]);
if (empty($incidence) === false
&& isset($incidence['inventories']) === true
&& empty($incidence['inventories']) === false
) {
foreach ($incidence['inventories'] as $inventory) {
$inventories[] = $this->getInventory($ITSM, $inventory['idInventory']);
}
}
} }
} catch (\Throwable $th) { } catch (\Throwable $th) {
$error = $th->getMessage(); $error = $th->getMessage();
@ -414,6 +424,7 @@ class Manager
'priorities' => $priorities, 'priorities' => $priorities,
'priorityDiv' => $priorityDiv, 'priorityDiv' => $priorityDiv,
'headerTabs' => $headerTabs, 'headerTabs' => $headerTabs,
'inventories' => $inventories,
] ]
); );
} }
@ -855,6 +866,28 @@ class Manager
} }
/**
* Get Inventory.
*
* @param ITSM $ITSM Object for callApi.
* @param integer $idInventory Inventory ID.
*
* @return array Data inventory
*/
private function getInventory(ITSM $ITSM, int $idInventory): array
{
$result = $ITSM->callApi(
'inventory',
[],
[],
$idInventory,
'GET'
);
return $result;
}
/** /**
* Get Incidences group by for groups. * Get Incidences group by for groups.
* *
@ -1113,6 +1146,11 @@ class Manager
$filters['externalIdLike'] = $externalIdLike; $filters['externalIdLike'] = $externalIdLike;
} }
$blocked = get_parameter('blocked', null);
if (isset($blocked) === true) {
$filters['blocked'] = $blocked;
}
if (isset($filters['status']) === true && empty($filters['status']) === true) { if (isset($filters['status']) === true && empty($filters['status']) === true) {
unset($filters['status']); unset($filters['status']);
} }

View File

@ -26,6 +26,8 @@
* ============================================================================ * ============================================================================
*/ */
use PandoraFMS\ITSM\ITSM;
// Begin. // Begin.
global $config; global $config;
@ -944,6 +946,46 @@ if (empty($agentAdditionalInfo) === false) {
); );
} }
if ((bool) $config['ITSM_enabled'] === true) {
$show_tab_issue = false;
try {
$ITSM = new ITSM();
$list = $ITSM->listIncidenceAgents($id_agente);
if (empty($list) === false) {
$show_tab_issue = true;
}
} catch (\Throwable $th) {
$show_tab_issue = false;
}
if ($show_tab_issue === true) {
try {
$table_itsm = $ITSM->getTableIncidencesForAgent($id_agente, true, 0);
} catch (Exception $e) {
$table_itsm = $e->getMessage();
}
$itsmInfo = ui_toggle(
$table_itsm,
'<span class="subsection_header_title">'.__('Incidences').'</span>',
'status_monitor_agent',
false,
false,
true,
'',
'white-box-content',
'box-flat white_table_graph w100p'
);
html_print_div(
[
'class' => 'agent_details_line',
'content' => $itsmInfo,
]
);
}
}
if (empty($agentIncidents) === false) { if (empty($agentIncidents) === false) {
html_print_div( html_print_div(
[ [

View File

@ -27,6 +27,7 @@
*/ */
use PandoraFMS\Enterprise\Metaconsole\Node; use PandoraFMS\Enterprise\Metaconsole\Node;
use PandoraFMS\ITSM\ITSM;
global $config; global $config;
@ -1558,16 +1559,29 @@ if ((bool) $config['activate_gis'] === true) {
// Incident tab. // Incident tab.
if ((bool) $config['ITSM_enabled'] === true) { if ((bool) $config['ITSM_enabled'] === true) {
$incidenttab['text'] = html_print_menu_button( $show_tab_issue = false;
[ try {
'href' => 'index.php?sec=gagente&amp;sec2=operation/agentes/ver_agente&tab=incident&id_agente='.$id_agente, $ITSM = new ITSM();
'image' => 'images/logs@svg.svg', $list = $ITSM->listIncidenceAgents($id_agente);
'title' => __('Incidents'), if (empty($list) === false) {
], $show_tab_issue = true;
true }
); } catch (\Throwable $th) {
$show_tab_issue = false;
}
$incidenttab['active'] = ($tab === 'incident'); if ($show_tab_issue === true) {
$incidenttab['text'] = html_print_menu_button(
[
'href' => 'index.php?sec=gagente&amp;sec2=operation/agentes/ver_agente&tab=incident&id_agente='.$id_agente,
'image' => 'images/logs@svg.svg',
'title' => __('Incidents'),
],
true
);
$incidenttab['active'] = ($tab === 'incident');
}
} }
// Url address tab. // Url address tab.

View File

@ -52,6 +52,8 @@ ui_print_standard_header(
] ]
); );
hd($inventories);
if (empty($error) === false) { if (empty($error) === false) {
ui_print_error_message($error); ui_print_error_message($error);
} }
@ -190,7 +192,7 @@ if (empty($incidence) === true) {
// Show description. // Show description.
$description_box = '<div class="ITSM_details_description">'; $description_box = '<div class="ITSM_details_description">';
$description_box .= $incidence['description']; $description_box .= str_replace("\r\n", '</br>', $incidence['description']);
$description_box .= '</div>'; $description_box .= '</div>';
ui_toggle($description_box, __('Description'), '', '', false); ui_toggle($description_box, __('Description'), '', '', false);

View File

@ -1932,7 +1932,8 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
'IP Address' => safe_output($agent->{'direccion'}), 'IP Address' => safe_output($agent->{'direccion'}),
'URL Address' => safe_output($agent->{'url_address'}), 'URL Address' => safe_output($agent->{'url_address'}),
'ID Agent' => $agent->{'id_agente'}, 'ID Agent' => $agent->{'id_agente'},
'Group' => safe_output(get_db_value($dbh, 'select nombre from tgrupo where id_grupo = ?', $agent->{'id_grupo'})) 'Group' => safe_output(get_db_value($dbh, 'select nombre from tgrupo where id_grupo = ?', $agent->{'id_grupo'})),
'OS Version' => $agent->{'os_version'}
); );
my %dataSend = ( my %dataSend = (
@ -1948,11 +1949,6 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
'createWu' => $action->{'create_wu_integria'} 'createWu' => $action->{'create_wu_integria'}
); );
# TODO: change to logger.
use Data::Dumper;
$Data::Dumper::SortKeys = 1;
print Dumper(\%dataSend);
my $response = pandora_API_ITSM_call($pa_config, 'post', $ITSM_path . '/pandorafms/alert', $ITSM_token, \%dataSend); my $response = pandora_API_ITSM_call($pa_config, 'post', $ITSM_path . '/pandorafms/alert', $ITSM_token, \%dataSend);
if (!defined($response)){ if (!defined($response)){
return; return;
@ -3878,6 +3874,32 @@ sub pandora_get_custom_field_for_itsm ($$) {
return \%result; return \%result;
} }
sub pandora_prepare_info_object_inventory_itsm ($) {
my ($dbh) = @_;
my $custom_fields = pandora_get_custom_fields($dbh);
my $sql = 'SELECT tagente.alias, tagente.id_agente AS "ID Agent", tagente.os_version AS "OS Version", tagente.direccion AS "IP Address",';
$sql .= ' tagente.url_address AS "URL Address", tgrupo.nombre AS "Group", tconfig_os.name AS "OS",';
foreach my $field (@{$custom_fields}) {
$sql .= ' case when tagent_custom_fields.name = "'. $field->{'name'} . '" then tagent_custom_data.description end AS "'. $field->{'name'} . '",';
}
$sql = substr($sql, 0, -1);
$sql .= ' FROM tagent_custom_fields';
$sql .= ' INNER JOIN tagent_custom_data ON tagent_custom_data.id_field = tagent_custom_fields.id_field';
$sql .= ' RIGHT JOIN tagente ON tagent_custom_data.id_agent = tagente.id_agente';
$sql .= ' INNER JOIN tgrupo ON tgrupo.id_grupo = tagente.id_grupo';
$sql .= ' INNER JOIN tconfig_os ON tconfig_os.id_os = tagente.id_os';
$sql .= ' GROUP BY tagente.id_agente';
$sql .= ' ORDER BY tagente.id_agente';
my @result = get_db_rows($dbh, $sql);
return \@result;
}
########################################################################## ##########################################################################
## Update a custom field from agent of tagent_custom_data ## Update a custom field from agent of tagent_custom_data
########################################################################## ##########################################################################
@ -7019,8 +7041,8 @@ sub pandora_API_ITSM_call ($$$$$) {
} }
} }
sub pandora_sync_agents_integria ($) { sub pandora_sync_agents_integria ($$) {
my ($dbh) = @_; my ($pa_config, $dbh) = @_;
my $config_ITSM_enabled = pandora_get_tconfig_token ($dbh, 'ITSM_enabled', ''); my $config_ITSM_enabled = pandora_get_tconfig_token ($dbh, 'ITSM_enabled', '');
@ -7028,44 +7050,23 @@ sub pandora_sync_agents_integria ($) {
return; return;
} }
my $config_api_path = pandora_get_tconfig_token ($dbh, 'ITSM_hostname', ''); my $ITSM_path = pandora_get_tconfig_token ($dbh, 'ITSM_hostname', '');
my $config_integria_user_pass = pandora_get_tconfig_token ($dbh, 'ITSM_token', ''); my $ITSM_token = pandora_get_tconfig_token ($dbh, 'ITSM_token', '');
my $api_path = $config_api_path;
my @agents_string = ''; my %dataAgents = (
my @agents = get_db_rows ($dbh, 'SELECT * FROM tagente'); 'agents' => pandora_prepare_info_object_inventory_itsm($dbh),
'idNode' => pandora_get_tconfig_token($dbh, 'metaconsole_node_id', 0)
my @agents_array = (); );
my $agents_string = '';
foreach my $agent (@agents) { # TODO: change to logger.
push @agents_array, $agent->{'nombre'} . #use Data::Dumper;
"|;|" . #$Data::Dumper::SortKeys = 1;
$agent->{'alias'} . #print Dumper(\%dataAgents);
"|;|" .
$agent->{'id_os'} .
"|;|" .
$agent->{'direccion'} .
"|;|" .
$agent->{'id_grupo'};
}
my $ua = LWP::UserAgent->new(); my $response = pandora_API_ITSM_call($pa_config, 'post', $ITSM_path . '/pandorafms/agents', $ITSM_token, \%dataAgents);
my $response = $ua->post( $api_path, { if (!defined($response)){
'user_pass' => $config_integria_user_pass, return;
'op' => 'sync_pandora_agents_inventory',
'params[]' => [@agents_array],
'token' => '|;|'
});
my $content = $response->decoded_content();
if (defined $content && is_numeric($content) && $content ne "-1") {
return $content;
}
else {
return 0;
} }
} }

View File

@ -1397,7 +1397,7 @@ if (defined($history_dbh)) {
} }
# Keep integrity between PandoraFMS agents and Pandora ITSM inventory objects. # Keep integrity between PandoraFMS agents and Pandora ITSM inventory objects.
pandora_sync_agents_integria($dbh); #pandora_sync_agents_integria($dbh);
# Cleanup and exit # Cleanup and exit
db_disconnect ($history_dbh) if defined ($history_dbh); db_disconnect ($history_dbh) if defined ($history_dbh);