Skip to content

Commit

Permalink
Implement basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolashohm committed Jul 16, 2014
1 parent 1f2b2c2 commit ce395c9
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 0 deletions.
43 changes: 43 additions & 0 deletions lib/MuninPlugin/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace MuninPlugin;

/**
* @author Nicolas Hohm <[email protected]>
*/
abstract class Data {

public function __call($name, $arguments)
{
$var_name = strtolower(substr($name, 3));

if (strpos($name, 'get') === 0) {
return $this->$var_name;
} elseif (strpos($name, 'set') === 0) {
$this->$var_name = $arguments[0];
return $this;
} else {
throw new \Exception('Unkown method '.$name, 1);
}
}

protected function getObjectVars(array $blacklist)
{
$objectVars = get_object_vars($this);

foreach (array_keys($objectVars) as $key) {

if (in_array($key, $blacklist)) {
unset($objectVars[$key]);
}

}

return $objectVars;
}

protected function getObjectVarsNotNull(array $blacklist) {
return array_filter($this->getObjectVars($blacklist));
}

}
48 changes: 48 additions & 0 deletions lib/MuninPlugin/Datasource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace MuninPlugin;

/**
* @author Nicolas Hohm <[email protected]>
*/
class Datasource extends Data {

protected $label;
protected $cdef;
protected $draw;
protected $graph;
protected $info;
protected $extinfo;
protected $max;
protected $min;
protected $negative;
protected $type;
protected $warning;
protected $critical;
protected $colour;
protected $sum;
protected $stack;
protected $line;
protected $oldname;
protected $value;

protected $name;
protected $blacklist = array('blacklist', 'name', 'value');

public function __construct($name) {
$this->name = $name;
}

public function getConfig()
{
$output = [];
$objectVars = $this->getObjectVarsNotNull($this->blacklist);

foreach ($objectVars as $key => $value) {
$output[] = $this->name.'.'.$key.' '.$value;
}

return implode(PHP_EOL, $output);
}

}
25 changes: 25 additions & 0 deletions lib/MuninPlugin/DatasourceSet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace MuninPlugin;

/**
* @author Nicolas Hohm <[email protected]>
*/
class DatasourceSet extends \ArrayObject {

public function getValues()
{
$output = [];

foreach ($this as $datasource) {
$output[] = $datasource->getName().'.value '.$datasource->getValue();
}

return implode(PHP_EOL, $output);
}

public function append(Datasource $datasource) {
parent::append($datasource);
}

}
74 changes: 74 additions & 0 deletions lib/MuninPlugin/Graph.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace MuninPlugin;

/**
* @author Nicolas Hohm <[email protected]>
*/
class Graph extends Data {

protected $title;
protected $createArgs;
protected $graphArgs;
protected $category;
protected $info;
protected $order;
protected $vlabel;
protected $total;
protected $scale;
protected $graph;
protected $host_name;
protected $update;
protected $period;
protected $vtitle;
protected $service_order;
protected $width;
protected $height;
protected $printf;

protected $datasourceSet;
protected $blacklist = array('blacklist', 'datasourceSet');

public function __construct($title)
{
$this->title = $title;
$this->datasourceSet = new DatasourceSet();
}

public function getConfig()
{
$output = [$this->getGraphConfig()];

foreach ($this->datasourceSet as $datasource) {
$output[] = $datasource->getConfig();
}

return implode(PHP_EOL, $output);
}

protected function getGraphConfig()
{
$output = [];
$objectVars = $this->getObjectVarsNotNull($this->blacklist);

foreach ($objectVars as $key => $value) {

$output[] = 'graph_'.$key.' '.$value;

}

return implode(PHP_EOL, $output);
}

public function getDatasourceSet()
{
return $this->datasourceSet;
}

public function setDatasourceSet(DatasourceSet $datasourceSet)
{
$this->datasourceSet = $datasourceSet;
return $this;
}

}

0 comments on commit ce395c9

Please sign in to comment.