Search in sources :

Example 1 with ServerVariable

use of org.netxms.client.server.ServerVariable in project netxms by netxms.

the class NXCSession method getServerVariables.

/**
 * Get server configuration variables
 *
 * @return The server variables
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public Map<String, ServerVariable> getServerVariables() throws IOException, NXCException {
    NXCPMessage request = newMessage(NXCPCodes.CMD_GET_CONFIG_VARLIST);
    sendMessage(request);
    final NXCPMessage response = waitForRCC(request.getMessageId());
    int count = response.getFieldAsInt32(NXCPCodes.VID_NUM_VARIABLES);
    final HashMap<String, ServerVariable> varList = new HashMap<String, ServerVariable>(count);
    long id = NXCPCodes.VID_VARLIST_BASE;
    for (int i = 0; i < count; i++, id += 10) {
        ServerVariable v = new ServerVariable(response, id);
        varList.put(v.getName(), v);
    }
    count = response.getFieldAsInt32(NXCPCodes.VID_NUM_VALUES);
    for (int i = 0; i < count; i++) {
        ServerVariable var = varList.get(response.getFieldAsString(id++));
        if (var != null)
            var.addPossibleValue(response, id);
        id += 2;
    }
    return varList;
}
Also used : HashMap(java.util.HashMap) NXCPMessage(org.netxms.base.NXCPMessage) ServerVariable(org.netxms.client.server.ServerVariable) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Example 2 with ServerVariable

use of org.netxms.client.server.ServerVariable in project netxms by netxms.

the class NXCSession method setDefaultServerValues.

/**
 * Set server configuration variables to default
 *
 * @param varList The list of variables
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public void setDefaultServerValues(List<ServerVariable> varList) throws IOException, NXCException {
    NXCPMessage msg = newMessage(NXCPCodes.CMD_SET_CONFIG_TO_DEFAULT);
    long base = NXCPCodes.VID_VARLIST_BASE;
    for (ServerVariable v : varList) msg.setField(base++, v.getName());
    msg.setFieldInt32(NXCPCodes.VID_NUM_VARIABLES, varList.size());
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) ServerVariable(org.netxms.client.server.ServerVariable)

Example 3 with ServerVariable

use of org.netxms.client.server.ServerVariable in project netxms by netxms.

the class ServerConfigTest method testServerVariables.

public void testServerVariables() throws Exception {
    final NXCSession session = connect();
    // Create test variable
    session.setServerVariable("TestVariable", "TestValue");
    // Get full list
    Map<String, ServerVariable> varList = session.getServerVariables();
    // Normally server should have at least one variable
    assertEquals(true, varList.size() > 0);
    // Get variable TestVariable
    ServerVariable var = varList.get("TestVariable");
    assertEquals(true, var != null);
    assertEquals("TestValue", var.getValue());
    // Delete test variable
    session.deleteServerVariable("TestVariable");
    // Get variable list again and check that test variable was deleted
    varList = session.getServerVariables();
    var = varList.get("TestVariable");
    assertEquals(true, var == null);
    session.disconnect();
}
Also used : ServerVariable(org.netxms.client.server.ServerVariable)

Example 4 with ServerVariable

use of org.netxms.client.server.ServerVariable in project netxms by netxms.

the class SnmpConfig method loadPortConfig.

private static Map<Integer, List<String>> loadPortConfig(NXCSession session) throws IOException, NXCException {
    List<Zone> zones = session.getAllZones();
    Map<Integer, List<String>> ports = new HashMap<Integer, List<String>>();
    for (Zone z : zones) {
        if (!z.getSnmpPorts().isEmpty())
            ports.put((int) z.getUIN(), z.getSnmpPorts());
    }
    Map<String, ServerVariable> variables = session.getServerVariables();
    // $NON-NLS-1$
    ServerVariable v = variables.get("SNMPPorts");
    // $NON-NLS-1$
    parsePorts(v != null ? v.getValue() : "", ports);
    return ports;
}
Also used : HashMap(java.util.HashMap) Zone(org.netxms.client.objects.Zone) List(java.util.List) ArrayList(java.util.ArrayList) ServerVariable(org.netxms.client.server.ServerVariable)

Example 5 with ServerVariable

use of org.netxms.client.server.ServerVariable in project netxms by netxms.

the class DiscoveryConfig method load.

/**
 * Load discovery configuration from server. This method directly calls
 * communication API, so it should not be called from UI thread.
 *
 * @return network discovery configuration
 * @throws IOException if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public static DiscoveryConfig load() throws NXCException, IOException {
    DiscoveryConfig config = new DiscoveryConfig();
    final NXCSession session = ConsoleSharedData.getSession();
    Map<String, ServerVariable> variables = session.getServerVariables();
    // $NON-NLS-1$
    config.enabled = getBoolean(variables, "RunNetworkDiscovery", false);
    // $NON-NLS-1$
    config.active = getBoolean(variables, "ActiveNetworkDiscovery", false);
    // $NON-NLS-1$
    config.useSnmpTraps = getBoolean(variables, "UseSNMPTrapsForDiscovery", false);
    // $NON-NLS-1$
    config.useSyslog = getBoolean(variables, "UseSyslogForDiscovery", false);
    // $NON-NLS-1$
    config.filterFlags = getInteger(variables, "DiscoveryFilterFlags", 0);
    // $NON-NLS-1$ //$NON-NLS-2$
    config.filter = getString(variables, "DiscoveryFilter", "none");
    config.addressFilter = session.getAddressList(NXCSession.ADDRESS_LIST_DISCOVERY_FILTER);
    config.targets = session.getAddressList(NXCSession.ADDRESS_LIST_DISCOVERY_TARGETS);
    return config;
}
Also used : NXCSession(org.netxms.client.NXCSession) ServerVariable(org.netxms.client.server.ServerVariable)

Aggregations

ServerVariable (org.netxms.client.server.ServerVariable)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 PartInitException (org.eclipse.ui.PartInitException)3 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 NXCPMessage (org.netxms.base.NXCPMessage)2 List (java.util.List)1 NXCSession (org.netxms.client.NXCSession)1 AccessPoint (org.netxms.client.objects.AccessPoint)1 Zone (org.netxms.client.objects.Zone)1 ConnectionPoint (org.netxms.client.topology.ConnectionPoint)1 VariableEditDialog (org.netxms.ui.eclipse.serverconfig.dialogs.VariableEditDialog)1