ITSM pandora_enterprise#11471

This commit is contained in:
daniel 2023-08-17 14:56:55 +02:00
parent ae77fc7b9a
commit 1fecd7d289
7 changed files with 517 additions and 120 deletions

View File

@ -1,21 +1,33 @@
<?php
/**
* ITSM.
*
* @category ITSM view
* @package Pandora FMS
* @subpackage Opensource
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2023 Pandora FMS
* Please see https://pandorafms.com/community/ for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for 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.
* ============================================================================
*/
// Pandora FMS - https://pandorafms.com
// ==================================================
// Copyright (c) 2005-2023 Pandora FMS
// Please see https://pandorafms.com/community/ for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for 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.
// Load global vars
global $config;
require_once 'include/functions_incidents.php';
check_login();
if (!$config['ITSM_enabled']) {
@ -23,9 +35,7 @@ if (!$config['ITSM_enabled']) {
return;
}
$group = $id_grupo;
if (! check_acl($config['id_user'], $group, 'AW', $id_agente)) {
if (! check_acl($config['id_user'], $id_grupo, 'AW', $id_agente)) {
db_pandora_audit(
AUDIT_LOG_ACL_VIOLATION,
'Trying to access agent manager'
@ -34,102 +44,61 @@ if (! check_acl($config['id_user'], $group, 'AW', $id_agente)) {
return;
}
$offset = (int) get_parameter('offset', 0);
\ui_require_css_file('pandoraitsm');
\ui_require_javascript_file('ITSM');
$agent = db_get_row('tagente', 'id_agente', $id_agente, false, false);
// See if id_agente is set (either POST or GET, otherwise -1
$id_agent = (int) get_parameter('id_agente');
$groups = users_get_groups($config['id_user'], 'AR');
$filter = ' AND id_agent = '.$id_agent;
$url = 'index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=incident&id_agente='.$id_agent;
try {
$columns = [
'idIncidence',
'title',
'groupCompany',
'statusResolution',
'priority',
'updateDate',
'startDate',
'idCreator',
'owner',
];
$params = [
'',
'-10',
'1',
'-1',
'0',
'',
'',
'',
agents_get_name($id_agent),
];
$column_names = [
__('ID'),
__('Title'),
__('Group').'/'.__('Company'),
__('Status').'/'.__('Resolution'),
__('Priority'),
__('Updated'),
__('Started'),
__('Creator'),
__('Owner'),
];
// $result = integria_api_call(null, null, null, null, 'get_incidents', $params, false, 'json', ',');
$result = json_decode($result, true);
if (empty($result) === true) {
$result = [];
$count = 0;
echo '<div class="nf">'.__('No incidents associated to this agent').'</div><br />';
return;
} else {
$count = count($result);
$result = array_slice($result, $offset, $config['block_size']);
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' => $agent['nombre'],
],
'no_sortable_columns' => [
2,
3,
-1,
],
'order' => [
'field' => 'updateDate',
'direction' => 'desc',
],
]
);
} catch (Exception $e) {
echo $e->getMessage();
}
// Show pagination.
ui_pagination($count, $url, $offset, 0, false, 'offset');
// ($count + $offset) it's real count of incidents because it's use LIMIT $offset in query.
echo '<br />';
// Show headers.
$table->width = '100%';
$table->class = 'databox';
$table->cellpadding = 4;
$table->cellspacing = 4;
$table->head = [];
$table->data = [];
$table->size = [];
$table->align = [];
$table->head[0] = __('ID');
$table->head[1] = __('Status');
$table->head[2] = __('Incident');
$table->head[3] = __('Priority');
$table->head[4] = __('Group');
$table->head[5] = __('Updated');
$table->size[0] = 43;
$table->size[7] = 50;
$table->align[1] = 'center';
$table->align[3] = 'center';
$table->align[4] = 'center';
$rowPair = true;
$iterator = 0;
foreach ($result as $row) {
if ($rowPair) {
$table->rowclass[$iterator] = 'rowPair';
} else {
$table->rowclass[$iterator] = 'rowOdd';
}
$rowPair = !$rowPair;
$iterator++;
$data = [];
$data[0] = '<a href="index.php?sec=incident&sec2=operation/incidents/dashboard_detail_integriaims_incident&incident_id='.$row['id_incidencia'].'">'.$row['id_incidencia'].'</a>';
// $attach = incidents_get_attach($row['id_incidencia']);
if (!empty($attach)) {
$data[0] .= '&nbsp;&nbsp;'.html_print_image('images/attachment.png', true, ['style' => 'align:middle;']);
}
// $data[1] = incidents_print_status_img($row['estado'], true);
$data[2] = '<a href="index.php?sec=incident&sec2=operation/incidents/dashboard_detail_integriaims_incident&incident_id='.$row['id_incidencia'].'">'.substr(io_safe_output($row['titulo']), 0, 45).'</a>';
// $data[3] = incidents_print_priority_img($row['prioridad'], true);
$data[4] = $row['id_grupo'];
$data[5] = ui_print_timestamp($row['actualizacion'], true);
array_push($table->data, $data);
}
html_print_table($table);
echo '</div>';
unset($table);
echo '<br><br>';
echo '<div id="both">&nbsp;</div>';
html_print_action_buttons('');

View File

@ -592,7 +592,7 @@ if (is_ajax()) {
0,
$management_is_not_allowed,
false,
''
'ITSM_users'
);
$rfield = html_print_autocomplete_users_from_pandora_itsm(
@ -602,7 +602,7 @@ if (is_ajax()) {
0,
$management_is_not_allowed || $recovery_disabled,
false,
''
'ITSM_users'
);
}
} else {

View File

@ -848,16 +848,20 @@ $(document).ready (function () {
}
else {
var is_element_select = $("[name=field" + i + "_value]").is("select");
var is_element_autocomplete_users_itsm = $("[name=field" + i + "_value]").hasClass("ITSM_users");
$("[name=field" + i + "_value]").val(old_value);
if (is_element_select === true) {
$("[name=field" + i + "_value]").trigger('change');
} else if (is_element_autocomplete_users_itsm === true) {
$("[name=field" + i + "_value_hidden]").val(old_value);
}
$("[name=field" + i + "_recovery_value]").val(old_recovery_value);
if (is_element_select === true) {
$("[name=field" + i + "_recovery_value]").trigger('change');
} else if (is_element_autocomplete_users_itsm === true) {
$("[name=field" + i + "_recovery_value_hidden]").val(old_recovery_value);
}
}
}

View File

@ -429,6 +429,7 @@ class Widget
case 'AvgSumMaxMinModule':
case 'BasicChart':
case 'AgentHive':
case 'ITSMIncidences':
$className .= '\\'.$name;
break;

View File

@ -0,0 +1,418 @@
<?php
/**
* Widget Simple graph Pandora FMS Console
*
* @category Console Class
* @package Pandora FMS
* @subpackage Widget
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2023 Pandora FMS
* Please see https://pandorafms.com/community/ for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for 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.
* ============================================================================
*/
namespace PandoraFMS\Dashboard;
use PandoraFMS\Enterprise\Metaconsole\Node;
global $config;
/**
* URL Widgets
*/
class ITSMIncidences extends Widget
{
/**
* Name widget.
*
* @var string
*/
protected $name;
/**
* Title widget.
*
* @var string
*/
protected $title;
/**
* Page widget;
*
* @var string
*/
protected $page;
/**
* Class name widget.
*
* @var [type]
*/
protected $className;
/**
* Values options for each widget.
*
* @var [type]
*/
protected $values;
/**
* Configuration required.
*
* @var boolean
*/
protected $configurationRequired;
/**
* Error load widget.
*
* @var boolean
*/
protected $loadError;
/**
* Width.
*
* @var integer
*/
protected $width;
/**
* Heigth.
*
* @var integer
*/
protected $height;
/**
* Grid Width.
*
* @var integer
*/
protected $gridWidth;
/**
* Cell ID.
*
* @var integer
*/
protected $cellId;
/**
* Construct.
*
* @param integer $cellId Cell ID.
* @param integer $dashboardId Dashboard ID.
* @param integer $widgetId Widget ID.
* @param integer|null $width New width.
* @param integer|null $height New height.
* @param integer|null $gridWidth Grid width.
*/
public function __construct(
int $cellId,
int $dashboardId=0,
int $widgetId=0,
?int $width=0,
?int $height=0,
?int $gridWidth=0
) {
global $config;
// WARNING: Do not edit. This chunk must be in the constructor.
parent::__construct(
$cellId,
$dashboardId,
$widgetId
);
// Width.
$this->width = $width;
// Height.
$this->height = $height;
// Grid Width.
$this->gridWidth = $gridWidth;
// Cell Id.
$this->cellId = $cellId;
// Options.
$this->values = $this->decoders($this->getOptionsWidget());
// Positions.
$this->position = $this->getPositionWidget();
// Page.
$this->page = basename(__FILE__);
// ClassName.
$class = new \ReflectionClass($this);
$this->className = $class->getShortName();
// Title.
$this->title = __('Pandora ITSM tickets');
// Name.
if (empty($this->name) === true) {
$this->name = 'ITSMIncidences';
}
// This forces at least a first configuration.
$this->configurationRequired = false;
if (empty($this->values['fields']) === true) {
$this->configurationRequired = true;
}
$this->overflow_scrollbars = false;
}
/**
* Decoders hack for retrocompability.
*
* @param array $decoder Values.
*
* @return array Returns the values with the correct key.
*/
public function decoders(array $decoder): array
{
$values = [];
// Retrieve global - common inputs.
$values = parent::decoders($decoder);
if (isset($decoder['show_full_legend']) === true) {
$values['showLegend'] = $decoder['show_full_legend'];
}
if (isset($decoder['fields']) === true) {
if (is_array($decoder['fields']) === true) {
$decoder['fields'] = implode(',', $decoder['fields']);
}
$values['fields'] = $decoder['fields'];
}
if (isset($decoder['limit']) === true) {
$values['limit'] = $decoder['limit'];
}
return $values;
}
/**
* Generates inputs for form (specific).
*
* @return array Of inputs.
*
* @throws Exception On error.
*/
public function getFormInputs(): array
{
global $config;
$values = $this->values;
// Retrieve global - common inputs.
$inputs = parent::getFormInputs();
// Default values.
if (isset($values['fields']) === false) {
$values['fields'] = implode(
',',
[
'idIncidence',
'title',
'priority',
'idCreator',
]
);
}
if (isset($values['limit']) === false) {
$values['limit'] = $config['block_size'];
}
$inputs[] = [
'label' => __('Limit'),
'arguments' => [
'type' => 'number',
'name' => 'limit',
'value' => $values['limit'],
'return' => true,
'max' => 100,
'min' => 0,
],
];
$fields = [
'idIncidence' => __('ID'),
'title' => __('Title'),
'groupCompany' => __('Group').'/'.__('Company'),
'statusResolution' => __('Status').'/'.__('Resolution'),
'priority' => __('Priority'),
'updateDate' => __('Updated'),
'startDate' => __('Started'),
'idCreator' => __('Creator'),
'owner' => __('Owner'),
];
$inputs[] = [
'label' => __('Fields to show'),
'arguments' => [
'type' => 'select',
'fields' => $fields,
'name' => 'fields[]',
'selected' => explode(',', $values['fields']),
'return' => true,
'multiple' => true,
'sort' => false,
],
];
return $inputs;
}
/**
* Get Post for widget.
*
* @return array
*/
public function getPost():array
{
// Retrieve global - common inputs.
$values = parent::getPost();
$values['fields'] = \get_parameter('fields', []);
$values['limit'] = \get_parameter('limit', 20);
return $values;
}
/**
* Draw widget.
*
* @return string;
*/
public function load()
{
global $config;
\ui_require_css_file('pandoraitsm', 'include/styles/', true);
$fields = [
'idIncidence' => __('ID'),
'title' => __('Title'),
'groupCompany' => __('Group').'/'.__('Company'),
'statusResolution' => __('Status').'/'.__('Resolution'),
'priority' => __('Priority'),
'updateDate' => __('Updated'),
'startDate' => __('Started'),
'idCreator' => __('Creator'),
'owner' => __('Owner'),
];
$fields_selected = explode(',', $this->values['fields']);
if (is_array($fields_selected) === false && empty($fields_selected) === true) {
$output = '';
$output .= '<div class="container-center">';
$output .= \ui_print_info_message(
__('Not found fields selected'),
'',
true
);
$output .= '</div>';
return $output;
}
$columns = $fields_selected;
$column_names = [];
foreach ($fields_selected as $field) {
$column_names[] = $fields[$field];
}
$tableId = 'ITSMIncidence_'.$this->dashboardId.'_'.$this->cellId;
try {
ui_print_datatable(
[
'id' => $tableId,
'class' => 'info_table',
'style' => 'width: 99%',
'columns' => $columns,
'column_names' => $column_names,
'ajax_url' => 'operation/ITSM/itsm',
'ajax_data' => ['method' => 'getListTickets'],
'order' => [
'field' => 'updateDate',
'direction' => 'desc',
],
'csv' => 0,
'dom_elements' => 'frtip',
'default_pagination' => $this->values['limit'],
]
);
} catch (\Exception $e) {
echo $e->getMessage();
}
}
/**
* Get description.
*
* @return string.
*/
public static function getDescription()
{
return __('Pandora ITSM tickets');
}
/**
* Get Name.
*
* @return string.
*/
public static function getName()
{
return 'ITSMIncidences';
}
/**
* Get size Modal Configuration.
*
* @return array
*/
public function getSizeModalConfiguration(): array
{
$size = [
'width' => 450,
'height' => 430,
];
return $size;
}
}

View File

@ -1095,6 +1095,11 @@ class Manager
$order = get_datatable_order(true);
$filters = get_parameter('filter', []);
$externalIdLike = get_parameter('externalIdLike', '');
if (empty($externalIdLike) === false) {
$filters['externalIdLike'] = $externalIdLike;
}
if (isset($filters['status']) === true && empty($filters['status']) === true) {
unset($filters['status']);
}

View File

@ -1882,14 +1882,14 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
# Field 3 (Ticket priority);
my $ticket_priority = $field3;
if ($ticket_priority eq '0') {
$ticket_priority = 1;
if ($ticket_priority eq '') {
$ticket_priority = 'MEDIUM';
}
# Field 4 (Ticket owner)
my $ticket_owner = $field4;
if ($ticket_owner eq '') {
$ticket_owner = 'admin';
$ticket_owner = undef;
}
# Field 5 (Ticket type)
@ -1901,7 +1901,7 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
# Field 6 (Ticket status)
my $ticket_status = $field6;
if ($ticket_status eq '') {
$ticket_status = 'new';
$ticket_status = 'NEW';
}
# Field 7 (Ticket description);
@ -1974,7 +1974,7 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
my $id_inventory = 0;
my $inventory_data = p_decode_json($pa_config, $existInventory);
my %data_inventory = (
"name" => $agent->{'alias'},
"name" => safe_output($agent->{'alias'}),
"isPublic" => \0,
"idObjectType" => 2,
"isShowInList" => \0,
@ -1983,7 +1983,7 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
"typeFieldData" => [
{
"idInventoryField" => 12,
"data" => $agent->{'id_os'}
"data" => safe_output(get_db_value($dbh, 'select name from tconfig_os where id_os = ?', $agent->{'id_os'})) . ' (' . $agent->{'id_os'} . ')'
},
{
"idInventoryField" => 13,
@ -1995,7 +1995,7 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
},
{
"idInventoryField" => 46,
"data" => $agent->{'id_grupo'}
"data" => safe_output(get_db_value($dbh, 'select nombre from tgrupo where id_grupo = ?', $agent->{'id_grupo'}) . ' (' . $agent->{'id_grupo'} . ')')
},
]
);