mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
use space not tabs
This commit is contained in:
@ -1301,64 +1301,64 @@ function list_arp()
|
||||
}
|
||||
function list_services()
|
||||
{
|
||||
global $config;
|
||||
global $config;
|
||||
$app = \Slim\Slim::getInstance();
|
||||
$router = $app->router()->getCurrentRoute()->getParams();
|
||||
$status = 'ok';
|
||||
$status = 'ok';
|
||||
$code = 200;
|
||||
$message = '';
|
||||
|
||||
// Filter BY STATE
|
||||
if (isset($_GET['state'])) {
|
||||
$where = " AND S.service_status= ? AND S.service_disabled='0' AND S.service_ignore='0'";
|
||||
$host_par[] = $_GET['state'];
|
||||
|
||||
if (!is_numeric($_GET['state'])) {
|
||||
$status = 'error';
|
||||
$message = "No valid service state provided, valid option is 0=Ok, 1=Warning, 2=Critical";
|
||||
}
|
||||
}
|
||||
|
||||
// GET BY HOST
|
||||
if(isset($router['hostname'])) {
|
||||
$hostname = $router['hostname'];
|
||||
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
|
||||
|
||||
$where .= " AND S.device_id = ?";
|
||||
$host_par[] = $device_id;
|
||||
|
||||
if (!is_numeric($device_id)) {
|
||||
$status = 'error';
|
||||
$message = "No valid hostname or device id provided";
|
||||
}
|
||||
}
|
||||
|
||||
// Filter BY STATE
|
||||
if (isset($_GET['state'])) {
|
||||
$where = " AND S.service_status= ? AND S.service_disabled='0' AND S.service_ignore='0'";
|
||||
$host_par[] = $_GET['state'];
|
||||
|
||||
if (!is_numeric($_GET['state'])) {
|
||||
$status = 'error';
|
||||
$message = "No valid service state provided, valid option is 0=Ok, 1=Warning, 2=Critical";
|
||||
}
|
||||
}
|
||||
|
||||
// GET BY HOST
|
||||
if(isset($router['hostname'])) {
|
||||
$hostname = $router['hostname'];
|
||||
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
|
||||
|
||||
$where .= " AND S.device_id = ?";
|
||||
$host_par[] = $device_id;
|
||||
|
||||
if (!is_numeric($device_id)) {
|
||||
$status = 'error';
|
||||
$message = "No valid hostname or device id provided";
|
||||
}
|
||||
}
|
||||
|
||||
// DEVICE
|
||||
$host_sql = 'SELECT * FROM devices AS D, services AS S WHERE D.device_id = S.device_id '.$where.' GROUP BY D.hostname ORDER BY D.hostname';
|
||||
|
||||
// SERVICE
|
||||
$shift = 1;
|
||||
foreach (dbFetchRows($host_sql, $host_par) as $device) {
|
||||
$device_id = $device['device_id'];
|
||||
$sql_param[0] = $device_id;
|
||||
|
||||
// FILTER BY TYPE
|
||||
if (isset($_GET['type'])) {
|
||||
$devicewhere = " AND `service_type` LIKE ?";
|
||||
$sql_param[1] = $_GET['type'];
|
||||
}
|
||||
// DEVICE
|
||||
$host_sql = 'SELECT * FROM devices AS D, services AS S WHERE D.device_id = S.device_id '.$where.' GROUP BY D.hostname ORDER BY D.hostname';
|
||||
|
||||
// SERVICE
|
||||
$shift = 1;
|
||||
foreach (dbFetchRows($host_sql, $host_par) as $device) {
|
||||
$device_id = $device['device_id'];
|
||||
$sql_param[0] = $device_id;
|
||||
|
||||
// FILTER BY TYPE
|
||||
if (isset($_GET['type'])) {
|
||||
$devicewhere = " AND `service_type` LIKE ?";
|
||||
$sql_param[1] = $_GET['type'];
|
||||
}
|
||||
|
||||
$services[] = dbFetchRows("SELECT * FROM `services` WHERE `device_id` = ?".$devicewhere, $sql_param);
|
||||
}
|
||||
$services[] = dbFetchRows("SELECT * FROM `services` WHERE `device_id` = ?".$devicewhere, $sql_param);
|
||||
}
|
||||
$count = count($services);
|
||||
$output = array(
|
||||
$output = array(
|
||||
'status' => $status,
|
||||
'err-msg' => $message,
|
||||
'err-msg' => $message,
|
||||
'count' => $count,
|
||||
'services' => $services,
|
||||
);
|
||||
|
||||
$app->response->setStatus($code);
|
||||
$app->response->setStatus($code);
|
||||
$app->response->headers->set('Content-Type', 'application/json');
|
||||
echo _json_encode($output);
|
||||
}
|
||||
|
Reference in New Issue
Block a user