Skip to content

Commit

Permalink
Merge pull request #1017 from bareos/dev/fbergkemper/master/timeline
Browse files Browse the repository at this point in the history
webui: introduce a job timeline chart
  • Loading branch information
pstorz committed Dec 16, 2021
2 parents 238efd8 + 135896a commit 0fa6bdc
Show file tree
Hide file tree
Showing 48 changed files with 33,873 additions and 5 deletions.
1 change: 1 addition & 0 deletions .bareos-check-sources-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ devtools/pip-tools/check_sources.egg-info/*
webui/vendor
webui/module/Application/language
webui/public/js/*.min.*
webui/public/js/apexcharts.js
webui/public/js/partials/*.min.*
webui/public/js/bootstrap-select.js.map
webui/public/css/*.min.*
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ and since Bareos version 20 this project adheres to [Semantic Versioning](https:
- packages: Build EL_8 packages instead of CentOS_8 for RHEL 8 derivates (Alma, Rocky, CentOS Stream)[PR #992]
- webui: provide a notification that NDMP restores are NOT supported by webui [PR #1020]
- console: prune command gained support to prune multiple volumes at once [PR #966]
- webui: introduce a job timeline chart [PR #1017]

### Changed
- docs: check if configuration directives are defined as CamelCase in core. Otherwise building the documentation will fail with an error [PR #1008]
Expand Down
18 changes: 17 additions & 1 deletion webui/module/Application/view/layout/login.phtml.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (C) 2013-2019 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (C) 2013-2021 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
* @author Frank Bergkemper
*
Expand Down Expand Up @@ -62,6 +62,22 @@ echo $this->doctype();

<body>

<style>
.panel-default, .panel {
background-color: transparent;
border-width: 0px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
}
html {
min-height: 100%;
}
body {
background: linear-gradient(#ffffff, #0075be);
}
</style>

<?php
include 'version.php';
?>
Expand Down
126 changes: 125 additions & 1 deletion webui/module/Job/src/Job/Controller/JobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (c) 2013-2020 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2021 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -534,6 +534,46 @@ public function runAction()
}
}

public function timelineAction()
{
$this->RequestURIPlugin()->setRequestURI();

if(!$this->SessionTimeoutPlugin()->isValid()) {
return $this->redirect()->toRoute(
'auth',
array(
'action' => 'login'
),
array(
'query' => array(
'req' => $this->RequestURIPlugin()->getRequestURI(),
'dird' => $_SESSION['bareos']['director']
)
)
);
}

$module_config = $this->getServiceLocator()->get('ModuleManager')->getModule('Application')->getConfig();
$invalid_commands = $this->CommandACLPlugin()->getInvalidCommands(
$module_config['console_commands']['Job']['mandatory']
);
if(count($invalid_commands) > 0) {
$this->acl_alert = true;
return new ViewModel(
array(
'acl_alert' => $this->acl_alert,
'invalid_commands' => implode(",", $invalid_commands)
)
);
}

$this->bsock = $this->getServiceLocator()->get('director');

// TODO

return new ViewModel();
}

public function getDataAction()
{
$this->RequestURIPlugin()->setRequestURI();
Expand All @@ -560,6 +600,8 @@ public function getDataAction()
$jobname = $this->params()->fromQuery('jobname');
$status = $this->params()->fromQuery('status');
$period = $this->params()->fromQuery('period');
$client = $this->params()->fromQuery('client');
$clients = $this->params()->fromQUery('clients');

try {
$this->bsock = $this->getServiceLocator()->get('director');
Expand Down Expand Up @@ -618,6 +660,88 @@ public function getDataAction()
echo $e->getMessage();
}
}
elseif($data == "timeline") {
try {
$result = [];
$c = explode(",", $clients);

foreach($c as $client) {
$result = array_merge($result, $this->getJobModel()->getClientJobsForPeriod($this->bsock, $client, $period));
}

$jobs = array();

foreach($result as $job) {

$starttime = new \DateTime($job['starttime']);
$endtime = new \DateTime($job['endtime']);
$schedtime = new \DateTime($job['schedtime']);

$starttime = $starttime->format('U')*1000;
$endtime = $endtime->format('U')*1000;
$schedtime = $schedtime->format('U')*1000;

switch($job['jobstatus']) {
// SUCESS
case 'T':
$fillcolor = "#5cb85c";
break;
// WARNING
case 'A':
case 'W':
$fillcolor = "#f0ad4e";
break;
// RUNNING
case 'R':
case 'l':
$fillcolor = "#5bc0de";
$endtime = new \DateTime(null);
$endtime = $endtime->format('U')*1000;
break;
// FAILED
case 'E':
case 'e':
case 'f':
$fillcolor = "#d9534f";
break;
// WAITING
case 'F':
case 'S':
case 's':
case 'M':
case 'm':
case 'j':
case 'C':
case 'c':
case 'd':
case 't':
case 'p':
case 'q':
$fillcolor = "#555555";
$endtime = new \DateTime(null);
$endtime = $endtime->format('U')*1000;
break;
default:
$fillcolor = "#555555";
break;
}

// workaround to display short job runs <= 1 sec.
if($starttime === $endtime) {
$endtime += 1000;
}

$item = '{"x":"'.$job['client'].'","y":["'.$starttime.'","'.$endtime.'"],"fillColor":"'.$fillcolor.'","name":"'.$job['name'].'","jobid":"'.$job['jobid'].'","starttime":"'.$job['starttime'].'","endtime":"'.$job['endtime'].'","schedtime":"'.$job['schedtime'].'"}';
array_push($jobs, json_decode($item));

}

$result = $jobs;

} catch(Exception $e) {
echo $e->getMessage();
}
}

try {
$this->bsock->disconnect();
Expand Down
19 changes: 18 additions & 1 deletion webui/module/Job/src/Job/Model/JobModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (C) 2013-2020 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (C) 2013-2021 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -136,6 +136,23 @@ public function getJobsByStatus(&$bsock=null, $jobname=null, $status=null, $days
}
}

public function getClientJobsForPeriod(&$bsock=null, $client=null, $period=null)
{
if(isset($bsock, $client, $period)) {
$cmd = 'llist jobs client="'.$client.'" days='.$period;
$result = $bsock->send_command($cmd, 2);
$jobs = \Zend\Json\Json::decode($result, \Zend\Json\Json::TYPE_ARRAY);
if (empty($jobs['result'])) {
return false;
} else {
return $jobs['result']['jobs'];
}
}
else {
throw new \Exception('Missing argument.');
}
}

/**
* Get a single Job
*
Expand Down
3 changes: 2 additions & 1 deletion webui/module/Job/view/job/job/actions.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (c) 2013-2020 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (C) 2013-2021 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -32,6 +32,7 @@ $this->headTitle($title);
<li><a href="<?php echo $this->url('job', array('action'=>'index')); ?>"><?php echo $this->translate('Show'); ?></a></li>
<li class="active"><a href="<?php echo $this->url('job', array('action'=>'actions')); ?>"><?php echo $this->translate('Actions'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'run')); ?>"><?php echo $this->translate('Run'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'timeline')); ?>"><?php echo $this->translate('Timeline'); ?></a></li>
</ul>

<br />
Expand Down
1 change: 1 addition & 0 deletions webui/module/Job/view/job/job/details.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $this->headTitle($title);
<li class="active"><a href="<?php echo $this->url('job', array('action'=>'index')); ?>"><?php echo $this->translate('Show'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'actions')); ?>"><?php echo $this->translate('Actions'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'run')); ?>"><?php echo $this->translate('Run'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'timeline')); ?>"><?php echo $this->translate('Timeline'); ?></a></li>
</ul>

<br />
Expand Down
1 change: 1 addition & 0 deletions webui/module/Job/view/job/job/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $this->headTitle($title);
<li class="active"><a href="<?php echo $this->url('job', array('action'=>'index')); ?>"><?php echo $this->translate('Show'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'actions')); ?>"><?php echo $this->translate('Actions'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'run')); ?>"><?php echo $this->translate('Run'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'timeline')); ?>"><?php echo $this->translate('Timeline'); ?></a></li>
</ul>

<br />
Expand Down
3 changes: 2 additions & 1 deletion webui/module/Job/view/job/job/run.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos for the canonical source repository
* @copyright Copyright (C) 2013-2020 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (C) 2013-2021 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -32,6 +32,7 @@ $this->headTitle($title);
<li><a href="<?php echo $this->url('job', array('action'=>'index')); ?>"><?php echo $this->translate('Show'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'actions')); ?>"><?php echo $this->translate('Actions'); ?></a></li>
<li class="active"><a href="<?php echo $this->url('job', array('action'=>'run')); ?>"><?php echo $this->translate('Run'); ?></a></li>
<li><a href="<?php echo $this->url('job', array('action'=>'timeline')); ?>"><?php echo $this->translate('Timeline'); ?></a></li>
</ul>

<br />
Expand Down

0 comments on commit 0fa6bdc

Please sign in to comment.