Search in sources :

Example 26 with NXCPMessage

use of org.netxms.base.NXCPMessage in project netxms by netxms.

the class NXCSession method updateAgentConfig.

/**
 * Update agent's master configuration file.
 *
 * @param nodeId Node ID
 * @param config New configuration file content
 * @param apply  Apply flag - if set to true, agent will restart automatically to
 *               apply changes
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public void updateAgentConfig(long nodeId, String config, boolean apply) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_UPDATE_AGENT_CONFIG);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
    msg.setField(NXCPCodes.VID_CONFIG_FILE, config);
    msg.setFieldInt16(NXCPCodes.VID_APPLY_FLAG, apply ? 1 : 0);
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage)

Example 27 with NXCPMessage

use of org.netxms.base.NXCPMessage in project netxms by netxms.

the class NXCSession method changeObjectBinding.

/**
 * Common internal implementation for bindObject, unbindObject, and
 * removeTemplate
 *
 * @param parentId  parent object's identifier
 * @param childId   Child object's identifier
 * @param bind      true if operation is "bind"
 * @param removeDci true if DCIs created from template should be removed during
 *                  unbind
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
private void changeObjectBinding(long parentId, long childId, boolean bind, boolean removeDci) throws IOException, NXCException {
    NXCPMessage msg = newMessage(bind ? NXCPCodes.CMD_BIND_OBJECT : NXCPCodes.CMD_UNBIND_OBJECT);
    msg.setFieldInt32(NXCPCodes.VID_PARENT_ID, (int) parentId);
    msg.setFieldInt32(NXCPCodes.VID_CHILD_ID, (int) childId);
    msg.setFieldInt16(NXCPCodes.VID_REMOVE_DCI, removeDci ? 1 : 0);
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage)

Example 28 with NXCPMessage

use of org.netxms.base.NXCPMessage in project netxms by netxms.

the class NXCSession method uploadFileToServer.

/**
 * Upload local file to server's file store
 *
 * @param localFile      local file
 * @param serverFileName name under which file will be stored on server
 * @param listener The ProgressListener to set
 * @throws IOException  if socket or file I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public void uploadFileToServer(File localFile, String serverFileName, ProgressListener listener) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_UPLOAD_FILE);
    if ((serverFileName == null) || serverFileName.isEmpty()) {
        serverFileName = localFile.getName();
    }
    msg.setField(NXCPCodes.VID_FILE_NAME, serverFileName);
    msg.setField(NXCPCodes.VID_MODIFICATION_TIME, new Date(localFile.lastModified()));
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
    sendFile(msg.getMessageId(), localFile, listener, allowCompression);
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) Date(java.util.Date)

Example 29 with NXCPMessage

use of org.netxms.base.NXCPMessage in project netxms by netxms.

the class NXCSession method getNetworkPath.

/**
 * Get IPv4 network path between two nodes. Server will return path based
 * on cached routing table information. Network path object may be incomplete
 * if server does not have enough information to build full path. In this case,
 * no exception thrown, and completness of path can be checked by calling
 * NetworkPath.isComplete().
 *
 * @param node1 source node
 * @param node2 destination node
 * @return network path object
 * @throws IOException  if socket or file I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public NetworkPath getNetworkPath(long node1, long node2) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_NETWORK_PATH);
    msg.setFieldInt32(NXCPCodes.VID_SOURCE_OBJECT_ID, (int) node1);
    msg.setFieldInt32(NXCPCodes.VID_DESTINATION_OBJECT_ID, (int) node2);
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    return new NetworkPath(response);
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) NetworkPath(org.netxms.client.topology.NetworkPath)

Example 30 with NXCPMessage

use of org.netxms.base.NXCPMessage in project netxms by netxms.

the class NXCSession method getAttributeForCurrentUser.

/**
 * Get custom attribute for currently logged in user. If attribute is not set, empty string will
 * be returned.
 *
 * @param name Attribute's name
 * @return Attribute's value
 * @throws IOException if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public String getAttributeForCurrentUser(final String name) throws IOException, NXCException {
    NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_CURRENT_USER_ATTR);
    msg.setField(NXCPCodes.VID_NAME, name);
    sendMessage(msg);
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    return response.getFieldAsString(NXCPCodes.VID_VALUE);
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage)

Aggregations

NXCPMessage (org.netxms.base.NXCPMessage)274 ConnectionPoint (org.netxms.client.topology.ConnectionPoint)69 AccessPoint (org.netxms.client.objects.AccessPoint)66 ArrayList (java.util.ArrayList)44 IOException (java.io.IOException)8 HashMap (java.util.HashMap)7 DciSummaryTable (org.netxms.client.datacollection.DciSummaryTable)7 MappingTable (org.netxms.client.mt.MappingTable)7 NXCPException (org.netxms.base.NXCPException)5 UnknownHostException (java.net.UnknownHostException)3 GeneralSecurityException (java.security.GeneralSecurityException)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 UUID (java.util.UUID)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 MessageProcessingResult (com.radensolutions.reporting.service.MessageProcessingResult)2 FileInputStream (java.io.FileInputStream)2 Socket (java.net.Socket)2 SignatureException (java.security.SignatureException)2 Date (java.util.Date)2 List (java.util.List)2