Merge branch 'feature/graphing' into 'master'
Added Graphing See merge request fronk/thetool!753
This commit is contained in:
9
application/Graphing/Graphing.php
Normal file
9
application/Graphing/Graphing.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @property mixed|null $name
|
||||
*/
|
||||
class Graphing extends mfBaseModel
|
||||
{
|
||||
|
||||
}
|
||||
64
application/Graphing/GraphingController.php
Normal file
64
application/Graphing/GraphingController.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
class GraphingController extends mfBaseController{
|
||||
private string $ZABBIX_API_URL = ZABBIX_API_URL;
|
||||
private string $ZABBIX_API_KEY = ZABBIX_API_KEY;
|
||||
private Zabbix $zabbix;
|
||||
|
||||
protected function init(): void {
|
||||
$me = new User();
|
||||
$me->loadMe();
|
||||
$this->layout()->set("me", $me);
|
||||
$this->me = $me;
|
||||
|
||||
if (!$this->me->isAdmin()) {
|
||||
$this->redirect("dashboard");
|
||||
}
|
||||
|
||||
$this->zabbix = new Zabbix($this->ZABBIX_API_URL, $this->ZABBIX_API_KEY);
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
$this->layout()->set('additionalJS', ["plugins/chart.js/chart.4.4.6.js", "plugins/chart.js/chartjs-adapter-moment.min.js"]);
|
||||
Helper::renderVue($this, "DeviceGraphing", $this->mod, []);
|
||||
}
|
||||
|
||||
|
||||
protected function dataAction() {
|
||||
header('Content-Type: application/json');
|
||||
$hostId = $this->request->hostId;
|
||||
$hostInterfaceItems = $this->zabbix->getHostInterfaceItems($hostId, '');
|
||||
// limit to 25 items
|
||||
$hostInterfaceItems = array_slice($hostInterfaceItems, 0, 25);
|
||||
|
||||
$itemIds = array_map(function($item) {
|
||||
return $item['itemid'];
|
||||
}, $hostInterfaceItems);
|
||||
|
||||
|
||||
$itemValues = $this->zabbix->getItemValues($itemIds, 1000);
|
||||
|
||||
$out = [];
|
||||
foreach ($hostInterfaceItems as $item) {
|
||||
$out[$item['itemid']] = [
|
||||
'name' => str_replace('Bits', 'Mbps', $item['name']),
|
||||
'units' => $item['units'],
|
||||
'values' => []
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($itemValues as $itemValue) {
|
||||
$out[$itemValue['itemid']]['values'][] = [
|
||||
'clock' => $itemValue['clock'],
|
||||
'value' => $itemValue['value'] / 1000000
|
||||
];
|
||||
}
|
||||
|
||||
// sort by name
|
||||
uasort($out, function($a, $b) {
|
||||
return strcmp($a['name'], $b['name']);
|
||||
});
|
||||
|
||||
|
||||
die(json_encode($out));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user