icingaweb2-module-graphite/library/Graphite/GraphDatasource.php
Thomas Gelf de3f400b3d GraphDatasource: support stacked() function...
...for single datasources. Thanks dgoetz!
2015-06-09 16:49:39 +02:00

92 lines
1.9 KiB
PHP

<?php
namespace Icinga\Module\Graphite;
use Icinga\Web\Url;
class GraphDatasource
{
protected $path;
protected $color;
protected $alias;
protected $scale;
protected $scaleToSeconds;
protected $stacked = false;
public function __construct($path)
{
$this->path = $path;
}
public function setColor($color)
{
$this->color = $color;
return $this;
}
public function setScale($scale)
{
$this->scale = $scale;
return $this;
}
public function setScaleToSeconds($seconds)
{
$this->scaleToSeconds = $seconds;
return $this;
}
public function setAlias($alias)
{
$this->alias = $alias;
return $this;
}
public function setStacked()
{
$this->stacked = true;
return $this;
}
public function getName()
{
if ($this->alias !== null) {
return $this->alias;
}
return $this->path;
}
protected function func()
{
$args = func_get_args();
$function = array_shift($args);
return sprintf($function . '(%s)', implode(',', $args));
}
public function addToUrl(Url $url, $metric)
{
$target = $metric . '.' . $this->path;
if ($this->color !== null) {
$target = $this->func('color', $target, "'" . $this->color . "'");
}
if ($this->scaleToSeconds !== null) {
$target = $this->func('scaleToSeconds', $target, $this->scaleToSeconds);
}
if ($this->scale !== null) {
$target = $this->func('scale', $target, $this->scale);
}
if ($this->alias !== null) {
$target = $this->func('alias', $target, "'" . $this->alias . "'");
}
if ($this->stacked) {
$target = $this->func('stacked', $target);
}
return $url->getParams()->add('target', $target);
}
}