-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
127 changed files
with
16,089 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Icinga Reporting | ||
|
||
Icinga Reporting is the central component for reporting related functionality in the monitoring web frontend and | ||
framework Icinga Web 2. The engine allows you to create reports over a specified time period for ad-hoc and scheduled | ||
generation of reports. Other modules use the provided functionality in order to provide concrete reports. | ||
|
||
## Documentation | ||
|
||
* [Installation](doc/02-Installation.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 | ||
|
||
namespace Icinga\Module\Reporting\Clicommands; | ||
|
||
use Icinga\Module\Reporting\Cli\Command; | ||
use Icinga\Module\Reporting\Scheduler; | ||
|
||
class ScheduleCommand extends Command | ||
{ | ||
/** | ||
* Run all configured reports based on their schedule | ||
* | ||
* USAGE: | ||
* | ||
* icingacli reporting schedule run | ||
*/ | ||
public function runAction() | ||
{ | ||
$scheduler = new Scheduler($this->getDb()); | ||
|
||
$scheduler->run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 | ||
|
||
namespace Icinga\Module\Reporting\Controllers; | ||
|
||
use Icinga\Application\Config; | ||
use Icinga\Module\Reporting\Forms\SelectBackendForm; | ||
use Icinga\Web\Controller; | ||
|
||
class ConfigController extends Controller | ||
{ | ||
public function init() | ||
{ | ||
$this->assertPermission('config/modules'); | ||
|
||
parent::init(); | ||
} | ||
|
||
public function backendAction() | ||
{ | ||
$form = (new SelectBackendForm()) | ||
->setIniConfig(Config::module('reporting')); | ||
|
||
$form->handleRequest(); | ||
|
||
$this->view->tabs = $this->Module()->getConfigTabs()->activate('backend'); | ||
$this->view->form = $form; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Icinga\Module\Reporting\Controllers; | ||
|
||
use GuzzleHttp\Psr7\ServerRequest; | ||
use Icinga\Module\Reporting\Hook\ReportHook; | ||
use Icinga\Module\Reporting\Web\Forms\ReportForm; | ||
use Icinga\Module\Reporting\Web\Controller; | ||
use Icinga\Web\Hook; | ||
use Icinga\Web\Url; | ||
use ipl\Html\Html; | ||
|
||
class PlugController extends Controller | ||
{ | ||
public function indexAction() | ||
{ | ||
$moduleToShow = strtolower($this->params->get('module', 'reporting')); | ||
|
||
$reportsByModule = []; | ||
|
||
foreach (ReportHook::getReports() as $class => $report) { | ||
$moduleName = $report->getModuleName(); | ||
|
||
if (! isset($reportsByModule[$moduleName])) { | ||
$reportsByModule[$moduleName] = []; | ||
} | ||
|
||
$reportsByModule[$moduleName][$class] = $report; | ||
} | ||
|
||
$editor = Html::tag('div', ['class' => 'editor']); | ||
|
||
$nav = []; | ||
|
||
$cards = []; | ||
|
||
foreach ($reportsByModule as $moduleName => $reports) { | ||
$link = Html::tag('a', ['href' => Url::fromRequest(['module' => $moduleName])], $moduleName); | ||
|
||
$nav[] = $link; | ||
|
||
if ($moduleName !== $moduleToShow) { | ||
continue; | ||
} | ||
|
||
$link->getAttributes()->add('class', 'active'); | ||
|
||
foreach ($reports as $report) { | ||
$cards[] = Html::tag( | ||
'div', | ||
['class' => 'card'], | ||
[ | ||
Html::tag('div', ['class' => 'card-top'], $report->getPreview()), | ||
Html::tag( | ||
'div', | ||
['class' => 'card-content'], | ||
Html::tag('h5', ['class' => 'card-title'], $report->getName()), | ||
Html::tag('p', ['class' => 'card-text'], $report->getDescription()) | ||
) | ||
] | ||
); | ||
} | ||
} | ||
|
||
$editor->add(Html::tag('div', ['class' => 'editor-nav'], $nav)); | ||
$editor->add(Html::tag('div', ['class' => 'editor-content'], $cards)); | ||
|
||
$this->addContent($editor); | ||
|
||
$this->addContent(Html::tag('a', ['href' => 'plug', 'class' => 'modal-toggle', 'data-base-target' => 'modal-container'], 'Modal')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
<?php | ||
// Icinga Reporting | (c) 2018 Icinga GmbH | GPLv2 | ||
|
||
namespace Icinga\Module\Reporting\Controllers; | ||
|
||
use GuzzleHttp\Psr7\ServerRequest; | ||
use Icinga\Application\Hook; | ||
use Icinga\Module\Reporting\Database; | ||
use Icinga\Module\Reporting\Report; | ||
use Icinga\Module\Reporting\Web\Controller; | ||
use Icinga\Module\Reporting\Web\Forms\ReportForm; | ||
use Icinga\Module\Reporting\Web\Forms\ScheduleForm; | ||
use Icinga\Module\Reporting\Web\Forms\SendForm; | ||
use Icinga\Web\StyleSheet; | ||
use ipl\Html\Html; | ||
use ipl\Html\HtmlString; | ||
use reportingipl\Web\Url; | ||
use reportingipl\Web\Widget\ActionBar; | ||
use reportingipl\Web\Widget\DropdownLink; | ||
|
||
class ReportController extends Controller | ||
{ | ||
use Database; | ||
|
||
/** @var Report */ | ||
protected $report; | ||
|
||
public function init() | ||
{ | ||
$this->report = Report::fromDb($this->params->getRequired('id')); | ||
} | ||
|
||
public function indexAction() | ||
{ | ||
$this->setTitle($this->report->getName()); | ||
|
||
$this->addControl($this->assembleActions()); | ||
|
||
$this->addContent($this->report->toHtml()); | ||
} | ||
|
||
public function editAction() | ||
{ | ||
$this->setTitle('Edit Report'); | ||
|
||
$values = [ | ||
'name' => $this->report->getName(), | ||
// TODO(el): Must cast to string here because ipl/html does not support integer return values for attribute callbacks | ||
'timeframe' => (string) $this->report->getTimeframe()->getId(), | ||
]; | ||
|
||
$reportlet = $this->report->getReportlets()[0]; | ||
|
||
$values['reportlet'] = $reportlet->getClass(); | ||
|
||
foreach ($reportlet->getConfig() as $name => $value) { | ||
$values[$name] = $value; | ||
} | ||
|
||
$form = new ReportForm(); | ||
$form->setId($this->report->getId()); | ||
$form->populate($values); | ||
$form->handleRequest(ServerRequest::fromGlobals()); | ||
|
||
$this->redirectForm($form, 'reporting/reports'); | ||
|
||
$this->addContent($form); | ||
} | ||
|
||
public function sendAction() | ||
{ | ||
$this->setTitle('Send Report'); | ||
|
||
$form = new SendForm(); | ||
$form | ||
->setReport($this->report) | ||
->handleRequest(ServerRequest::fromGlobals()); | ||
|
||
$this->redirectForm($form, "reporting/report?id={$this->report->getId()}"); | ||
|
||
$this->addContent($form); | ||
} | ||
|
||
public function scheduleAction() | ||
{ | ||
$this->setTitle('Schedule'); | ||
|
||
$form = new ScheduleForm(); | ||
$form | ||
->setReport($this->report) | ||
->handleRequest(ServerRequest::fromGlobals()); | ||
|
||
$this->redirectForm($form, "reporting/report?id={$this->report->getId()}"); | ||
|
||
$this->addContent($form); | ||
} | ||
|
||
public function downloadAction() | ||
{ | ||
$type = $this->params->getRequired('type'); | ||
|
||
$name = sprintf( | ||
'%s (%s) %s', | ||
$this->report->getName(), | ||
$this->report->getTimeframe()->getName(), | ||
date('Y-m-d H:i') | ||
); | ||
|
||
switch ($type) { | ||
case 'pdf': | ||
$pdfexport = null; | ||
|
||
if (Hook::has('Pdfexport')) { | ||
$pdfexport = Hook::first('Pdfexport'); | ||
|
||
if (! $pdfexport->isSupported()) { | ||
throw new \Exception("Can't export"); | ||
} | ||
} | ||
|
||
if (! $pdfexport) { | ||
throw new \Exception("Can't export"); | ||
} | ||
|
||
$html = Html::tag( | ||
'html', | ||
null, | ||
[ | ||
Html::tag( | ||
'head', | ||
null, | ||
Html::tag( | ||
'style', | ||
null, | ||
new HtmlString(StyleSheet::forPdf()) | ||
) | ||
), | ||
Html::tag( | ||
'body', | ||
null, | ||
Html::tag( | ||
'div', | ||
['class' => 'icinga-module module-reporting'], | ||
new HtmlString($this->report->toHtml()) | ||
) | ||
) | ||
] | ||
); | ||
|
||
/** @var Hook\PdfexportHook */ | ||
$pdfexport->streamPdfFromHtml((string) $html, $name); | ||
exit; | ||
case 'csv': | ||
$response = $this->getResponse(); | ||
$response | ||
->setHeader('Content-Type', 'text/csv') | ||
->setHeader('Cache-Control', 'no-store') | ||
->setHeader( | ||
'Content-Disposition', | ||
'attachment; filename=' . $name . '.csv' | ||
) | ||
->appendBody($this->report->toCsv()) | ||
->sendResponse(); | ||
exit; | ||
case 'json': | ||
$response = $this->getResponse(); | ||
$response | ||
->setHeader('Content-Type', 'application/json') | ||
->setHeader('Cache-Control', 'no-store') | ||
->setHeader( | ||
'Content-Disposition', | ||
'inline; filename=' . $name . '.json' | ||
) | ||
->appendBody($this->report->toJson()) | ||
->sendResponse(); | ||
exit; | ||
} | ||
} | ||
|
||
protected function assembleActions() | ||
{ | ||
$reportId = $this->report->getId(); | ||
|
||
$download = (new DropdownLink('Download')) | ||
->addLink('PDF', Url::fromPath('reporting/report/download?type=pdf', ['id' => $reportId])); | ||
|
||
if ($this->report->providesData()) { | ||
$download->addLink('CSV', Url::fromPath('reporting/report/download?type=csv', ['id' => $reportId])); | ||
$download->addLink('JSON', Url::fromPath('reporting/report/download?type=json', ['id' => $reportId])); | ||
} | ||
|
||
$actions = new ActionBar(); | ||
|
||
$actions | ||
->addLink('Modify', Url::fromPath('reporting/report/edit', ['id' => $reportId]), 'edit') | ||
->addLink('Schedule', Url::fromPath('reporting/report/schedule', ['id' => $reportId]), 'calendar-empty') | ||
->add($download) | ||
->addLink('Send', Url::fromPath('reporting/report/send', ['id' => $reportId]), 'forward'); | ||
|
||
return $actions; | ||
} | ||
} |
Oops, something went wrong.