Exemplo n.º 1
0
  /**
   * performUpdate
   *
   * @param owner a {@link java.lang.String} object.
   * @param repository a {@link java.io.File} object.
   * @param value a {@link org.opennms.netmgt.snmp.SnmpValue} object.
   * @return a boolean.
   */
  public boolean performUpdate(String owner, File repository, SnmpValue value) {

    String val = getStorableValue(value);

    String collectionName = m_collectionName;
    int step = DataCollectionConfigFactory.getInstance().getStep(collectionName);
    List<String> rraList = DataCollectionConfigFactory.getInstance().getRRAList(collectionName);
    boolean result = false;
    try {
      RrdUtils.createRRD(
          owner,
          repository.getAbsolutePath(),
          getName(),
          step,
          getType(),
          getHeartbeat(),
          getMin(),
          getMax(),
          rraList);

      RrdUtils.updateRRD(owner, repository.getAbsolutePath(), getName(), val);
    } catch (RrdException e) {
      result = true;
    }
    return result;
  }
Exemplo n.º 2
0
  /**
   * Creates a the rrd file from the rrdDefinition. Since this definition is really just the create
   * command string it just executes it.
   *
   * @param createCommand a {@link java.lang.String} object.
   * @throws java.lang.Exception if any.
   */
  @Override
  public void createFile(CreateCommand createCommand, Map<String, String> attributeMappings)
      throws Exception {
    if (createCommand == null) {
      LOG.debug("createRRD: skipping RRD file");
      return;
    }
    LOG.debug("Executing: rrdtool {}", createCommand.toString());
    Interface.launch(createCommand.toString());

    String filenameWithoutExtension = createCommand.filename.replace(RrdUtils.getExtension(), "");
    int lastIndexOfSeparator = filenameWithoutExtension.lastIndexOf(File.separator);

    RrdUtils.createMetaDataFile(
        filenameWithoutExtension.substring(0, lastIndexOfSeparator),
        filenameWithoutExtension.substring(lastIndexOfSeparator),
        attributeMappings);
  }
  @Before
  public void setUp() throws Exception {
    MockLogAppender.setupLogging();
    MockDatabase db = new MockDatabase();
    DataSourceFactory.setInstance(db);

    RrdUtils.setStrategy(m_strategy);

    m_provisioner = new OpenNMSProvisioner();

    m_eventManager = new MockEventIpcManager();
    m_provisioner.setEventManager(m_eventManager);

    m_capsdConfig = new TestCapsdConfigManager(CAPSD_CONFIG);
    CapsdConfigFactory.setInstance(m_capsdConfig);

    m_pollerConfig = new TestPollerConfigManager(POLLER_CONFIG, "localhost", false);
    PollerConfigFactory.setInstance(m_pollerConfig);

    m_provisioner.setCapsdConfig(m_capsdConfig);
    m_provisioner.setPollerConfig(m_pollerConfig);

    InputStream configStream =
        ConfigurationTestUtils.getInputStreamForConfigFile("opennms-server.xml");
    OpennmsServerConfigFactory onmsSvrConfig = new OpennmsServerConfigFactory(configStream);
    configStream.close();
    OpennmsServerConfigFactory.setInstance(onmsSvrConfig);

    configStream = ConfigurationTestUtils.getInputStreamForConfigFile("database-schema.xml");
    DatabaseSchemaConfigFactory.setInstance(new DatabaseSchemaConfigFactory(configStream));
    configStream.close();

    configStream =
        ConfigurationTestUtils.getInputStreamForResource(
            this, "/org/opennms/netmgt/capsd/collectd-configuration.xml");
    CollectdConfigFactory.setInstance(
        new CollectdConfigFactory(
            configStream, onmsSvrConfig.getServerName(), onmsSvrConfig.verifyServer()));
    configStream.close();

    JdbcTemplate jdbcTemplate = new JdbcTemplate(db);

    m_syncer = new JdbcCapsdDbSyncer();
    m_syncer.setJdbcTemplate(jdbcTemplate);
    m_syncer.setOpennmsServerConfig(OpennmsServerConfigFactory.getInstance());
    m_syncer.setCapsdConfig(m_capsdConfig);
    m_syncer.setPollerConfig(m_pollerConfig);
    m_syncer.setCollectdConfig(CollectdConfigFactory.getInstance());
    m_syncer.setNextSvcIdSql(db.getNextServiceIdStatement());
    m_syncer.afterPropertiesSet();

    m_syncer.syncServices();
    m_provisioner.setCapsdDbSyncer(m_syncer);
  }
