Creating UsersMonitor

The sample project solgeneossample comes with a sample data view called Users, which is generated by UsersMonitor. The Users view displays the currently configured CLI users on the event broker.

To create UsersMonitor, do the following:

  1. Untar the example package, named sol-geneossample-<version>.tar.gz.
  2. Create a monitor class called UsersMonitor.java that extends BaseMonitor, and place it under the src directory with the proper package structure.

    For this sample, the package structure for UsersMonitor.java is com/solacesystems/solgeneos/sample/monitor.

  3. In UsersMonitor.java, override onPostInitialize() method. The sample does the following:
    1. Retrieve management IP address, port, username, and password properties from Solace Geneos Agent’s global properties:

      // retrieve SEMP over HTTP properties from global properties
      Properties props = SolGeneosAgent.onlyInstance.getGlobalProperties();
      String host = props.getProperty(MGMT_IP_ADDRESS_PROPERTY_NAME);
      int port = Integer.parseInt(props.getProperty(MGMT_PORT_PROPERTY_NAME));
      String username = props.getProperty(MGMT_USERNAME_PROPERTY_NAME);
      String password = SolGeneosAgent.onlyInstance.getEncryptedProperty(MGMT_ENCRYPTED_PASSWORD_PROPERTY_NAME,MGMT_PASSWORD_PROPERTY_NAME);
    2. Initialize an HTTP client, which will be used for polling data using SEMP:

      // create a http client
      m_httpClient = new HttpClient(new SimpleHttpConnectionManager());
       
      // set connection host configuration
      HostConfiguration hostConfig = new HostConfiguration();
      hostConfig.setHost(host, port);
      m_httpClient.setHostConfiguration(hostConfig);
       
      // set connection credential
      m_httpClient.getState().setCredentials(
      new AuthScope(host, port),
      new UsernamePasswordCredentials(username, password))
    3. Initialize a SAX parser UsersSEMPParser used for parsing SEMP reply. A sample parser implementation is under com/solacesystems/solgeneos/sample/util. UsersSEMPParser.java is located in src/com/solacesystems/solgeneos/sample/monitor.

      // create SEMP parser
      m_parser = new UsersSEMPParser();
  4. In UsersMonitor.java, override onCollect() method to collect data from the event broker using SEMP, format SEMP reply into NetProbe acceptable format, populate the Users view’s content and return the monitor's next valid state (State.REPORTING_QUEUE). The sample does the following:
    1. Create view headlines by reading properties from user_samples.properties as the example to show how to use user‑defined properties:

      String viewCreator = "";
      UserPropertiesConfig userPropsConfig = SolGeneosAgent.onlyInstance.
                            getUserPropertiesConfig(USER_PROPERTIES_FILE_NAME);
      if (userPropsConfig != null && userPropsConfig.getProperties() != null) {
             viewCreator = 
             userPropsConfig.getProperties().getProperty(VIEW_CREATOR);
      }
       
      LinkedHashMap<String, Object> headlines = 
             new LinkedHashMap<String, Object>();
      headlines.put("Creator", viewCreator);
    2. Send a SEMP request over HTTP using the http client created in step 2:

      PostMethod post = new PostMethod(HTTP_REQUEST_URI);
      post.setRequestHeader(HEADER_CONTENT_TYPE_UTF8);
      post.setRequestEntity(new             ByteArrayRequestEntity(SHOW_USERS_REQUEST.getBytes("UTF-8")));
      String respBody = "";
      try {
             int result = m_httpClient.executeMethod(post);
             String statusText = post.getStatusText();
             if (result != 200) {
               throw new Exception("Error occurred while sending request: "
                 + result + " - " + statusText);
       
             respBody = post.getResponseBodyAsString();
      } finally {
             post.releaseConnection();
      }
    3. Use the SAX parser created in step 2 to parse the SEMP reply inside the HTTP response:

      m_parser.parse(respBody);
      Vector<Object> tableContent = m_parser.getTableContent();
    4. Populate the view content:

      TreeMap<String, View> viewMap = getViewMap();
      if (viewMap != null && viewMap.size() > 0) {
          for (Iterator<String> viewIt = viewMap.keySet().iterator();
             viewIt.hasNext();) {
                    view view = viewMap.get(viewIt.next());
                   if (view.isActive()) {
                           view.setHeadlines(headlines);
                           view.setTableContent(tableContent);
                    
             }
      }
    1. Return next monitor state State.REPORTING_QUEUE.
  5. Create a monitor property file called UsersMonitor.properties, and place it in the config directory. A sample monitor property file called monitor.properties.template is bundled with the agent distribution under the templates directory. Monitor developers can reference this file for all the monitor level and view level property names supported by the agent.
    1. Set monitorClassName to the full class name of the monitor class, for example: monitorClassName=com.solacesystems.solgeneos.sample.monitor.UsersMonitor.
    2. Set samplingRate to a reasonable value (for example, samplingRate=30).
    3. Set view name to view.v0.viewName=Users.
  6. Run “ant dist”.
  7. Copy property files from the target event broker directory _antDist/config directory to /usr/sw/solgeneos/config.
  8. Copy Jar files from _antDist/lib directory to the target event broker directory /usr/sw/solgeneos/monitors.
  9. Restart Solace Geneos Agent. The Users view should show up in the Active Console.