Search in sources :

Example 21 with AbstractObject

use of org.netxms.client.objects.AbstractObject in project netxms by netxms.

the class IdMatchingDialog method mapNode.

/**
 * Map node
 *
 * @param data
 */
private void mapNode(ObjectIdMatchingData data) {
    Set<Integer> classFilter;
    switch(data.objectClass) {
        case AbstractObject.OBJECT_NODE:
        case AbstractObject.OBJECT_CLUSTER:
            classFilter = ObjectSelectionDialog.createNodeSelectionFilter(false);
            showFilterToolTip = true;
            break;
        case AbstractObject.OBJECT_CONTAINER:
            classFilter = ObjectSelectionDialog.createContainerSelectionFilter();
            showFilterToolTip = false;
            break;
        case AbstractObject.OBJECT_ZONE:
            classFilter = ObjectSelectionDialog.createZoneSelectionFilter();
            showFilterToolTip = true;
            break;
        case AbstractObject.OBJECT_DASHBOARD:
            classFilter = new HashSet<Integer>(2);
            classFilter.add(AbstractObject.OBJECT_DASHBOARD);
            classFilter.add(AbstractObject.OBJECT_DASHBOARDROOT);
            break;
        default:
            classFilter = null;
            break;
    }
    ObjectSelectionDialog dlg = new ObjectSelectionDialog(getShell(), null, classFilter);
    dlg.showFilterToolTip(showFilterToolTip);
    if (dlg.open() == Window.OK) {
        AbstractObject object = dlg.getSelectedObjects().get(0);
        if (ImportDashboard.isCompatibleClasses(object.getObjectClass(), data.objectClass)) {
            data.dstId = object.getObjectId();
            data.dstName = object.getObjectName();
            updateDciMapping(data);
            viewer.update(data, null);
        } else {
            MessageDialogHelper.openWarning(getShell(), Messages.get().IdMatchingDialog_Warning, Messages.get().IdMatchingDialog_ClassMismatch);
        }
    }
}
Also used : ObjectSelectionDialog(org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog) AbstractObject(org.netxms.client.objects.AbstractObject)

Example 22 with AbstractObject

use of org.netxms.client.objects.AbstractObject in project netxms by netxms.

the class AlarmDetails method refresh.

/**
 * Refresh view
 */
private void refresh() {
    new ConsoleJob(Messages.get().AlarmDetails_RefreshJobTitle, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final Alarm alarm = session.getAlarm(alarmId);
            final List<AlarmComment> comments = session.getAlarmComments(alarmId);
            List<EventInfo> _events = null;
            try {
                _events = session.getAlarmEvents(alarmId);
            } catch (NXCException e) {
                if (e.getErrorCode() != RCC.ACCESS_DENIED)
                    throw e;
            }
            final List<EventInfo> events = _events;
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    updateAlarmDetails(alarm);
                    for (AlarmCommentsEditor e : editors.values()) e.dispose();
                    for (AlarmComment n : comments) editors.put(n.getId(), createEditor(n));
                    if (lastValuesWidget == null) {
                        AbstractObject object = session.findObjectById(alarm.getSourceObjectId());
                        if (object != null) {
                            // $NON-NLS-1$
                            lastValuesWidget = new LastValuesWidget(AlarmDetails.this, dataArea, SWT.BORDER, object, "AlarmDetails.LastValues", null);
                            lastValuesWidget.refresh();
                        }
                    }
                    if (events != null) {
                        eventViewer.setInput(events);
                        eventViewer.expandAll();
                        if (labelAccessDenied != null) {
                            labelAccessDenied.dispose();
                            labelAccessDenied = null;
                        }
                    } else if (labelAccessDenied == null) {
                        labelAccessDenied = new CLabel(eventViewer.getControl().getParent(), SWT.NONE);
                        toolkit.adapt(labelAccessDenied);
                        labelAccessDenied.setImage(StatusDisplayInfo.getStatusImage(Severity.CRITICAL));
                        labelAccessDenied.setText(Messages.get().AlarmDetails_RelatedEvents_AccessDenied);
                        labelAccessDenied.moveAbove(null);
                        labelAccessDenied.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
                    }
                    updateLayout();
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().AlarmDetails_RefreshJobError;
        }
    }.start();
}
Also used : AlarmCommentsEditor(org.netxms.ui.eclipse.alarmviewer.widgets.AlarmCommentsEditor) CLabel(org.eclipse.swt.custom.CLabel) LastValuesWidget(org.netxms.ui.eclipse.datacollection.widgets.LastValuesWidget) AlarmComment(org.netxms.client.events.AlarmComment) PartInitException(org.eclipse.ui.PartInitException) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Alarm(org.netxms.client.events.Alarm) AbstractObject(org.netxms.client.objects.AbstractObject) GridData(org.eclipse.swt.layout.GridData) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob)

