64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?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));
|
|
}
|
|
} |