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;
}
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());
}
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();
}
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;
}
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;
}
Aggregations