Example 23 with AbstractObject

use of org.netxms.client.objects.AbstractObject in project netxms by netxms.

the class TakeScreenshot method selectionChanged.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
	 */
@Override
public void selectionChanged(IAction action, ISelection selection) {
    if ((selection instanceof IStructuredSelection) && (((IStructuredSelection) selection).size() == 1)) {
        Object obj = ((IStructuredSelection) selection).getFirstElement();
        if ((obj instanceof AbstractNode) && ((AbstractNode) obj).hasAgent()) {
            action.setEnabled(true);
            node = ((AbstractObject) obj);
        } else {
            action.setEnabled(false);
            node = null;
        }
    } else {
        action.setEnabled(false);
        node = null;
    }
}
Also used : AbstractNode(org.netxms.client.objects.AbstractNode) AbstractObject(org.netxms.client.objects.AbstractObject) AbstractObject(org.netxms.client.objects.AbstractObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 24 with AbstractObject

use of org.netxms.client.objects.AbstractObject in project netxms by netxms.

the class GrafanaAlarms method getCollection.

/* (non-Javadoc)
    * @see org.netxms.websvc.handlers.AbstractHandler#getCollection(java.util.Map)
    */
@Override
public Object getCollection(Map<String, String> query) throws Exception {
    if (!getSession().isObjectsSynchronized())
        getSession().syncObjects();
    if (query.isEmpty()) {
        Set<Integer> classFilter = new HashSet<Integer>(5);
        classFilter.add(AbstractObject.OBJECT_NODE);
        classFilter.add(AbstractObject.OBJECT_MOBILEDEVICE);
        classFilter.add(AbstractObject.OBJECT_RACK);
        classFilter.add(AbstractObject.OBJECT_CLUSTER);
        classFilter.add(AbstractObject.OBJECT_SENSOR);
        AbstractObject[] objects = getSession().getTopLevelObjects(classFilter);
        Map<Long, String> result = new HashMap<Long, String>();
        for (AbstractObject o : objects) result.put(o.getObjectId(), o.getObjectName());
        return result;
    }
    JsonObject root = new JsonObject();
    JsonArray columns = new JsonArray();
    columns.add(createColumn("Severity", true, true));
    columns.add(createColumn("State", true, false));
    columns.add(createColumn("Source", true, false));
    columns.add(createColumn("Message", true, false));
    columns.add(createColumn("Count", true, false));
    columns.add(createColumn("Helpdesk ID", true, false));
    columns.add(createColumn("Ack/Resolved By", true, false));
    columns.add(createColumn("Created", true, false));
    columns.add(createColumn("Last Change", true, false));
    root.add("columns", columns);
    JsonArray rows = new JsonArray();
    JsonArray r = new JsonArray();
    DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
    AbstractObject object = null;
    AbstractUserObject user = null;
    JsonParser parser = new JsonParser();
    JsonElement element = parser.parse(query.get("targets"));
    if (!element.isJsonArray())
        return new JsonArray();
    JsonArray targets = element.getAsJsonArray();
    JsonObject alarmSource;
    long sourceId = 0;
    Map<Long, Alarm> alarms = getSession().getAlarms();
    for (JsonElement e : targets) {
        for (Alarm a : alarms.values()) {
            if (e.getAsJsonObject().has("alarmSource")) {
                alarmSource = e.getAsJsonObject().getAsJsonObject("alarmSource");
                if (alarmSource.size() > 0)
                    sourceId = Long.parseLong(alarmSource.get("id").getAsString());
            }
            if (sourceId == 0 || a.getSourceObjectId() == sourceId) {
                r.add(a.getCurrentSeverity().name());
                r.add(STATES[a.getState()]);
                object = getSession().findObjectById(a.getSourceObjectId());
                if (object == null)
                    r.add(a.getSourceObjectId());
                else
                    r.add(object.getObjectName());
                r.add(a.getMessage());
                r.add(a.getRepeatCount());
                r.add(a.getHelpdeskReference());
                user = getSession().findUserDBObjectById(a.getAckByUser());
                if (user == null)
                    r.add("");
                else
                    r.add(user.getName());
                r.add(df.format(a.getCreationTime()));
                r.add(df.format(a.getLastChangeTime()));
                rows.add(r);
                r = new JsonArray();
            }
        }
    }
    root.add("rows", rows);
    root.addProperty("type", "table");
    JsonArray wrapper = new JsonArray();
    wrapper.add(root);
    return wrapper;
}
Also used : HashMap(java.util.HashMap) AbstractUserObject(org.netxms.client.users.AbstractUserObject) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) AbstractObject(org.netxms.client.objects.AbstractObject) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Alarm(org.netxms.client.events.Alarm) SimpleDateFormat(java.text.SimpleDateFormat) HashSet(java.util.HashSet) JsonParser(com.google.gson.JsonParser)

