Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Add tab in computer form to display fusion group and fusion task wher…
Browse files Browse the repository at this point in the history
…e the computer is
  • Loading branch information
David Durieux committed Nov 3, 2018
1 parent 1321cb9 commit 90dc992
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 2 deletions.
59 changes: 59 additions & 0 deletions inc/deploygroup.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,4 +621,63 @@ function cleanDBOnPurge() {
}


/**
* Display for a computer the groups where it is
*
* @param integer $computers_id
*/
function showForComputer($computers_id) {
global $DB;

echo "<table width='950' class='tab_cadre_fixe'>";

echo "<tr>";
echo "<th>";
echo __('Group');
echo "</th>";
echo "<th>";
echo __('Type');
echo "</th>";
echo "</tr>";

$link = Toolbox::getItemTypeFormURL("PluginFusioninventoryDeployGroup");

$iterator = $DB->request([
'FROM' => PluginFusioninventoryDeployGroup_Staticdata::getTable(),
'WHERE' => [
'items_id' => $computers_id,
'itemtype' => 'Computer',
],
]);
while ($data = $iterator->next()) {
$this->getFromDB($data['plugin_fusioninventory_deploygroups_id']);
echo "<tr>";
echo "<td>";
echo "<a href='".$link."?id=".$this->fields['id']."'>".$this->fields['name']."</a>";
echo "</td>";
echo "<td>";
echo __('Static group', 'fusioninventory');
echo "</td>";
echo "</tr>";
}

$iterator = $DB->request([
'FROM' => PluginFusioninventoryDeployGroup_Dynamicdata::getTable(),
'WHERE' => [
'computers_id_cache' => ["LIKE", '%"'.$computers_id.'"%'],
],
]);
while ($data = $iterator->next()) {
$this->getFromDB($data['plugin_fusioninventory_deploygroups_id']);
echo "<tr>";
echo "<td>";
echo "<a href='".$link."?id=".$this->fields['id']."'>".$this->fields['name']."</a>";
echo "</td>";
echo "<td>";
echo __('Dynamic group', 'fusioninventory');
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
}
127 changes: 126 additions & 1 deletion inc/taskjobstate.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,17 @@ class PluginFusioninventoryTaskjobstate extends CommonDBTM {
* @return string name of the tab
*/
function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
return __("Job executions", "fusioninventory");
switch ($item->getType()) {

case 'Computer':
return __("Tasks / Groups", "fusioninventory");
break;

case 'PluginFusioninventoryTask':
return __("Job executions", "fusioninventory");
break;

}
}


Expand Down Expand Up @@ -160,6 +170,12 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem
if ($item->getType() == 'PluginFusioninventoryTask') {
$item->showJobLogs();
return true;
} else if ($item->getType() == 'Computer') {
$pfTaskJobState = new PluginFusioninventoryTaskjobstate();
$pfTaskJobState->showStatesForComputer($item->getID());
echo "<br>";
$pfDeployGroup = new PluginFusioninventoryDeployGroup();
$pfDeployGroup->showForComputer($item->getID());
}
return false;
}
Expand Down Expand Up @@ -667,4 +683,113 @@ function getFromDBByUniqID($uniqid) {
}


/**
* Display the tasks where the computer is associated
*
* @param integer $computers_id
*/
function showStatesForComputer($computers_id) {
global $DB;

$pfAgent = new PluginFusioninventoryAgent();
$pfTask = new PluginFusioninventoryTask();
$pfTaskjob = new PluginFusioninventoryTaskjob();
$pfTaskjoblog = new PluginFusioninventoryTaskjoblog();

// Get the agent of the computer
$agents_id = $pfAgent->getAgentWithComputerid($computers_id);

$tasks_id = [];

// Get tasks ids
$iterator = $DB->request([
'FROM' => $this->getTable(),
'WHERE' => [
'plugin_fusioninventory_agents_id' => $agents_id,
],
'ORDER' => 'id DESC',
]);
while ($data = $iterator->next()) {
$pfTaskjob->getFromDB($data['plugin_fusioninventory_taskjobs_id']);
$pfTask->getFromDB($pfTaskjob->fields['plugin_fusioninventory_tasks_id']);
if (!isset($tasks_id[$pfTask->fields['id']])) {
$tasks_id[$pfTask->fields['id']] = [
'is_active' => $pfTask->fields['is_active'],
'jobstates' => [],
'method' => $pfTaskjob->fields['method'],
'name' => $pfTask->fields['name'],
];
}
// Limit to 5 last runs
if (count($tasks_id[$pfTask->fields['id']]['jobstates']) < 5) {
$tasks_id[$pfTask->fields['id']]['jobstates'][] = $data['id'];
}
}
echo "<table width='950' class='tab_cadre_fixe'>";

echo "<tr>";
echo "<th>";
echo __('Task');
echo "</th>";
echo "<th>";
echo __('Active');
echo "</th>";
echo "<th>";
echo __('Module method');
echo "</th>";
echo "<th>";
echo __('Date');
echo "</th>";
echo "<th>";
echo __('Status');
echo "</th>";
echo "</tr>";

$modules_methods = PluginFusioninventoryStaticmisc::getModulesMethods();
$link = Toolbox::getItemTypeFormURL("PluginFusioninventoryTask");
$stateColors = [
PluginFusioninventoryTaskjoblog::TASK_PREPARED => '#efefef',
PluginFusioninventoryTaskjoblog::TASK_RUNNING => '#aaaaff',
PluginFusioninventoryTaskjoblog::TASK_STARTED => '#aaaaff',
PluginFusioninventoryTaskjoblog::TASK_OK => '#aaffaa',
PluginFusioninventoryTaskjoblog::TASK_ERROR => '#ff0000',
];

foreach ($tasks_id as $id=>$data) {
echo "<tr class='tab_bg_1'>";
echo "<td>";
echo "<a href='".$link."?id=".$id."'>".$data['name']."</a>";
echo "</td>";
echo "<td>";
echo Dropdown::getYesNo($data['is_active']);
echo "</td>";
echo "<td>";
echo $modules_methods[$data['method']];
echo "</td>";
echo "<td colspan='2'>";
echo "</td>";
echo "</tr>";

// Each taskjobstate
foreach ($data['jobstates'] as $jobstates_id) {
$logs = $pfTaskjoblog->find("`plugin_fusioninventory_taskjobstates_id`=".$jobstates_id, "id DESC", 1);
if (count($logs) > 0) {
$log = current($logs);
echo "<tr class='tab_bg_1'>";
echo "<td colspan='3'>";
echo "</td>";
echo "</td>";
echo "<td style='background-color: ".$stateColors[$log['state']]."'>";
echo Html::convDateTime($log['date']);
echo "</td>";
echo "<td style='background-color: ".$stateColors[$log['state']]."'>";
echo $pfTaskjoblog->getStateName($log['state']);
// status
echo "</td>";
echo "</tr>";
}
}
}
echo "</table>";
}
}
3 changes: 2 additions & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ function plugin_init_fusioninventory() {
$Plugin->registerClass('PluginFusioninventoryTaskjobstate',
[
'addtabon' => [
'PluginFusioninventoryTask'
'PluginFusioninventoryTask',
'Computer',
]
]
);
Expand Down

0 comments on commit 90dc992

Please sign in to comment.