class DatabaseConsistencyCheckHelper {

  static Map<String, String>  checkForStalealertdefs () {
    Configuration conf = injector.getInstance(Configuration.class);
    Map<String, String> alertInfo = new HashMap<>();
    LOG.info("Checking to ensure there is no stale alert definitions");

    ensureConnection();

    String STALE_ALERT_DEFINITIONS = "select definition_name, service_name from alert_definition where service_name not in " +
            "(select service_name from clusterservices) and service_name not in ('AMBARI')";

    ResultSet rs = null;
    Statement statement;

    try {
      statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
      rs = statement.executeQuery(STALE_ALERT_DEFINITIONS);
      if (rs != null) {
        while (rs.next()) {
          alertInfo.put(rs.getString("definition_name"),rs.getString("service_name"));
        }
        if (!alertInfo.isEmpty()){
          String alertInfoStr = "";
          for (Map.Entry<String, String> entry : alertInfo.entrySet()) {
            alertInfoStr = entry.getKey() + "(" + entry.getValue() + ")" ;
          }
          warning("You have Alerts that are not mapped with any services : {}.Run --auto-fix-database to fix "  +
                  "this automatically. Please backup Ambari Server database before running --auto-fix-database.", alertInfoStr);
        }
      }
    } catch (SQLException e) {
      warning("Exception occurred during checking for stale alert definitions: ", e);
    } finally {
      if (rs != null) {
        try {
          rs.close();
        } catch (SQLException e) {
          LOG.error("Exception occurred during  checking for stale alert definitions: ", e);
        }
      }
    }
    return alertInfo;
  }

}