Example 25 with AbstractObject

use of org.netxms.client.objects.AbstractObject in project netxms by netxms.

the class SummaryTableAdHoc method create.

/* (non-Javadoc)
    * @see org.netxms.websvc.handlers.AbstractHandler#create(org.json.JSONObject)
    */
@Override
protected Object create(JSONObject data) throws Exception {
    NXCSession session = getSession();
    if (!session.isObjectsSynchronized())
        session.syncObjects();
    String objectFilter = JsonTools.getStringFromJson(data, "baseObject", null);
    log.debug("POST adhoc summaryTable: baseObject = " + objectFilter);
    JSONArray columnFilter = JsonTools.getJsonArrayFromJson(data, "columns", null);
    if (objectFilter == null || objectFilter.isEmpty() || columnFilter == null) {
        log.warn("POST adhoc summaryTable: no DciSummaryTableColumn table or no value for BaseObject");
        return createErrorResponse(RCC.INVALID_ARGUMENT);
    }
    long baseObjectId;
    try {
        baseObjectId = Long.parseLong(objectFilter);
    } catch (NumberFormatException ex) {
        AbstractObject obj = session.findObjectByName(objectFilter);
        if (obj != null)
            baseObjectId = obj.getObjectId();
        else
            baseObjectId = 0;
    }
    List<DciSummaryTableColumn> columns = new ArrayList<DciSummaryTableColumn>();
    for (int i = 0; i < columnFilter.length(); i++) {
        JSONObject obj = columnFilter.getJSONObject(i);
        columns.add(new DciSummaryTableColumn(JsonTools.getStringFromJson(obj, "columnName", ""), JsonTools.getStringFromJson(obj, "dciName", ""), JsonTools.getBooleanFromJson(obj, "isRegexp", false) ? DciSummaryTableColumn.REGEXP_MATCH : 0));
    }
    AggregationFunction agrFunc = JsonTools.getEnumFromJson(data, AggregationFunction.class, "aggregationFunction", null);
    Date startDate;
    Date endDate;
    long date = JsonTools.getLongFromJson(data, "startDate", -1);
    startDate = date > 0 ? new Date(date * 1000) : null;
    date = JsonTools.getLongFromJson(data, "endDate", -1);
    endDate = date > 0 ? new Date(date * 1000) : null;
    // end date
    boolean multiInstance = JsonTools.getBooleanFromJson(data, "multiInstance", true);
    Table table = session.queryAdHocDciSummaryTable(baseObjectId, columns, agrFunc, startDate, endDate, multiInstance);
    // create json
    JSONObject root = new JSONObject();
    JSONArray columnList = new JSONArray();
    JSONArray rowList = new JSONArray();
    String[] names = table.getColumnDisplayNames();
    for (int i = 0; i < names.length; i++) columnList.put(names[i]);
    root.put("columns", columnList);
    TableRow[] rows = table.getAllRows();
    for (int i = 0; i < rows.length; i++) {
        JSONArray row = new JSONArray();
        for (int j = 0; j < rows[i].size(); j++) row.put(rows[i].get(j).getValue());
        rowList.put(row);
    }
    root.put("rows", rowList);
    return new ResponseContainer("table", root);
}
Also used : NXCSession(org.netxms.client.NXCSession) Table(org.netxms.client.Table) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) Date(java.util.Date) AggregationFunction(org.netxms.client.constants.AggregationFunction) JSONObject(org.json.JSONObject) AbstractObject(org.netxms.client.objects.AbstractObject) TableRow(org.netxms.client.TableRow) DciSummaryTableColumn(org.netxms.client.datacollection.DciSummaryTableColumn) ResponseContainer(org.netxms.websvc.json.ResponseContainer)

Aggregations

AbstractObject (org.netxms.client.objects.AbstractObject)216 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)55 NXCSession (org.netxms.client.NXCSession)51 AbstractNode (org.netxms.client.objects.AbstractNode)31 PartInitException (org.eclipse.ui.PartInitException)27 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)26 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)25 Cluster (org.netxms.client.objects.Cluster)22 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)22 ArrayList (java.util.ArrayList)20 Node (org.netxms.client.objects.Node)20 GridData (org.eclipse.swt.layout.GridData)18 Composite (org.eclipse.swt.widgets.Composite)18 NetworkMapObject (org.netxms.client.maps.elements.NetworkMapObject)18 GridLayout (org.eclipse.swt.layout.GridLayout)15 Container (org.netxms.client.objects.Container)15 Interface (org.netxms.client.objects.Interface)12 Template (org.netxms.client.objects.Template)12 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 Point (org.eclipse.swt.graphics.Point)11