Search in sources :

Example 56 with NXCPMessage

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

the class NXCSession method resolveAlarm.

/**
 * Resolve alarm.
 *
 * @param alarmId Identifier of alarm to be resolved.
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public void resolveAlarm(final long alarmId) throws IOException, NXCException {
    NXCPMessage msg = newMessage(NXCPCodes.CMD_RESOLVE_ALARM);
    msg.setFieldInt32(NXCPCodes.VID_ALARM_ID, (int) alarmId);
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage)

Example 57 with NXCPMessage

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

the class NXCSession method downloadFileFromAgent.

/**
 * Download file from remote host via agent.
 *
 * @param nodeId node object ID
 * @param remoteFileName fully qualified file name on remote system
 * @param maxFileSize maximum download size, 0 == UNLIMITED
 * @param follow if set to true, server will send file updates as they appear (like for tail -f command)
 * @param inputValues input values map for %() macro substitution (can be null)
 * @param alarmId alarm ID used for macro expansion
 * @param listener The ProgressListener to set
 * @return agent file handle which contains server assigned ID and handle for local file
 * @throws IOException  if socket or file I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public AgentFileData downloadFileFromAgent(long nodeId, String remoteFileName, long maxFileSize, boolean follow, Map<String, String> inputValues, long alarmId, ProgressListener listener, ServerJobIdUpdater updateServerJobId) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_AGENT_FILE);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
    msg.setField(NXCPCodes.VID_FILE_NAME, remoteFileName);
    msg.setFieldInt32(NXCPCodes.VID_FILE_SIZE_LIMIT, (int) maxFileSize);
    msg.setFieldInt16(NXCPCodes.VID_FILE_FOLLOW, follow ? 1 : 0);
    msg.setFieldInt32(NXCPCodes.VID_ALARM_ID, (int) alarmId);
    if (inputValues != null) {
        msg.setFieldInt32(NXCPCodes.VID_IN_FIELD_COUNT, inputValues.size());
        long varId = NXCPCodes.VID_IN_FIELD_BASE;
        for (Entry<String, String> e : inputValues.entrySet()) {
            msg.setField(varId++, e.getKey());
            msg.setField(varId++, e.getValue());
        }
    }
    sendMessage(msg);
    // first confirmation - server job started
    final NXCPMessage response = waitForRCC(msg.getMessageId());
    final String id = response.getFieldAsString(NXCPCodes.VID_NAME);
    remoteFileName = response.getFieldAsString(NXCPCodes.VID_FILE_NAME);
    if (updateServerJobId != null)
        updateServerJobId.setJobIdCallback(response.getFieldAsInt32(NXCPCodes.VID_REQUEST_ID));
    if (listener != null) {
        final long fileSize = waitForRCC(msg.getMessageId()).getFieldAsInt64(NXCPCodes.VID_FILE_SIZE);
        listener.setTotalWorkAmount(fileSize);
        synchronized (progressListeners) {
            progressListeners.put(msg.getMessageId(), listener);
        }
    }
    ReceivedFile remoteFile = waitForFile(msg.getMessageId(), 36000000);
    if (remoteFile == null)
        throw new NXCException(RCC.AGENT_FILE_DOWNLOAD_ERROR);
    AgentFileData file = new AgentFileData(id, remoteFileName, remoteFile.getFile());
    try {
        // second confirmation - file transfered from agent to console
        waitForRCC(msg.getMessageId());
    } finally {
        removeProgressListener(msg.getMessageId());
    }
    return file;
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage)

Example 58 with NXCPMessage

use of org.netxms.base.NXCPMessage 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 59 with NXCPMessage

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

the class NXCSession method executeAction.

/**
 * Execute action on remote agent
 *
 * @param nodeId Node object ID
 * @param action Action name
 * @param args Action arguments
 * @param receiveOutput true if action's output has to be read
 * @param listener listener for action's output or null
 * @param writer writer for action's output or null
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public void executeAction(long nodeId, String action, String[] args, boolean receiveOutput, final TextOutputListener listener, final Writer writer) throws IOException, NXCException {
    NXCPMessage msg = newMessage(NXCPCodes.CMD_EXECUTE_ACTION);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
    msg.setField(NXCPCodes.VID_ACTION_NAME, action);
    msg.setField(NXCPCodes.VID_RECEIVE_OUTPUT, receiveOutput);
    if (args != null) {
        msg.setFieldInt16(NXCPCodes.VID_NUM_ARGS, args.length);
        long fieldId = NXCPCodes.VID_ACTION_ARG_BASE;
        for (String a : args) msg.setField(fieldId++, a);
    } else {
        msg.setFieldInt16(NXCPCodes.VID_NUM_ARGS, 0);
    }
    MessageHandler handler = receiveOutput ? new MessageHandler() {

        @Override
        public boolean processMessage(NXCPMessage m) {
            String text = m.getFieldAsString(NXCPCodes.VID_MESSAGE);
            if (text != null) {
                if (listener != null)
                    listener.messageReceived(text);
                if (writer != null) {
                    try {
                        writer.write(text);
                    } catch (IOException e) {
                    }
                }
            }
            if (m.isEndOfSequence())
                setComplete();
            return true;
        }
    } : null;
    if (receiveOutput)
        addMessageSubscription(NXCPCodes.CMD_COMMAND_OUTPUT, msg.getMessageId(), handler);
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
    if (receiveOutput) {
        synchronized (handler) {
            try {
                handler.wait();
            } catch (InterruptedException e) {
            }
        }
        if (handler.isTimeout())
            throw new NXCException(RCC.TIMEOUT);
    }
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) IOException(java.io.IOException)

Example 60 with NXCPMessage

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

the class NXCSession method updateObjectComments.

/**
 * Change object's comments.
 *
 * @param objectId Object's ID
 * @param comments New comments
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public void updateObjectComments(final long objectId, final String comments) throws IOException, NXCException {
    NXCPMessage msg = newMessage(NXCPCodes.CMD_UPDATE_OBJECT_COMMENTS);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) objectId);
    msg.setField(NXCPCodes.VID_COMMENTS, comments);
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
}
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