function edit_components() { global $config; $app = \Slim\Slim::getInstance(); $router = $app->router()->getCurrentRoute()->getParams(); $hostname = $router['hostname']; $data = json_decode(file_get_contents('php://input'), true); // use hostname as device_id if it's all digits $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname); $COMPONENT = new LibreNMS\Component(); if ($COMPONENT->setComponentPrefs($device_id, $data)) { // Edit Success. $code = 200; $status = 'ok'; $message = ''; } else { // Edit Failure. $code = 500; $status = 'error'; $message = 'Components could not be edited.'; } $output = array('status' => "{$status}", 'err-msg' => $message, 'count' => count($data)); $app->response->setStatus($code); $app->response->headers->set('Content-Type', 'application/json'); echo _json_encode($output); }
d_echo("\n\nAdjacency Component: " . $key . "\n"); d_echo(" Label: " . $array['label'] . "\n"); d_echo(" Index: " . $array['index'] . "\n"); d_echo(" Status: " . $array['status'] . "\n"); d_echo(" Message: " . $array['error'] . "\n"); } elseif ($array['otvtype'] == 'endpoint') { $count = 0; $endpoint = $array['endpoint']; if (isset($count_mac[$endpoint])) { $count = $count_mac[$endpoint]; } // Let's log some debugging d_echo("\n\nEndpoint Component: " . $key . "\n"); d_echo(" Label: " . $array['label'] . "\n"); d_echo(" MAC Count: " . $count . "\n"); $rrd_name = array('cisco', 'otv', $endpoint, 'mac'); $rrd_def = 'DS:count:GAUGE:600:0:U'; $fields = array('count' => $count); $tags = compact('endpoint', 'rrd_name', 'rrd_def'); data_update($device, 'cisco-otv-mac', $tags, $fields); } // End If } // End foreach components // Write the Components back to the DB. $component->setComponentPrefs($device['device_id'], $components); } // end if count components // Clean-up after yourself! unset($components, $component, $module); }
$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);