use space not tabs

This commit is contained in:
nerdalertdk
2016-08-26 09:26:52 +02:00
committed by GitHub
parent 1bf6ed6bd6
commit c873a3556e

View File

@@ -1301,64 +1301,64 @@ function list_arp()
} }
function list_services() function list_services()
{ {
global $config; global $config;
$app = \Slim\Slim::getInstance(); $app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams(); $router = $app->router()->getCurrentRoute()->getParams();
$status = 'ok'; $status = 'ok';
$code = 200; $code = 200;
$message = ''; $message = '';
// Filter BY STATE // Filter BY STATE
if (isset($_GET['state'])) { if (isset($_GET['state'])) {
$where = " AND S.service_status= ? AND S.service_disabled='0' AND S.service_ignore='0'"; $where = " AND S.service_status= ? AND S.service_disabled='0' AND S.service_ignore='0'";
$host_par[] = $_GET['state']; $host_par[] = $_GET['state'];
if (!is_numeric($_GET['state'])) { if (!is_numeric($_GET['state'])) {
$status = 'error'; $status = 'error';
$message = "No valid service state provided, valid option is 0=Ok, 1=Warning, 2=Critical"; $message = "No valid service state provided, valid option is 0=Ok, 1=Warning, 2=Critical";
} }
} }
// GET BY HOST // GET BY HOST
if(isset($router['hostname'])) { if(isset($router['hostname'])) {
$hostname = $router['hostname']; $hostname = $router['hostname'];
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
$where .= " AND S.device_id = ?"; $where .= " AND S.device_id = ?";
$host_par[] = $device_id; $host_par[] = $device_id;
if (!is_numeric($device_id)) { if (!is_numeric($device_id)) {
$status = 'error'; $status = 'error';
$message = "No valid hostname or device id provided"; $message = "No valid hostname or device id provided";
} }
} }
// DEVICE // 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'; $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 // SERVICE
$shift = 1; $shift = 1;
foreach (dbFetchRows($host_sql, $host_par) as $device) { foreach (dbFetchRows($host_sql, $host_par) as $device) {
$device_id = $device['device_id']; $device_id = $device['device_id'];
$sql_param[0] = $device_id; $sql_param[0] = $device_id;
// FILTER BY TYPE // FILTER BY TYPE
if (isset($_GET['type'])) { if (isset($_GET['type'])) {
$devicewhere = " AND `service_type` LIKE ?"; $devicewhere = " AND `service_type` LIKE ?";
$sql_param[1] = $_GET['type']; $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); $count = count($services);
$output = array( $output = array(
'status' => $status, 'status' => $status,
'err-msg' => $message, 'err-msg' => $message,
'count' => $count, 'count' => $count,
'services' => $services, 'services' => $services,
); );
$app->response->setStatus($code); $app->response->setStatus($code);
$app->response->headers->set('Content-Type', 'application/json'); $app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output); echo _json_encode($output);
} }