Exemplo n.º 1
0
/**
 * Update the device-group relationship for the given group id
 * @param $group_id
 */
function UpdateDeviceGroup($group_id)
{
    $queried_devices = QueryDevicesFromGroup($group_id);
    $db_devices = GetDevicesFromGroup($group_id);
    // compare the arrays to get the added and removed devices
    $added_devices = array_diff($queried_devices, $db_devices);
    $removed_devices = array_diff($db_devices, $queried_devices);
    // insert new devices
    $insert = array();
    foreach ($added_devices as $device_id) {
        $insert[] = array('device_id' => $device_id, 'device_group_id' => $group_id);
    }
    if (!empty($insert)) {
        dbBulkInsert($insert, 'device_group_device');
    }
    // remove old devices
    if (!empty($removed_devices)) {
        dbDelete('device_group_device', '`device_group_id`=? AND `device_id` IN (?)', array($group_id, array(implode(',', $removed_devices))));
    }
}
Exemplo n.º 2
0
                $old_mac = $existing_data[$index]['mac_address'];
                if ($mac != $old_mac && $mac != '') {
                    d_echo("Changed mac address for {$ip} from {$old_mac} to {$mac}\n");
                    log_event("MAC change: {$ip} : " . mac_clean_to_readable($old_mac) . ' -> ' . mac_clean_to_readable($mac), $device, 'interface', $port_id);
                    dbUpdate(array('mac_address' => $mac), 'ipv4_mac', 'port_id=? AND ipv4_address=? AND context_name=?', array($port_id, $ip, $context));
                }
                d_echo(null, '.');
            } elseif (isset($interface['port_id'])) {
                d_echo(null, '+');
                $insert_data[] = array('port_id' => $port_id, 'mac_address' => $mac, 'ipv4_address' => $ip, 'context_name' => $context);
            }
        }
    }
    // add new entries
    if (!empty($insert_data)) {
        dbBulkInsert($insert_data, 'ipv4_mac');
    }
    // remove stale entries
    foreach ($existing_data as $entry) {
        $entry_mac = $entry['mac_address'];
        $entry_if = $entry['port_id'];
        $entry_ip = $entry['ipv4_address'];
        if ($arp_table[$entry_if][$entry_ip] != $entry_mac) {
            dbDelete('ipv4_mac', '`port_id` = ? AND `mac_address`=? AND `ipv4_address`=? AND `context_name`=?', array($entry_if, $entry_mac, $entry_ip, $context));
            d_echo(null, '-');
        }
    }
    echo PHP_EOL;
    unset($existing_data, $arp_table, $insert_data, $sql, $params, $context);
    unset($device['context_name']);
}
Exemplo n.º 3
0
     }
 }
 // Processes
 if (!empty($agent_data['ps'])) {
     echo 'Processes: ';
     dbDelete('processes', 'device_id = ?', array($device['device_id']));
     $data = array();
     foreach (explode("\n", $agent_data['ps']) as $process) {
         $process = preg_replace('/\\((.*),([0-9]*),([0-9]*),([0-9\\:]*),([0-9]*)\\)\\ (.*)/', '\\1|\\2|\\3|\\4|\\5|\\6', $process);
         list($user, $vsz, $rss, $cputime, $pid, $command) = explode('|', $process, 6);
         if (!empty($command)) {
             $data[] = array('device_id' => $device['device_id'], 'pid' => $pid, 'user' => $user, 'vsz' => $vsz, 'rss' => $rss, 'cputime' => $cputime, 'command' => $command);
         }
     }
     if (count($data) > 0) {
         dbBulkInsert('processes', $data);
     }
     echo "\n";
 }
 foreach (array_keys($agent_data['app']) as $key) {
     if (file_exists("includes/polling/applications/{$key}.inc.php")) {
         d_echo("Enabling {$key} for " . $device['hostname'] . " if not yet enabled\n");
         if (in_array($key, array('apache', 'mysql', 'nginx', 'proxmox', 'ceph', 'powerdns'))) {
             if (dbFetchCell('SELECT COUNT(*) FROM `applications` WHERE `device_id` = ? AND `app_type` = ?', array($device['device_id'], $key)) == '0') {
                 echo "Found new application '{$key}'\n";
                 dbInsert(array('device_id' => $device['device_id'], 'app_type' => $key, 'app_status' => '', 'app_instance' => ''), 'applications');
             }
         }
     }
 }
 // memcached