Search in sources :

Example 1 with MibObject

use of org.netxms.client.snmp.MibObject in project netxms by netxms.

the class SnmpTest method testMibFileDownload.

public void testMibFileDownload() throws Exception {
    final NXCSession session = connect(true);
    Date ts = session.getMibFileTimestamp();
    System.out.println("MIB file timestamp: " + ts.toString());
    File f = session.downloadMibFile();
    System.out.println("MIB file downloaded to: " + f.getPath() + " (size " + f.length() + " bytes)");
    session.disconnect();
    MibTree tree = new MibTree(f);
    assertNotNull(tree.getRootObject());
    MibObject[] objects = tree.getRootObject().getChildObjects();
    assertNotNull(objects);
    assertTrue(objects.length > 0);
    for (int i = 0; i < objects.length; i++) System.out.println(objects[i].getObjectId().toString() + " " + objects[i].getName() + " " + objects[i].getFullName());
    MibObject o = tree.findObject(SnmpObjectId.parseSnmpObjectId(".1.3.6.1.2.1.1.1"), true);
    assertNotNull(o);
    System.out.println("Found: " + o.getObjectId().toString() + " " + o.getName() + " " + o.getFullName());
    o = tree.findObject(SnmpObjectId.parseSnmpObjectId(".1.3.6.1.100.100.100"), false);
    assertNotNull(o);
    System.out.println("Found: " + o.getObjectId().toString() + " " + o.getName() + " " + o.getFullName());
    o = tree.findObject(SnmpObjectId.parseSnmpObjectId(".1.3.6.1.100.100.100"), true);
    assertNull(o);
}
Also used : MibObject(org.netxms.client.snmp.MibObject) File(java.io.File) MibTree(org.netxms.client.snmp.MibTree) Date(java.util.Date)

Example 2 with MibObject

use of org.netxms.client.snmp.MibObject in project netxms by netxms.

the class CreateSnmpDci method run.

/**
 * @see IActionDelegate#run(IAction)
 */
public void run(IAction action) {
    if (objects.size() == 0)
        return;
    MibObject mibObject = MibCache.findObject(objects.get(0).getName(), false);
    String description = (mibObject != null) ? mibObject.getName() : objects.get(0).getName();
    if (objects.size() > 1)
        // $NON-NLS-1$
        description += " @@instance@@";
    final CreateSnmpDciDialog dlg = new CreateSnmpDciDialog(shell, description);
    if (dlg.open() != Window.OK)
        return;
    final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
    final List<SnmpValue> values = new ArrayList<SnmpValue>(objects);
    // Get set of nodes
    final Set<AbstractNode> nodes = new HashSet<AbstractNode>();
    for (SnmpValue v : values) {
        AbstractNode node = (AbstractNode) session.findObjectById(v.getNodeId(), AbstractNode.class);
        if (node != null) {
            nodes.add(node);
        }
    }
    // Check what nodes requires DCI list lock
    final Map<Long, Boolean> lockRequired = new HashMap<Long, Boolean>(nodes.size());
    final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    for (AbstractNode n : nodes) {
        IViewReference ref = page.findViewReference(DataCollectionEditor.ID, Long.toString(n.getObjectId()));
        lockRequired.put(n.getObjectId(), !((ref != null) && (ref.getView(false) != null)));
    }
    new ConsoleJob(Messages.get().CreateSnmpDci_JobTitle, viewPart, Activator.PLUGIN_ID, null) {

        @Override
        protected String getErrorMessage() {
            return Messages.get().CreateSnmpDci_ErrorMessage;
        }

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            monitor.beginTask(Messages.get(getDisplay()).CreateSnmpDci_TaskTitle, values.size());
            for (SnmpValue v : values) {
                // $NON-NLS-1$
                final String description = dlg.getDescription().replaceAll("@@instance@@", Long.toString(v.getObjectId().getIdFromPos(v.getObjectId().getLength() - 1)));
                createDci(session, v, description, dlg.getPollingInterval(), dlg.getRetentionTime(), dlg.getDeltaCalculation(), lockRequired);
                monitor.worked(1);
            }
            monitor.done();
        }
    }.start();
}
Also used : NXCSession(org.netxms.client.NXCSession) AbstractNode(org.netxms.client.objects.AbstractNode) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) NXCException(org.netxms.client.NXCException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SnmpValue(org.netxms.client.snmp.SnmpValue) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) MibObject(org.netxms.client.snmp.MibObject) CreateSnmpDciDialog(org.netxms.ui.eclipse.datacollection.dialogs.CreateSnmpDciDialog) HashSet(java.util.HashSet)

Example 3 with MibObject

use of org.netxms.client.snmp.MibObject in project netxms by netxms.

the class MibObjectDetails method onManualOidChange.

/**
 * Handler for manual OID change
 */
private void onManualOidChange() {
    MibObject o = MibCache.findObject(oid.getText(), false);
    if ((o != null) && (mibTree != null)) {
        updateObjectId = false;
        mibTree.setSelection(o);
        updateObjectId = true;
    }
}
Also used : MibObject(org.netxms.client.snmp.MibObject)

Example 4 with MibObject

use of org.netxms.client.snmp.MibObject in project netxms by netxms.

the class MibExplorer method doWalk.

/**
 * Do SNMP walk
 */
