Search in sources :

Example 1 with Alarm

use of org.netxms.client.events.Alarm 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 2 with Alarm

use of org.netxms.client.events.Alarm 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 3 with Alarm

use of org.netxms.client.events.Alarm in project netxms by netxms.

the class AlarmList method terminateAlarms.

/**
 * Terminate selected alarms
 */
private void terminateAlarms() {
    IStructuredSelection selection = (IStructuredSelection) alarmViewer.getSelection();
    if (selection.isEmpty())
        return;
    final List<Long> alarmIds = new ArrayList<Long>(selection.size());
    for (Object o : selection.toList()) alarmIds.add(((Alarm) o).getId());
    new ConsoleJob(Messages.get().TerminateAlarm_JobTitle, viewPart, Activator.PLUGIN_ID, AlarmList.JOB_FAMILY) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final Map<Long, Integer> terminationFails = session.bulkTerminateAlarms(alarmIds);
            if (!terminationFails.isEmpty()) {
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        AlarmStateChangeFailureDialog dlg = new AlarmStateChangeFailureDialog(viewPart.getSite().getShell(), terminationFails);
                        if (dlg.open() == Window.OK) {
                            return;
                        }
                    }
                });
            }
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().TerminateAlarm_ErrorMessage;
        }
    }.start();
}
Also used : ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PartInitException(org.eclipse.ui.PartInitException) AlarmStateChangeFailureDialog(org.netxms.ui.eclipse.alarmviewer.dialogs.AlarmStateChangeFailureDialog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Alarm(org.netxms.client.events.Alarm) AbstractObject(org.netxms.client.objects.AbstractObject) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with Alarm

use of org.netxms.client.events.Alarm in project netxms by netxms.

the class AlarmList method acknowledgeAlarms.

/**
 * Acknowledge selected alarms
 *
 * @param sticky
 */
private void acknowledgeAlarms(final boolean sticky, final int time) {
    IStructuredSelection selection = (IStructuredSelection) alarmViewer.getSelection();
    if (selection.size() == 0)
        return;
    final Object[] alarms = selection.toArray();
    new ConsoleJob(Messages.get().AcknowledgeAlarm_JobName, viewPart, Activator.PLUGIN_ID, AlarmList.JOB_FAMILY) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            monitor.beginTask(Messages.get(getDisplay()).AcknowledgeAlarm_TaskName, alarms.length);
            for (Object o : alarms) {
                if (monitor.isCanceled())
                    break;
                if (o instanceof Alarm)
                    session.acknowledgeAlarm(((Alarm) o).getId(), sticky, time);
                monitor.worked(1);
            }
            monitor.done();
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().AcknowledgeAlarm_ErrorMessage;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Alarm(org.netxms.client.events.Alarm) AbstractObject(org.netxms.client.objects.AbstractObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Example 5 with Alarm

use of org.netxms.client.events.Alarm in project netxms by netxms.

the class AlarmList method showIssue.

/**
 * Show in web browser helpdesk ticket (issue) linked to selected alarm
 */
private void showIssue() {
    IStructuredSelection selection = (IStructuredSelection) alarmViewer.getSelection();
    if (selection.size() != 1)
        return;
    final long id = ((Alarm) selection.getFirstElement()).getId();
    new ConsoleJob(Messages.get().AlarmList_JobTitle_ShowTicket, viewPart, Activator.PLUGIN_ID, AlarmList.JOB_FAMILY) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final String url = session.getHelpdeskIssueUrl(id);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    UrlLauncher launcher = RWT.getClient().getService(UrlLauncher.class);
                    launcher.openURL(url);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().AlarmList_JobError_ShowTicket;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UrlLauncher(org.eclipse.rap.rwt.client.service.UrlLauncher) Alarm(org.netxms.client.events.Alarm) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

Alarm (org.netxms.client.events.Alarm)25 AbstractObject (org.netxms.client.objects.AbstractObject)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 PartInitException (org.eclipse.ui.PartInitException)8 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 List (java.util.List)3 NXCException (org.netxms.client.NXCException)3 NXCSession (org.netxms.client.NXCSession)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 NXCPMessage (org.netxms.base.NXCPMessage)2 AlarmComment (org.netxms.client.events.AlarmComment)2 AbstractNode (org.netxms.client.objects.AbstractNode)2 ZoneMember (org.netxms.client.objects.ZoneMember)2 AbstractUserObject (org.netxms.client.users.AbstractUserObject)2 SuppressLint (android.annotation.SuppressLint)1