/**
   * PollAPI's handle is obtained using the NmsUtil's getAPI() method. A schema to store the data
   * collected for the three dataIdentifieres namely IFINOCTETS,IFOUTOCTETS,IFERRORS of an agent for
   * a particular time in a single row of a table called 'WinNTtable' is created and added to the
   * database using the PollAPI. Then the table 'WintNTtable' is created corresponding to this
   * schema using the PollAPI's createTable() method. Finally this table is asscociated with all
   * PolledData whose policyName equals 'WindowsNT'
   */
  public Vector applyPollFilter(ManagedObject obj, Vector pdatasVect) {
    Vector pvector = pdatasVect;
    PolledData pd = null;

    if (flag) {
      try {
        // PollAPI's handle is obtained using NmsUtil's
        // getAPI() method.
        api = (PollAPI) NmsUtil.getAPI("PollAPI");
      } catch (Exception e) {
        System.out.println("Error occurred while getting PollAPI handle: " + e);
        e.printStackTrace();
      }

      try {
        // form the schema and create the WinNTtable.
        // Note: This schema is created for mysql database. User should
        // modify this schema depending upon the database.
        String schema =
            "create table <> (AGENT varchar(100),IFINOCTETS BIGINT, IFOUTOCTETS BIGINT, IFERRORS BIGINT,TIMEOFCOL varchar(100))";
        String tablename = "WinNTtable";
        api.addCreateSchema(tablename, schema);
        api.createTable("WinNTtable");
      } catch (Exception e) {
        System.out.println("Exception in creating Schema and adding table");
        e.printStackTrace();
      }
      // flag is set to false since table is created
      flag = false;
    }

    // The vector of PolledData objects is enumerated and checked for the
    // policyName. If it equals to 'WindowsNT, then the statsDataTableName
    // of the PolledData is set to "WinNTtable" so that all the data
    // collected for this PolledData would be stored in this table.

    for (Enumeration e = pvector.elements(); e.hasMoreElements(); ) {
      pd = (PolledData) e.nextElement();
      if (pd.getPolicyName().equals("WindowsNT")) {
        pd.setStatsDataTableName("WinNTtable");
      }
    }
    // finally return the PolledData vector after setting the table name
    // to all PolledData whose policyName equals "WindowsNT".
    return pvector;
  }
Ejemplo n.º 2
0
  /**
   * Sets the TabularData to the AaplicationTable
   *
   * @param data The TabularData to be set to the AaplicationTable
   */
  public void setAlarmTable(TabularData data) throws Exception {
    AgentException ae = null;

    for (Enumeration e = data.enumerate(); e.hasMoreElements(); ) {
      Object[] index = (Object[]) e.nextElement();
      CompositeData comp = data.getRow(index);

      if (table != null)
        entry =
            (AlarmEntry)
                Utilities.getEntryFromCompositeData(table, comp, indexNames, instrClassName);
      else if (vec != null)
        entry =
            (AlarmEntry) Utilities.getEntryFromCompositeData(vec, comp, indexNames, instrClassName);

      if (comp.getOperationType().equals(CompositeData.CREATED)) { // create new entry

        if (entry != null)
          throw new AgentException("Row already exist", CommonUtils.ROWCREATIONFAILED); // no i18n
        entry = new AlarmEntry();

        if (table != null) table.put(index, entry);
        else if (vec != null) vec.addElement(entry);
        for (Enumeration ce = comp.enumerate(); ce.hasMoreElements(); ) {
          String key = (String) ce.nextElement();
          try {
            Utilities.setField(entry, instrClassName, key, comp.getDataItem(key));
          } catch (AgentException aexp) {
            ae = aexp;
          }
        }
      } else if (comp.getOperationType().equals(CompositeData.DELETED)) {

        if (table != null) {
          for (Enumeration en = table.keys(); en.hasMoreElements(); ) {
            Object keyObject = en.nextElement();
            if (entry.equals(table.get(keyObject))) table.remove(keyObject);
          }
        } else if (vec != null)
          if (!vec.removeElement(entry))
            throw new AgentException("Invalid Index", CommonUtils.INVALIDINDEX); // no i18n
        data.deleteRow(index);
      } else if (comp.getOperationType().equals(CompositeData.MODIFIED)) {

        for (Enumeration ce = comp.enumerate(); ce.hasMoreElements(); ) {
          String key = (String) ce.nextElement();
          if (!comp.isModified(key)) continue;
          try {

            Utilities.setField(entry, instrClassName, key, comp.getDataItem(key));
          } catch (AgentException aexp) {
            ae = aexp;
          }
        }
      }

      comp.setOperationType(CompositeData.NOCHANGES);
    }

    if (ae != null) throw ae;
  }