Search in sources :

Example 1 with MibTree

use of org.netxms.client.snmp.MibTree 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 MibTree

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

the class MibCache method getMibTree.

/**
 * @return the mibTree
 */
public static MibTree getMibTree() {
    synchronized (MUTEX) {
        if (mibTree != null)
            return mibTree;
        Location loc = Platform.getInstanceLocation();
        if (loc != null) {
            File targetDir;
            try {
                targetDir = new File(loc.getURL().toURI());
            } catch (URISyntaxException e) {
                targetDir = new File(loc.getURL().getPath());
            }
            // $NON-NLS-1$
            File mibFile = new File(targetDir, "netxms.mib");
            if (mibFile.exists()) {
                try {
                    mibTree = new MibTree(mibFile);
                } catch (Exception e) {
                    // $NON-NLS-1$
                    Activator.logError("Cannot load MIB file", e);
                }
            }
        }
        return (mibTree != null) ? mibTree : new MibTree();
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) File(java.io.File) MibTree(org.netxms.client.snmp.MibTree) SnmpObjectIdFormatException(org.netxms.client.snmp.SnmpObjectIdFormatException) URISyntaxException(java.net.URISyntaxException) Location(org.eclipse.osgi.service.datalocation.Location)

Aggregations

File (java.io.File)2 MibTree (org.netxms.client.snmp.MibTree)2 URISyntaxException (java.net.URISyntaxException)1 Date (java.util.Date)1 Location (org.eclipse.osgi.service.datalocation.Location)1 MibObject (org.netxms.client.snmp.MibObject)1 SnmpObjectIdFormatException (org.netxms.client.snmp.SnmpObjectIdFormatException)1