Merge branch 'master' into feature/deduplicate-puppet-code-6842

This commit is contained in:
Eric Lippmann 2014-12-15 18:03:38 +01:00
commit 87c5af7df9
14 changed files with 89 additions and 37 deletions

View File

@ -45,7 +45,7 @@ object HostGroup "all-hosts" {
assign where true assign where true
} }
local host_types = ["ok", "random", "down", "up", "unreachable", "pending"] var host_types = ["ok", "random", "down", "up", "unreachable", "pending"]
for (host_type in host_types) { for (host_type in host_types) {
object HostGroup "all-" + host_type use (host_type) { object HostGroup "all-" + host_type use (host_type) {
@ -54,7 +54,7 @@ for (host_type in host_types) {
} }
} }
local service_types = ["ok", "warning", "critical", "unknown", "flapping", "pending"] var service_types = ["ok", "warning", "critical", "unknown", "flapping", "pending"]
// Servicegroups // Servicegroups
for (service_type in service_types) { for (service_type in service_types) {

View File

@ -31,7 +31,7 @@ if ( isset($pdf) )
} }
</script> </script>
<?= $this->img('img/logo_icinga_big_dark.png', array('align' => 'right', 'width' => '150')) ?> <?= $this->img('img/logo_icinga_big_dark.png', array('align' => 'right', 'width' => '75')) ?>
<!--<div id="page-header"> <!--<div id="page-header">
<table> <table>
<tr> <tr>

View File

@ -92,7 +92,7 @@ if (in_array($path, $special)) {
header('Content-Type: image/svg+xml'); header('Content-Type: image/svg+xml');
$pie = new PieChart(); $pie = new PieChart();
$pie->initFromRequest(); $pie->initFromRequest();
echo $pie->render(); $pie->toSvg();
} elseif ($path === 'png/chart.php') { } elseif ($path === 'png/chart.php') {
if (!array_key_exists('data', $_GET)) { if (!array_key_exists('data', $_GET)) {

View File

@ -4,7 +4,7 @@
namespace Icinga\Chart; namespace Icinga\Chart;
use Exception; use Imagick;
use Icinga\Chart\Legend; use Icinga\Chart\Legend;
use Icinga\Chart\Palette; use Icinga\Chart\Palette;
use Icinga\Chart\Primitive\Drawable; use Icinga\Chart\Primitive\Drawable;
@ -110,12 +110,35 @@ abstract class Chart implements Drawable
return $this->renderer->render(); return $this->renderer->render();
} }
/**
* Return this graph rendered as PNG
*
* @param int $width The width of the PNG in pixel
* @param int $height The height of the PNG in pixel
*
* @return string A PNG binary string
*
* @throws IcingaException In case ImageMagick is not available
*/
public function toPng($width, $height)
{
if (! class_exists('Imagick')) {
throw new IcingaException('Cannot render PNGs without ImageMagick');
}
$image = new Imagick();
$image->readImageBlob($this->render());
$image->setImageFormat('png24');
$image->resizeImage($width, $height, imagick::FILTER_LANCZOS, 1);
return $image;
}
/** /**
* Align the chart to the top left corner instead of centering it * Align the chart to the top left corner instead of centering it
* *
* @param bool $align * @param bool $align
*/ */
public function alignTopLeft ($align = true) public function alignTopLeft($align = true)
{ {
$this->align = $align; $this->align = $align;
} }

View File

@ -5,17 +5,13 @@
namespace Icinga\Chart\Inline; namespace Icinga\Chart\Inline;
use Icinga\Chart\PieChart as PieChartRenderer; use Icinga\Chart\PieChart as PieChartRenderer;
use Imagick;
use Exception;
use Icinga\Exception\IcingaException;
/** /**
* Draw an inline pie-chart directly from the available request parameters. * Draw an inline pie-chart directly from the available request parameters.
*/ */
class PieChart extends Inline class PieChart extends Inline
{ {
protected function getChart()
public function render($output = true)
{ {
$pie = new PieChartRenderer(); $pie = new PieChartRenderer();
$pie->alignTopLeft(); $pie->alignTopLeft();
@ -23,23 +19,24 @@ class PieChart extends Inline
$pie->drawPie(array( $pie->drawPie(array(
'data' => $this->data, 'colors' => $this->colors, 'labels' => $this->labels 'data' => $this->data, 'colors' => $this->colors, 'labels' => $this->labels
)); ));
return $pie;
}
public function toSvg($output = true)
{
if ($output) { if ($output) {
echo $pie->render(); echo $this->getChart()->render();
} else { } else {
return $pie->render(); return $this->getChart()->render();
} }
} }
public function toPng() public function toPng($output = true)
{ {
if (! class_exists('Imagick')) { if ($output) {
// TODO: This is quick & dirty. 404? echo $this->getChart()->toPng($this->width, $this->height);
throw new IcingaException('Cannot render PNGs without Imagick'); } else {
return $this->getChart()->toPng($this->width, $this->height);
} }
$image = new Imagick();
$image->readImageBlob($this->render(false));
$image->setImageFormat('png24');
$image->resizeImage($this->width, $this->height, imagick::FILTER_LANCZOS, 1);
echo $image;
} }
} }

View File

@ -49,7 +49,6 @@ class Pdf extends DOMPDF
$html = $layout->render(); $html = $layout->render();
$imgDir = Url::fromPath('img'); $imgDir = Url::fromPath('img');
$html = preg_replace('~src="' . $imgDir . '/~', 'src="' . Icinga::app()->getBootstrapDirectory() . '/img/', $html); $html = preg_replace('~src="' . $imgDir . '/~', 'src="' . Icinga::app()->getBootstrapDirectory() . '/img/', $html);
$html = preg_replace('~src="/svg/chart.php(.*)"~', 'class="icon" src="http://master1.com/png/chart.php$1"', $html);
$this->load_html($html); $this->load_html($html);
$this->render(); $this->render();
$this->stream( $this->stream(

View File

@ -4,10 +4,12 @@
namespace Icinga\Web\Widget\Chart; namespace Icinga\Web\Widget\Chart;
use Icinga\Chart\PieChart;
use Icinga\Web\Widget\AbstractWidget; use Icinga\Web\Widget\AbstractWidget;
use Icinga\Web\Url; use Icinga\Web\Url;
use Icinga\Util\Format; use Icinga\Util\Format;
use Icinga\Application\Logger; use Icinga\Application\Logger;
use Icinga\Exception\IcingaException;
/** /**
* A SVG-PieChart intended to be displayed as a small icon next to labels, to offer a better visualization of the * A SVG-PieChart intended to be displayed as a small icon next to labels, to offer a better visualization of the
@ -375,6 +377,22 @@ EOD;
*/ */
public function render() public function render()
{ {
if ($this->view()->layout()->getLayout() === 'pdf') {
$pie = new PieChart();
$pie->alignTopLeft();
$pie->disableLegend();
$pie->drawPie(array(
'data' => $this->data, 'colors' => $this->colors, 'labels' => $this->labels
));
try {
$png = $pie->toPng($this->width, $this->height);
return '<img class="inlinepie" src="data:image/png;base64,' . base64_encode($png) . '" />';
} catch (IcingaException $_) {
return '';
}
}
$template = $this->template; $template = $this->template;
$template = str_replace('{url}', $this->url, $template); $template = str_replace('{url}', $this->url, $template);

View File

@ -637,7 +637,7 @@ class FilterEditor extends AbstractWidget
public function renderSearch() public function renderSearch()
{ {
$html = ' <form method="post" class="inline" action="' $html = ' <form method="post" class="inline dontprint" action="'
. $this->url() . $this->url()
. '"><input type="text" name="q" style="width: 8em" class="search" value="" placeholder="' . '"><input type="text" name="q" style="width: 8em" class="search" value="" placeholder="'
. t('Search...') . t('Search...')

View File

@ -11,7 +11,7 @@
//define("DOMPDF_DPI", 72); //define("DOMPDF_DPI", 72);
//define("DOMPDF_ENABLE_PHP", true); //define("DOMPDF_ENABLE_PHP", true);
//define("DOMPDF_ENABLE_REMOTE", true); //define("DOMPDF_ENABLE_REMOTE", true);
//define("DOMPDF_ENABLE_CSS_FLOAT", true); define("DOMPDF_ENABLE_CSS_FLOAT", true);
//define("DOMPDF_ENABLE_JAVASCRIPT", false); //define("DOMPDF_ENABLE_JAVASCRIPT", false);
//define("DEBUGPNG", true); //define("DEBUGPNG", true);
//define("DEBUGKEEPTEMP", true); //define("DEBUGKEEPTEMP", true);

View File

@ -9,7 +9,7 @@ use Icinga\Module\Monitoring\Plugin\PerfdataSet;
class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
{ {
public function perfdata($perfdataStr, $compact = false, $float = false) public function perfdata($perfdataStr, $compact = false)
{ {
$pset = PerfdataSet::fromString($perfdataStr)->asArray(); $pset = PerfdataSet::fromString($perfdataStr)->asArray();
$onlyPieChartData = array_filter($pset, function ($e) { return $e->getPercentage() > 0; }); $onlyPieChartData = array_filter($pset, function ($e) { return $e->getPercentage() > 0; });
@ -24,11 +24,7 @@ class Zend_View_Helper_Perfdata extends Zend_View_Helper_Abstract
foreach ($onlyPieChartData as $perfdata) { foreach ($onlyPieChartData as $perfdata) {
$pieChart = $this->createInlinePie($perfdata); $pieChart = $this->createInlinePie($perfdata);
if ($compact) { if ($compact) {
if (! $float) { $result .= $pieChart->render();
$result .= $pieChart->render();
} else {
$result .= '<div style="float: right;">' . $pieChart->render() . '</div>';
}
} else { } else {
if (! $perfdata->isPercentage()) { if (! $perfdata->isPercentage()) {
// TODO: Should we trust sprintf-style placeholders in perfdata titles? // TODO: Should we trust sprintf-style placeholders in perfdata titles?

View File

@ -67,7 +67,7 @@ foreach ($services as $service):
</td> </td>
<td> <td>
<?= $this->perfdata($service->service_perfdata, true, true) ?> <?= $this->perfdata($service->service_perfdata, true) ?>
<?php if (!$service->service_handled && $service->service_state > 0): ?> <?php if (!$service->service_handled && $service->service_state > 0): ?>
<?= $this->icon('attention-alt', $this->translate('Unhandled')) ?> <?= $this->icon('attention-alt', $this->translate('Unhandled')) ?>

View File

@ -461,8 +461,8 @@ class WebWizard extends Wizard implements SetupWizard
mt('setup', 'PHP Module: GD'), mt('setup', 'PHP Module: GD'),
mt( mt(
'setup', 'setup',
'In case you want icons and graphs being exported to PDF' 'In case you want icons being exported to PDF as'
. ' as well, you\'ll need the GD extension for PHP.' . ' well, you\'ll need the GD extension for PHP.'
), ),
Platform::extensionLoaded('gd'), Platform::extensionLoaded('gd'),
Platform::extensionLoaded('gd') ? mt('setup', 'The PHP module GD is available') : ( Platform::extensionLoaded('gd') ? mt('setup', 'The PHP module GD is available') : (
@ -470,6 +470,19 @@ class WebWizard extends Wizard implements SetupWizard
) )
); );
$requirements->addOptional(
mt('setup', 'PHP Module: Imagick'),
mt(
'setup',
'In case you want graphs being exported to PDF as well'
. ', you\'ll need the ImageMagick extension for PHP.'
),
Platform::extensionLoaded('imagick'),
Platform::extensionLoaded('imagick') ? mt('setup', 'The PHP module Imagick is available') : (
mt('setup', 'The PHP module Imagick is missing')
)
);
$requirements->addOptional( $requirements->addOptional(
mt('setup', 'PHP Module: PDO-MySQL'), mt('setup', 'PHP Module: PDO-MySQL'),
mt( mt(

View File

@ -65,11 +65,12 @@ table.action td a:hover {
text-decoration: underline; text-decoration: underline;
} }
table.action div.inlinepie { table.action span.sparkline, table.action img.inlinepie {
margin: 0.5em 0.25em 0.5em 0.25em; margin: 0.5em 0.25em 0.5em 0.25em;
float:right;
} }
.dashboard table.action div.inlinepie { .dashboard table.action span.sparkline, .dashboard table.action img.inlinepie {
margin: 0em 0.25em 0em 0.25em; margin: 0em 0.25em 0em 0.25em;
} }

View File

@ -1,10 +1,15 @@
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
.controls form, .controls .pagination, .controls > .tabs, .dontprint, .inlinepie { .controls form, .controls .pagination, .controls .widgetLimiter, .controls > .tabs, .dontprint {
display: none !important; display: none !important;
} }
table.action img.inlinepie {
width: 50%;
height: 50%;
}
@page { @page {
margin: 2cm; margin: 2cm;
} }