Rebased (sql schema conflict)

This commit is contained in:
laf
2016-01-19 14:33:15 +00:00
13 changed files with 957 additions and 2 deletions

View File

@@ -13,6 +13,7 @@
*/
require_once '../includes/functions.php';
require_once '../includes/component.php';
require_once '../includes/device-groups.inc.php';
function authToken(\Slim\Route $route) {
@@ -507,6 +508,45 @@ function get_graph_by_portgroup() {
}
function get_components() {
global $config;
$code = 200;
$status = 'ok';
$message = '';
$app = \Slim\Slim::getInstance();
$router = $app->router()->getCurrentRoute()->getParams();
$hostname = $router['hostname'];
// Do some filtering if the user requests.
$options = array();
// We need to specify the label as this is a LIKE query
if (isset($_GET['label'])) {
// set a label like filter
$options['filter']['label'] = array('LIKE',$_GET['label']);
unset ($_GET['label']);
}
// Add the rest of the options with an equals query
foreach ($_GET as $k) {
$options['filter'][$k] = array('=',$_GET[$k]);
}
// use hostname as device_id if it's all digits
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
$COMPONENT = new component();
$components = $COMPONENT->getComponents($device_id,$options);
$output = array(
'status' => "$status",
'err-msg' => $message,
'count' => count($components[$device_id]),
'components' => $components[$device_id],
);
$app->response->setStatus($code);
$app->response->headers->set('Content-Type', 'application/json');
echo _json_encode($output);
}
function get_graphs() {
global $config;
$code = 200;

View File

@@ -0,0 +1,84 @@
<?php
if (is_admin() === false) {
$response = array(
'status' => 'error',
'message' => 'Need to be admin',
);
echo _json_encode($response);
exit;
}
$status = 'error';
$message = 'Error with config';
// enable/disable components on devices.
$device_id = intval($_POST['device']);
require_once "../includes/component.php";
$OBJCOMP = new component();
// Go get the component array.
$COMPONENTS = $OBJCOMP->getComponents($device_id);
// We only care about our device id.
$COMPONENTS = $COMPONENTS[$device_id];
// Track how many updates we are making.
$UPDATE = array();
foreach ($COMPONENTS as $ID => $AVP) {
// Is the component disabled?
if (isset($_POST['dis_'.$ID])) {
// Yes it is, was it disabled before?
if ($COMPONENTS[$ID]['disabled'] == 0) {
// No it wasn't, best we disable it then..
$COMPONENTS[$ID]['disabled'] = 1;
$UPDATE[$ID] = true;
}
}
else {
// No its not, was it disabled before?
if ($COMPONENTS[$ID]['disabled'] == 1) {
// Yes it was, best we enable it then..
$COMPONENTS[$ID]['disabled'] = 0;
$UPDATE[$ID] = true;
}
}
// Is the component ignored?
if (isset($_POST['ign_'.$ID])) {
// Yes it is, was it ignored before?
if ($COMPONENTS[$ID]['ignore'] == 0) {
// No it wasn't, best we ignore it then..
$COMPONENTS[$ID]['ignore'] = 1;
$UPDATE[$ID] = true;
}
}
else {
// No its not, was it ignored before?
if ($COMPONENTS[$ID]['ignore'] == 1) {
// Yes it was, best we un-ignore it then..
$COMPONENTS[$ID]['ignore'] = 0;
$UPDATE[$ID] = true;
}
}
}
if (count($UPDATE) > 0) {
// Update our edited components.
$STATUS = $OBJCOMP->setComponentPrefs($device_id,$COMPONENTS);
$message = count($UPDATE).' Device records updated.';
$status = 'ok';
}
else {
$message = 'Record unchanged. No update necessary.';
$status = 'ok';
}
$response = array(
'status' => $status,
'message' => $message,
);
echo _json_encode($response);

View File

@@ -1165,6 +1165,16 @@ function alert_details($details) {
$fallback = false;
}
if ($tmp_alerts['type'] && $tmp_alerts['label']) {
if ($tmp_alerts['error'] == "") {
$fault_detail .= ' '.$tmp_alerts['type'].' - '.$tmp_alerts['label'].';&nbsp;';
}
else {
$fault_detail .= ' '.$tmp_alerts['type'].' - '.$tmp_alerts['label'].' - '.$tmp_alerts['error'].';&nbsp;';
}
$fallback = false;
}
if ($fallback === true) {
foreach ($tmp_alerts as $k => $v) {
if (!empty($v) && $k != 'device_id' && (stristr($k, 'id') || stristr($k, 'desc') || stristr($k, 'msg')) && substr_count($k, '_') <= 1) {

View File

@@ -0,0 +1,59 @@
<?php
$row = 1;
$device_id = $_POST['device_id'];
require_once "../includes/component.php";
$OBJCOMP = new component();
// Add a filter if supplied
if (isset($searchPhrase) && !empty($searchPhrase)) {
$options['filter']['label'] = array('LIKE', $searchPhrase);
}
// Add a Sort option
if (!isset($sort) || empty($sort)) {
// Nothing supplied, default is id ASC.
$options['sort'] = 'id asc';
}
else {
$options['sort'] = $sort;
}
// Define the Limit parameters
if (isset($current)) {
$start = (($current * $rowCount) - ($rowCount));
}
if ($rowCount != -1) {
$options['limit'] = array($start,$rowCount);
}
$COMPONENTS = $OBJCOMP->getComponents($device_id,$options);
$response[] = array(
'id' => '<button type="submit" id="save-form" class="btn btn-success btn-sm" title="Save current component disable/ignore settings">Save</button><button type="submit" id="form-reset" class="btn btn-danger btn-sm" title="Reset form to when the page was loaded">Reset</button>',
'label' => '&nbsp;',
'status' => '<button type="submit" id="alert-select" class="btn btn-default btn-sm" title="Disable alerting on all currently-alerting components">Alerting</button>',
'disable' => '<button type="submit" id="disable-toggle" class="btn btn-default btn-sm" title="Toggle polling for all components">Toggle</button><button type="button" id="disable-select" class="btn btn-default btn-sm" title="Disable polling on all components">Select All</button>',
'ignore' => '<button type="submit" id="ignore-toggle" class="btn btn-default btn-sm" title="Toggle alerting for all components">Toggle</button><button type="button" id="ignore-select" class="btn btn-default btn-sm" title="Disable alerting on all components">Select All</button>',
);
foreach ($COMPONENTS[$device_id] as $ID => $AVP) {
$response[] = array(
'id' => $ID,
'type' => $AVP['type'],
'label' => $AVP['label'],
'status' => ($AVP['status'] ? "<span name='status_".$ID."' class='green'>Normal</span>" : "<span name='status_".$ID."' class='red'>Alert</span>"),
'disable' => '<input type="checkbox" class="disable-check" name="dis_'.$ID.'"'.($AVP['disabled'] ? 'checked' : '').'>',
'ignore' => '<input type="checkbox" class="ignore-check" name="ign_'.$ID.'"'.($AVP['ignore'] ? 'checked' : '').'>',
);
}//end foreach
$output = array(
'current' => $current,
'rowCount' => $rowCount,
'rows' => $response,
'total' => count($COMPONENTS[$device_id]),
);
echo _json_encode($output);