Advertisement
Guest User

NagiosCheck

a guest
Oct 5th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.94 KB | None | 0 0
  1. package com.quantros.qsupport;
  2. import java.util.Iterator;
  3. import java.util.List;
  4. import java.util.Vector;
  5.  
  6. import javax.servlet.ServletContext;
  7. import javax.servlet.ServletException;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import javax.servlet.http.HttpSession;
  11.  
  12. import com.infoobjectsinc.util.DBMSConnection;
  13. import com.infoobjectsinc.util.QGlobals;
  14. import com.infoobjectsinc.util.QuantrosException;
  15. import com.quantros.AppModules.IOFunctions;
  16. import com.quantros.AppModules.ProcessDataHandler;
  17. import com.quantros.platform.db.QJdbcTemplate;
  18.  
  19. /**
  20.  * @author Khai Doan
  21.  *
  22.  */
  23. public class NagiosChecks implements ProcessDataHandler {
  24.     private Vector errors;
  25.     private QJdbcTemplate dbtemplate;
  26.    
  27.     /**
  28.      * This is a plugin for Nagios, a network / service monitoring tool
  29.      * @param req request object
  30.      * @param res  response object
  31.      * @param servctxt ServletContext object
  32.      * @throws ServletException and IOException
  33.      */
  34.     public void processData(HttpServletRequest req, HttpServletResponse res,
  35.             ServletContext servctxt) throws ServletException, QuantrosException,
  36.             Exception {
  37.         try{
  38.             HttpSession session = req.getSession(true);
  39.             IOFunctions iof = new IOFunctions(QGlobals.debugger);
  40.             this.errors = new Vector();
  41.  
  42.             String type = iof.getParameter(req, "type", "");
  43.            
  44.             this.dbtemplate = new QJdbcTemplate(
  45.                     DBMSConnection.getDataSource("SupportDataSource"),
  46.                     QGlobals.debugger,
  47.                     "NagiosChecks: processData");
  48.            
  49.             if (! type.equals("")) {
  50.                 this.check_is_file_uploaded();
  51.             } else {
  52.                 this.check_copy_data_from_production_to_training();
  53.                 this.check_product_activation();
  54.                 this.check_provider_upload();
  55.                 this.check_generic_batch_upload();
  56.                 this.check_save_or_clone_requests();
  57.             }
  58.            
  59.             String errstr = this.join(this.errors, "\n");
  60.             res.setContentType("text/html");
  61.             String message = "";
  62.             if (errstr.equalsIgnoreCase("")) {
  63.                 message = "<p>ALL CHECKS SUCCESSFUL.</p>";
  64.             } else {
  65.                 message = "<pre>" + errstr + "</pre>";
  66.             }          
  67.             res.getWriter().print("<html><head></head><body>" + message + "<iframe style='width: 100%; border:0px;' src='/MicroStrategy/plugins/CustomESM/jsp/AuditLogCheck.jsp'></iframe></body></html>");
  68.         } catch(Exception e) {
  69.             QGlobals.debugger.error("NavigationTree", "processData",    e);
  70.             throw new QuantrosException(e);
  71.         }
  72.        
  73.     }
  74.    
  75.     // Join a list of strings
  76.     private String join(Vector v, String separator) {
  77.         StringBuffer buffer = new StringBuffer();
  78.         Iterator iter = v.iterator();
  79.         while (iter.hasNext()) {
  80.             buffer.append(iter.next());
  81.             if (iter.hasNext()) {
  82.                 buffer.append(separator);
  83.             }
  84.         }
  85.         return buffer.toString();
  86.     }
  87.  
  88.     private void check_copy_data_from_production_to_training() throws Exception {
  89.         String sql = "SELECT * FROM SUPPORT.LAST_PRODUCTION_TO_TRAINING WHERE LAST_COPIED_TIME < SYSDATE - INTERVAL '30' MINUTE";
  90.         List list = this.dbtemplate.QueryForList(sql);
  91.         boolean lagging = false;
  92.         if (list.size() > 0) {
  93.             lagging = true;
  94.         }      
  95.         sql = "SELECT * FROM SUPPORT.SYNC_DATA_SQL WHERE ADDDATE < SYSDATE - INTERVAL '30' MINUTE";
  96.         list = this.dbtemplate.QueryForList(sql);
  97.         if (list.size() > 0) {
  98.             lagging = true;
  99.         }
  100.         if (lagging) {
  101.             this.errors.add("The background process for copying data from production to training and Production(PSOM) is lagging behind or not running at all.");
  102.         }
  103.     }
  104.    
  105.     private void check_product_activation() throws Exception {
  106.         String sql = "SELECT * FROM SUPPORT.ACTIVATIONSCHEDULE WHERE STATUS != 'C' AND RELEASE_DATE < SYSDATE - INTERVAL '8' HOUR AND ADDDATE < SYSDATE - INTERVAL '1' HOUR";
  107.         List list = this.dbtemplate.QueryForList(sql);
  108.         if (list.size() > 0) {
  109.             this.errors.add("The background process for activating products is not working appropriately.");
  110.         }      
  111.     }
  112.    
  113.     private void check_provider_upload() throws Exception {
  114.         /*
  115.          * In the SUPPORT.QSUP_PROVIDER_INFO_UPLOAD table, we only have one date column (the UPLOAD_DATE column).
  116.          * For the provider upload tool, we do not have ability to schedule when the file should be process.  We always process
  117.          * the file that same night it was uploaded.  The UPLOAD_DATE column holds the time that the file
  118.          * was uploaded.  This is different from product activation.  Therefore, here we have to remove the time portion
  119.          * and add one day to our query
  120.          */
  121.         String sql = "SELECT * FROM SUPPORT.QSUP_PROVIDER_INFO_UPLOAD WHERE (STATUS='P') AND (TO_DATE(TRUNC(UPLOAD_DATE)) + 1 < SYSDATE - INTERVAL '8' HOUR)";
  122.         List list = this.dbtemplate.QueryForList(sql);
  123.         if (list.size() > 0) {
  124.             this.errors.add("The background process for provider upload is not working appropriately.");
  125.         }
  126.     }
  127.  
  128.     private void check_homepage_publish() throws Exception {
  129.         String sql = "SELECT * FROM SUPPORT.HOMEPAGE_PUBLISH_SCHEDULE WHERE STATUS != 'C' AND RELEASEDATE < SYSDATE - INTERVAL '8' HOUR";
  130.         List list = this.dbtemplate.QueryForList(sql);
  131.         if (list.size() > 0) {
  132.             this.errors.add("The background process for publishing homepage is not working appropriately.");
  133.         }      
  134.     }
  135.    
  136.     private void check_is_file_uploaded() throws Exception {
  137.         String sql = "SELECT * FROM SUPPORT.GENERIC_FILE_UPLOAD WHERE STATUS IN ('UPLOADED')";     
  138.         List list = this.dbtemplate.QueryForList(sql);
  139.         if (list.size() > 0) {
  140.             this.errors.add("A QSupport user has just uploaded an Excel file.  Look at the SUPPORT.GENERIC_FILE_UPLOAD for details, and do appropriate thing.");
  141.             return;
  142.         }
  143.     }
  144.    
  145.     private void check_generic_batch_upload() throws Exception {
  146.         String sql = "SELECT * FROM SUPPORT.GENERIC_FILE_UPLOAD WHERE STATUS IN ('UPLOADED','PARSING STARTED') AND MODDATE < SYSDATE - INTERVAL '1' HOUR";
  147.         List list = this.dbtemplate.QueryForList(sql);
  148.         if (list.size() > 0) {
  149.             this.errors.add("One of the background processes that process the SUPPORT.GENERIC_FILE_UPLOAD table is not working appropriately.  There are upload jobs that have had the status of UPLOADED or 'PARSING STARTED' for more than 2 hours.");
  150.             return;
  151.         }
  152.         sql = "SELECT * FROM SUPPORT.GENERIC_FILE_UPLOAD WHERE STATUS IN ('PARSING COMPLETED') AND MODDATE < SYSDATE - INTERVAL '24' HOUR";
  153.         if (list.size() > 0) {
  154.             this.errors.add("One of the background processes that process the SUPPORT.GENERIC_FILE_UPLOAD table is not working appropriately.  There are jobs that have had the status of 'PARSING COMPLETED' for more than 24 hours.  Is this a large facilities upload job such that it is causing the product activation to take more than 24 hours to activate all the included products for all the included facilities?");
  155.             return;
  156.         }
  157.     }
  158.    
  159.     private void check_save_or_clone_requests() throws Exception {
  160.         String sql = "SELECT * FROM SUPPORT.CLONE_REQUESTS WHERE STATUS = 'REQUESTED' AND ADDDATE < SYSDATE - INTERVAL '2' HOUR";
  161.         List list = this.dbtemplate.QueryForList(sql);
  162.         if (list.size() > 0) {
  163.             this.errors.add("The background process SaveOrClone is not working appropriately or is lagging behind.");
  164.         }
  165.     }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement