Example #1
0
function add_components()
{
    global $config;
    $code = 200;
    $status = 'ok';
    $message = '';
    $app = \Slim\Slim::getInstance();
    $router = $app->router()->getCurrentRoute()->getParams();
    $hostname = $router['hostname'];
    $ctype = $router['type'];
    // use hostname as device_id if it's all digits
    $device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
    $COMPONENT = new LibreNMS\Component();
    $component = $COMPONENT->createComponent($device_id, $ctype);
    $output = array('status' => "{$status}", 'err-msg' => $message, 'count' => count($component), 'components' => $component);
    $app->response->setStatus($code);
    $app->response->headers->set('Content-Type', 'application/json');
    echo _json_encode($output);
}
Example #2
0
  * Ok, we have our 2 array's (Components and SNMP) now we need
  * to compare and see what needs to be added/updated.
  *
  * Let's loop over the SNMP data to see if we need to ADD or UPDATE any components.
  */
 foreach ($tblComponents as $key => $array) {
     $component_key = false;
     // Loop over our components to determine if the component exists, or we need to add it.
     foreach ($components as $compid => $child) {
         if ($child['UID'] === $array['UID']) {
             $component_key = $compid;
         }
     }
     if (!$component_key) {
         // The component doesn't exist, we need to ADD it - ADD.
         $new_component = $component->createComponent($device['device_id'], $module);
         $component_key = key($new_component);
         $components[$component_key] = array_merge($new_component[$component_key], $array);
         echo "+";
     } else {
         // The component does exist, merge the details in - UPDATE.
         $components[$component_key] = array_merge($components[$component_key], $array);
         echo ".";
     }
 }
 /*
  * Loop over the Component data to see if we need to DELETE any components.
  */
 foreach ($components as $key => $array) {
     // Guilty until proven innocent
     $found = false;