Exemplo n.º 4
0
  /** {@inheritDoc} */
  @Override
  public CreateCommand createDefinition(
      String creator,
      String directory,
      String rrdName,
      int step,
      List<RrdDataSource> dataSources,
      List<String> rraList)
      throws Exception {
    File f = new File(directory);
    f.mkdirs();

    String fileName = directory + File.separator + rrdName + RrdUtils.getExtension();

    if (new File(fileName).exists()) {
      LOG.debug(
          "createDefinition: filename [{}] already exists returning null as definition", fileName);
      return null;
    }

    StringBuffer parameter = new StringBuffer();

    parameter.append(" --start=" + (System.currentTimeMillis() / 1000L - 10L));

    parameter.append(" --step=" + step);

    for (RrdDataSource dataSource : dataSources) {
      parameter.append(" DS:");
      parameter.append(dataSource.getName()).append(':');
      parameter.append(dataSource.getType()).append(":");
      parameter.append(dataSource.getHeartBeat()).append(':');
      parameter.append(dataSource.getMin()).append(':');
      parameter.append(dataSource.getMax());
    }

    for (String rra : rraList) {
      parameter.append(' ');
      parameter.append(rra);
    }

    return new CreateCommand(fileName, parameter.toString());
  }
  /**
   * Sets the up.
   *
   * @throws Exception the exception
   */
  @Before
  public void setUp() throws Exception {
    FileUtils.deleteDirectory(new File(TEST_SNMP_DIRECTORY));
    MockLogAppender.setupLogging();

    System.setProperty("org.opennms.rrd.usetcp", "false");
    System.setProperty("org.opennms.rrd.usequeue", "false");
    RrdUtils.setStrategy(new JRobinRrdStrategy());

    m_collectionAgent = EasyMock.createMock(CollectionAgent.class);
    EasyMock.expect(m_collectionAgent.getNodeId()).andReturn(1).anyTimes();
    EasyMock.expect(m_collectionAgent.getHostAddress()).andReturn("127.0.0.1").anyTimes();
    EasyMock.expect(m_collectionAgent.getStorageDir()).andReturn(new File("1")).anyTimes();
    m_eventProxy = EasyMock.createMock(EventProxy.class);

    m_xmlCollectionDao = new XmlDataCollectionConfigDaoJaxb();
    Resource resource = new FileSystemResource(getXmlConfigFileName());
    m_xmlCollectionDao.setConfigResource(resource);
    m_xmlCollectionDao.afterPropertiesSet();
    MockDocumentBuilder.setXmlFileName(getXmlSampleFileName());

    EasyMock.replay(m_collectionAgent, m_eventProxy);
  }
Exemplo n.º 6
0
  @Before
  public void setUp() throws Exception {
    m_assertLevel = Level.WARN;

    // System.setProperty("mock.logLevel", "DEBUG");
    // System.setProperty("mock.debug", "true");
    MockUtil.println("------------ Begin Test  --------------------------");
    MockLogAppender.setupLogging();

    m_network = new MockNetwork();
    m_network.setCriticalService("ICMP");
    m_network.addNode(1, "Router");
    m_network.addInterface("192.168.1.1");
    m_network.addService("ICMP");
    m_network.addService("SMTP");
    m_network.addService("SNMP");
    m_network.addInterface("192.168.1.2");
    m_network.addService("ICMP");
    m_network.addService("SMTP");
    m_network.addNode(2, "Server");
    m_network.addInterface("192.168.1.3");
    m_network.addService("ICMP");
    m_network.addService("HTTP");
    m_network.addService("SMTP");
    m_network.addService("SNMP");
    m_network.addNode(3, "Firewall");
    m_network.addInterface("192.168.1.4");
    m_network.addService("SMTP");
    m_network.addService("HTTP");
    m_network.addInterface("192.168.1.5");
    m_network.addService("SMTP");
    m_network.addService("HTTP");
    m_network.addNode(4, "DownNode");
    m_network.addInterface("192.168.1.6");
    m_network.addService("SNMP");
    //		m_network.addInterface("fe80:0000:0000:0000:0231:f982:0123:4567");
    //		m_network.addService("SNMP");

    m_db = new MockDatabase();
    m_db.populate(m_network);
    DataSourceFactory.setInstance(m_db);

    //		DemandPollDao demandPollDao = new DemandPollDaoHibernate(m_db);
    //		demandPollDao.setAllocateIdStmt(m_db
    //				.getNextSequenceValStatement("demandPollNxtId"));
    //		m_demandPollDao = demandPollDao;

    m_pollerConfig = new MockPollerConfig(m_network);
    m_pollerConfig.setNextOutageIdSql(m_db.getNextOutageIdStatement());
    m_pollerConfig.setNodeOutageProcessingEnabled(true);
    m_pollerConfig.setCriticalService("ICMP");
    m_pollerConfig.addPackage("TestPackage");
    m_pollerConfig.addDowntime(1000L, 0L, -1L, false);
    m_pollerConfig.setDefaultPollInterval(1000L);
    m_pollerConfig.populatePackage(m_network);
    m_pollerConfig.addPackage("TestPkg2");
    m_pollerConfig.addDowntime(1000L, 0L, -1L, false);
    m_pollerConfig.setDefaultPollInterval(2000L);
    m_pollerConfig.addService(m_network.getService(2, "192.168.1.3", "HTTP"));

    m_anticipator = new EventAnticipator();
    m_outageAnticipator = new OutageAnticipator(m_db);

    m_eventMgr = new MockEventIpcManager();
    m_eventMgr.setEventWriter(m_db);
    m_eventMgr.setEventAnticipator(m_anticipator);
    m_eventMgr.addEventListener(m_outageAnticipator);
    m_eventMgr.setSynchronous(false);

    QueryManager queryManager = new DefaultQueryManager();
    queryManager.setDataSource(m_db);

    DefaultPollContext pollContext = new DefaultPollContext();
    pollContext.setEventManager(m_eventMgr);
    pollContext.setLocalHostName("localhost");
    pollContext.setName("Test.DefaultPollContext");
    pollContext.setPollerConfig(m_pollerConfig);
    pollContext.setQueryManager(queryManager);

    PollableNetwork network = new PollableNetwork(pollContext);

    m_poller = new Poller();
    m_poller.setDataSource(m_db);
    m_poller.setEventManager(m_eventMgr);
    m_poller.setNetwork(network);
    m_poller.setQueryManager(queryManager);
    m_poller.setPollerConfig(m_pollerConfig);
    m_poller.setPollOutagesConfig(m_pollerConfig);

    MockOutageConfig config = new MockOutageConfig();
    config.setGetNextOutageID(m_db.getNextOutageIdStatement());

    RrdUtils.setStrategy(new NullRrdStrategy());

    // m_outageMgr = new OutageManager();
    // m_outageMgr.setEventMgr(m_eventMgr);
    // m_outageMgr.setOutageMgrConfig(config);
    // m_outageMgr.setDbConnectionFactory(m_db);

  }
Exemplo n.º 7
0
 /**
  * getRrdSuffix
  *
  * @return a {@link java.lang.String} object.
  */
 public static String getRrdSuffix() {
   return RrdUtils.getExtension();
 }
Exemplo n.º 8
0
  /**
   * fetchLastValue
   *
   * @param latIface a {@link org.opennms.netmgt.threshd.LatencyInterface} object.
   * @param latParms a {@link org.opennms.netmgt.threshd.LatencyParameters} object.
   * @return a {@link java.lang.Double} object.
   * @throws org.opennms.netmgt.threshd.ThresholdingException if any.
   */
  public Double fetchLastValue(LatencyInterface latIface, LatencyParameters latParms)
      throws ThresholdingException {
    // Assume that this only happens on a simple "Threshold", not an "Expression"
    // If it is an Expression, then we don't yet know what to do - this will likely just fail with
    // some sort of exception.
    // perhaps we should figure out how to expand it (or at least use code elsewhere to do so
    // sensibly)
    String datasource = getDataSourceExpression();

    // Use RRD strategy to "fetch" value of the datasource from the RRD file
    Double dsValue = null;
    try {
      if (getDatasourceType().equals("if")) {
        if (log().isDebugEnabled()) {
          log().debug("Fetching last value from dataSource '" + datasource + "'");
        }

        File rrdFile = new File(latIface.getLatencyDir(), datasource + RrdUtils.getExtension());
        if (!rrdFile.exists()) {
          log().info("rrd file " + rrdFile + " does not exist");
          return null;
        }

        if (!rrdFile.canRead()) {
          log().error("Unable to read existing rrd file " + rrdFile);
          return null;
        }

        if (latParms.getRange() == 0) {
          dsValue =
              RrdUtils.fetchLastValue(
                  rrdFile.getAbsolutePath(), datasource, latParms.getInterval());
        } else {
          dsValue =
              RrdUtils.fetchLastValueInRange(
                  rrdFile.getAbsolutePath(),
                  datasource,
                  latParms.getInterval(),
                  latParms.getRange());
        }
      } else {
        throw new ThresholdingException(
            "expr types not yet implemented", LatencyThresholder.THRESHOLDING_FAILED);
      }

      if (log().isDebugEnabled()) {
        log().debug("Last value from dataSource '" + datasource + "' was " + dsValue);
      }
    } catch (NumberFormatException nfe) {
      log()
          .warn(
              "Unable to convert retrieved value for datasource '"
                  + datasource
                  + "' to a double, skipping evaluation.");
    } catch (RrdException e) {
      log()
          .error(
              "An error occurred retriving the last value for datasource '"
                  + datasource
                  + "': "
                  + e,
              e);
    }

    return dsValue;
  }