-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
1f2b2c2
commit ce395c9
Showing
4 changed files
with
190 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,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)); | ||
} | ||
|
||
} |
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,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); | ||
} | ||
|
||
} |
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,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); | ||
} | ||
|
||
} |
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,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; | ||
} | ||
|
||
} |