public static void main(String[] args) throws FileNotFoundException { BasicConfigurator.configure(); Logger.getRootLogger().setLevel(Level.WARN); Mib2Events convertor = new Mib2Events(); convertor.parseCli(args); try { convertor.convert(); } catch (FileNotFoundException e) { printError(convertor.getMibLocation(), e); System.exit(1); } catch (IOException e) { printError(convertor.getMibLocation(), e); } catch (MibLoaderException e) { e.getLog().printTo(System.err); System.exit(1); } if (convertor.getMib().getLog().warningCount() > 0) { convertor.getMib().getLog().printTo(System.err); } PrintStream out = System.out; out.println( "<!-- Start of auto generated data from MIB: " + convertor.getMib().getName() + " -->"); try { convertor.printEvents(out); } catch (Throwable e) { printError(convertor.getMibLocation(), e); System.exit(1); } out.println( "<!-- End of auto generated data from MIB: " + convertor.getMib().getName() + " -->"); }
private void loadDirectory(String[] files, String path) throws Exception { StringBuilder currentPath = new StringBuilder(); for (int i = 0; i < files.length; i++) { if (!path.endsWith("/")) { currentPath.append(path).append("/"); } currentPath.append(files[i]); if (SingletonFSInterface.instance().isFile(new URI(currentPath.toString()))) // if it's a file { try { if (!files[i].startsWith(".")) { mibLoader.load(files[i]); } } catch (Exception e) { GlobalLogger.instance() .getApplicationLogger() .error(TextEvent.Topic.PROTOCOL, e, "ERROR : loading the MIBS files"); if (e instanceof MibLoaderException) { ((MibLoaderException) e).getLog().printTo(new PrintStream("../logs/snmpStack.log")); } } } else // if it's a directory, load it and all it's content { if (!files[i].startsWith(".")) { loadDirectory( SingletonFSInterface.instance().list(new URI(currentPath.toString())), currentPath.toString()); } } // reset currentPath currentPath.delete(0, currentPath.length()); } }
/** * Loads a MIB file from a specified source. * * @param src the MIB file or URL */ public void loadMib(String src) { String message = null; setStatus("Loading " + src + "..."); try { browser.loadMib(src); } catch (FileNotFoundException e) { message = "Failed to load " + e.getMessage(); } catch (IOException e) { message = "Failed to load " + src + ": " + e.getMessage(); } catch (MibLoaderException e) { message = "Failed to load " + src; ByteArrayOutputStream output = new ByteArrayOutputStream(); e.getLog().printTo(new PrintStream(output)); descriptionArea.append(output.toString()); } if (message != null) { JOptionPane.showMessageDialog(this, message, "MIB Loading Error", JOptionPane.ERROR_MESSAGE); } setStatus(null); }