private void doWalk() {
    if (walkActive || (currentNode == null))
        return;
    final MibObject object = mibBrowser.getSelection();
    if (object == null)
        return;
    walkActive = true;
    actionWalk.setEnabled(false);
    viewer.setInput(new SnmpValue[0]);
    walkData.clear();
    ConsoleJob job = new ConsoleJob(Messages.get().MibExplorer_WalkJob_Title, this, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            session.snmpWalk(currentNode.getObjectId(), object.getObjectId().toString(), MibExplorer.this);
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().MibExplorer_WalkJob_Error;
        }

        @Override
        protected void jobFinalize() {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    walkActive = false;
                    actionWalk.setEnabled(currentNode != null);
                }
            });
        }
    };
    job.setUser(false);
    job.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) MibObject(org.netxms.client.snmp.MibObject)

Example 5 with MibObject

use of org.netxms.client.snmp.MibObject in project netxms by netxms.

the class MibExplorer method createPartControl.

/* (non-Javadoc)
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
	 */
@Override
public void createPartControl(Composite parent) {
    // $NON-NLS-1$
    headerFont = new Font(parent.getDisplay(), "Verdana", 11, SWT.BOLD);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    parent.setLayout(layout);
    header = new CLabel(parent, SWT.BORDER);
    header.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    header.setFont(headerFont);
    header.setBackground(SharedColors.getColor(SharedColors.MIB_EXPLORER_HEADER_BACKGROUND, parent.getDisplay()));
    header.setForeground(SharedColors.getColor(SharedColors.MIB_EXPLORER_HEADER_TEXT, parent.getDisplay()));
    // $NON-NLS-1$
    header.setText((currentNode != null) ? currentNode.getObjectName() : "");
    SashForm splitter = new SashForm(parent, SWT.VERTICAL);
    splitter.setLayout(new FillLayout());
    splitter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    SashForm mibViewSplitter = new SashForm(splitter, SWT.HORIZONTAL);
    mibViewSplitter.setLayout(new FillLayout());
    mibBrowser = new MibBrowser(mibViewSplitter, SWT.BORDER);
    mibBrowser.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            MibObject object = mibBrowser.getSelection();
            details.setObject(object);
        }
    });
    details = new MibObjectDetails(mibViewSplitter, SWT.BORDER, true, mibBrowser);
    // Create result area
    resultArea = new Composite(splitter, SWT.BORDER);
    FormLayout formLayout = new FormLayout();
    resultArea.setLayout(formLayout);
    // Create filter area
    filterText = new FilterText(resultArea, SWT.BORDER);
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            onFilterModify();
        }
    });
    filterText.setCloseAction(new Action() {

        @Override
        public void run() {
            enableFilter(false);
            actionShowFilter.setChecked(initShowFilter);
        }
    });
    // Setup layout
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    ;
    fd.top = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    filterText.setLayoutData(fd);
    // walk results
    viewer = new TableViewer(resultArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    setupViewerColumns();
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new SnmpValueLabelProvider());
    filter = new SnmpWalkFilter();
    viewer.addFilter(filter);
    viewer.getTable().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            // $NON-NLS-1$
            WidgetHelper.saveColumnSettings(viewer.getTable(), Activator.getDefault().getDialogSettings(), "MibExplorer");
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            actionSelect.setEnabled(selection.size() == 1);
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            selectInTree();
        }
    });
    // Setup layout
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    ;
    fd.top = new FormAttachment(filterText, 0, SWT.BOTTOM);
    fd.bottom = new FormAttachment(100, 0);
    fd.right = new FormAttachment(100, 0);
    viewer.getControl().setLayoutData(fd);
    splitter.setWeights(new int[] { 70, 30 });
    createActions();
    contributeToActionBars();
    createTreePopupMenu();
    createResultsPopupMenu();
    activateContext();
    // Set initial focus to filter input line
    if (initShowFilter)
        filterText.setFocus();
    else
        // Will hide filter area correctly
        enableFilter(false);
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) DisposeListener(org.eclipse.swt.events.DisposeListener) ExportToCsvAction(org.netxms.ui.eclipse.actions.ExportToCsvAction) RefreshAction(org.netxms.ui.eclipse.actions.RefreshAction) Action(org.eclipse.jface.action.Action) SnmpValueLabelProvider(org.netxms.ui.eclipse.snmp.views.helpers.SnmpValueLabelProvider) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Font(org.eclipse.swt.graphics.Font) MibObjectDetails(org.netxms.ui.eclipse.snmp.widgets.MibObjectDetails) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) FilterText(org.netxms.ui.eclipse.widgets.FilterText) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) SnmpWalkFilter(org.netxms.ui.eclipse.snmp.views.helpers.SnmpWalkFilter) SashForm(org.eclipse.swt.custom.SashForm) MibBrowser(org.netxms.ui.eclipse.snmp.widgets.MibBrowser) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) MibObject(org.netxms.client.snmp.MibObject) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

MibObject (org.netxms.client.snmp.MibObject)8 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2 MibBrowser (org.netxms.ui.eclipse.snmp.widgets.MibBrowser)2 MibObjectDetails (org.netxms.ui.eclipse.snmp.widgets.MibObjectDetails)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Action (org.eclipse.jface.action.Action)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1