Search in sources :

Example 76 with NXCPMessage

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

the class NXCSession method getLastValues.

/**
 * Get last DCI values for given Single Dci Config list
 *
 * @param dciConfig List with Single Dci Configs
 * @return List of DCI values
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public DciValue[] getLastValues(List<SingleDciConfig> dciConfig) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_DCI_VALUES);
    long base = NXCPCodes.VID_DCI_VALUES_BASE;
    msg.setFieldInt32(NXCPCodes.VID_NUM_ITEMS, dciConfig.size());
    for (SingleDciConfig c : dciConfig) {
        c.fillMessage(msg, base);
        base += 10;
    }
    return sendLastValuesMsg(msg);
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) SingleDciConfig(org.netxms.client.maps.configs.SingleDciConfig)

Example 77 with NXCPMessage

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

the class NXCSession method executeLibraryScript.

/**
 * Execute library script on object. Script name interpreted as command line with server-side macro substitution. Map inputValues
 * can be used to pass data for %() macros.
 *
 * @param nodeId node ID to execute script on
 * @param alarmId alarm ID to use for expansion
 * @param script script name and parameters
 * @param inputFields input values map for %() macro substitution (can be null)
 * @param listener script output listener
 * @throws IOException if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public void executeLibraryScript(long nodeId, long alarmId, String script, Map<String, String> inputFields, final TextOutputListener listener) throws IOException, NXCException {
    NXCPMessage msg = newMessage(NXCPCodes.CMD_EXECUTE_LIBRARY_SCRIPT);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
    msg.setField(NXCPCodes.VID_SCRIPT, script);
    msg.setFieldInt32(NXCPCodes.VID_ALARM_ID, (int) alarmId);
    msg.setField(NXCPCodes.VID_RECEIVE_OUTPUT, listener != null);
    if (inputFields != null) {
        msg.setFieldInt16(NXCPCodes.VID_NUM_FIELDS, inputFields.size());
        long fieldId = NXCPCodes.VID_FIELD_LIST_BASE;
        for (Entry<String, String> e : inputFields.entrySet()) {
            msg.setField(fieldId++, e.getKey());
            msg.setField(fieldId++, e.getValue());
        }
    }
    processScriptExecution(msg, listener);
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage)

Example 78 with NXCPMessage

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

the class NXCSession method sendEvent.

/**
 * Send event to server. Event can be identified either by event code or event name. If event name
 * is given, event code will be ignored.
 *
 * Node: sending events by name supported by server version 1.1.8 and higher.
 *
 * @param eventCode  event code. Ignored if event name is not null.
 * @param eventName  event name. Must be set to null if event identified by code.
 * @param objectId   Object ID to send event on behalf of. If set to 0, server will determine object ID by client IP address.
 * @param parameters event's parameters
 * @param userTag    event's user tag
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public void sendEvent(long eventCode, String eventName, long objectId, String[] parameters, String userTag) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_TRAP);
    msg.setFieldInt32(NXCPCodes.VID_EVENT_CODE, (int) eventCode);
    if (eventName != null)
        msg.setField(NXCPCodes.VID_EVENT_NAME, eventName);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) objectId);
    msg.setField(NXCPCodes.VID_USER_TAG, (userTag != null) ? userTag : "");
    msg.setFieldInt16(NXCPCodes.VID_NUM_ARGS, parameters.length);
    long varId = NXCPCodes.VID_EVENT_ARG_BASE;
    for (int i = 0; i < parameters.length; i++) {
        msg.setField(varId++, parameters[i]);
    }
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Example 79 with NXCPMessage

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

the class NXCSession method deleteAgentFile.

/**
 * Delete file from agent
 *
 * @param nodeId node id
 * @param fileName full path to 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 void deleteAgentFile(long nodeId, String fileName) throws IOException, NXCException {
    final NXCPMessage msg = newMessage(NXCPCodes.CMD_FILEMGR_DELETE_FILE);
    msg.setFieldInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
    msg.setField(NXCPCodes.VID_FILE_NAME, fileName);
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
}
Also used : NXCPMessage(org.netxms.base.NXCPMessage)

Example 80 with NXCPMessage

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

the class NXCSession method scheduleReport.

/**
 * Schedule a report
 *
 * @param job The ReportingJob
 * @param parameters The parameters to set
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
public void scheduleReport(ReportingJob job, Map<String, String> parameters) throws NXCException, IOException {
    NXCPMessage msg = newMessage(NXCPCodes.CMD_RS_SCHEDULE_EXECUTION);
    msg.setField(NXCPCodes.VID_REPORT_DEFINITION, job.getReportId());
    msg.setField(NXCPCodes.VID_RS_JOB_ID, job.getJobId());
    msg.setFieldInt32(NXCPCodes.VID_RS_JOB_TYPE, job.getType());
    msg.setFieldInt64(NXCPCodes.VID_TIMESTAMP, job.getStartTime().getTime());
    msg.setFieldInt32(NXCPCodes.VID_DAY_OF_WEEK, job.getDaysOfWeek());
    msg.setFieldInt32(NXCPCodes.VID_DAY_OF_MONTH, job.getDaysOfMonth());
    msg.setField(NXCPCodes.VID_COMMENTS, job.getComments());
    msg.setFieldInt32(NXCPCodes.VID_NUM_PARAMETERS, parameters.size());
    long varId = NXCPCodes.VID_PARAM_LIST_BASE;
    for (Entry<String, String> e : parameters.entrySet()) {
        msg.setField(varId++, e.getKey());
        msg.setField(varId++, e.getValue());
    }
    sendMessage(msg);
    waitForRCC(msg.getMessageId());
    // FIXME: combine into one message
    if (job.isNotifyOnCompletion()) {
        msg = newMessage(NXCPCodes.CMD_RS_ADD_REPORT_NOTIFY);
        msg.setField(NXCPCodes.VID_RS_JOB_ID, job.getJobId());
        msg.setFieldInt32(NXCPCodes.VID_RENDER_FORMAT, job.getRenderFormat().getCode());
        msg.setField(NXCPCodes.VID_RS_REPORT_NAME, job.getReportName());
        msg.setFieldInt32(NXCPCodes.VID_NUM_ITEMS, job.getEmailRecipients().size());
        varId = NXCPCodes.VID_ITEM_LIST;
        for (String s : job.getEmailRecipients()) msg.setField(varId++, s);
        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