Files
librenms-librenms/includes/html/table/storage-edit.inc.php

57 lines
1.7 KiB
PHP
Raw Normal View History

<?php
$device_id = $vars['device_id'];
2020-09-21 15:59:34 +02:00
$sql = ' FROM `storage` AS `S` LEFT JOIN `devices` AS `D` ON `S`.`device_id` = `D`.`device_id` WHERE `D`.`device_id`=? AND `S`.`storage_deleted`=0';
$param[] = $device_id;
2020-09-21 15:40:17 +02:00
if (isset($searchPhrase) && ! empty($searchPhrase)) {
2020-09-21 15:59:34 +02:00
$sql .= ' AND (`D`.`hostname` LIKE ? OR `S`.`storage_descr` LIKE ? OR `S`.`storage_perc` LIKE ? OR `S`.`storage_perc_warn` LIKE ?)';
$param[] = "%$searchPhrase%";
$param[] = "%$searchPhrase%";
$param[] = "%$searchPhrase%";
$param[] = "%$searchPhrase%";
}
$count_sql = "SELECT COUNT(`storage_id`) $sql";
$total = dbFetchCell($count_sql, $param);
if (empty($total)) {
$total = 0;
}
2020-09-21 15:40:17 +02:00
if (! isset($sort) || empty($sort)) {
$sort = '`D`.`hostname`, `S`.`storage_descr`';
}
$sql .= " ORDER BY $sort";
if (isset($current)) {
$limit_low = ($current * $rowCount) - ($rowCount);
$limit_high = $rowCount;
}
if ($rowCount != -1) {
$sql .= " LIMIT $limit_low,$limit_high";
}
$sql = "SELECT * $sql";
//$response[] = array('storage_descr' => $sql);
foreach (dbFetchRows($sql, $param) as $drive) {
$perc = round($drive['storage_perc']);
$perc_warn = round($drive['storage_perc_warn']);
$size = \LibreNMS\Util\Number::formatBi($drive['storage_size']);
2020-09-21 15:40:17 +02:00
$response[] = [
'storage_id' => $drive['storage_id'],
'hostname' => generate_device_link($drive),
'storage_descr' => $drive['storage_descr'],
2020-09-21 15:59:34 +02:00
'storage_perc' => $perc . '%',
'storage_perc_warn' => $perc_warn,
2020-09-21 15:40:17 +02:00
'storage_size' => $size,
];
}
2020-09-21 15:40:17 +02:00
$output = ['current'=>$current, 'rowCount'=>$rowCount, 'rows'=>$response, 'total'=>$total];
echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);