You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ol...@apache.org on 2016/06/02 08:51:04 UTC

ambari git commit: AMBARI-16871. Ams Alerts have misleading message if they can't access the metric (Miklos Gergely via oleewere)

Repository: ambari
Updated Branches:
  refs/heads/trunk 5416153e9 -> b49b3545d


AMBARI-16871. Ams Alerts have misleading message if they can't access the metric (Miklos Gergely via oleewere)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b49b3545
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b49b3545
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b49b3545

Branch: refs/heads/trunk
Commit: b49b3545db453116b217856740995096d0165806
Parents: 5416153
Author: Miklos Gergely <mg...@hortonworks.com>
Authored: Thu Jun 2 10:43:51 2016 +0200
Committer: oleewere <ol...@gmail.com>
Committed: Thu Jun 2 10:43:51 2016 +0200

----------------------------------------------------------------------
 .../src/main/python/ambari_agent/alerts/ams_alert.py        | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b49b3545/ambari-agent/src/main/python/ambari_agent/alerts/ams_alert.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/alerts/ams_alert.py b/ambari-agent/src/main/python/ambari_agent/alerts/ams_alert.py
index 00ecc93..70f100f 100644
--- a/ambari-agent/src/main/python/ambari_agent/alerts/ams_alert.py
+++ b/ambari-agent/src/main/python/ambari_agent/alerts/ams_alert.py
@@ -81,10 +81,10 @@ class AmsAlert(MetricAlert):
 
     if isinstance(self.metric_info, AmsMetric):
       raw_data_points, http_code = self._load_metric(alert_uri.is_ssl_enabled, host, port, self.metric_info)
-      if not raw_data_points and http_code in [200, 307]:
+      if not raw_data_points and http_code not in [200, 307]:
         collect_result = self.RESULT_UNKNOWN
         value_list.append('HTTP {0} response (metrics unavailable)'.format(str(http_code)))
-      elif not raw_data_points and http_code not in [200, 307]:
+      elif not raw_data_points and http_code in [200, 307]:
         raise Exception("[Alert][{0}] Unable to extract JSON from HTTP response".format(self.get_name()))
       else:
 
@@ -130,6 +130,8 @@ class AmsAlert(MetricAlert):
     except Exception, exception:
       if logger.isEnabledFor(logging.DEBUG):
         logger.exception("[Alert][{0}] Unable to retrieve metrics from AMS: {1}".format(self.get_name(), str(exception)))
+      status = response.status if 'response' in vars() else None
+      return (None, status)
     finally:
       if logger.isEnabledFor(logging.DEBUG):
         logger.debug("""
@@ -141,8 +143,7 @@ class AmsAlert(MetricAlert):
         try:
           conn.close()
         except:
-          logger.debug("[Alert][{0}] Unable to close URL connection to {1}".format
-                       (self.get_name(), url))
+          logger.debug("[Alert][{0}] Unable to close URL connection to {1}".format(self.get_name(), url))
     json_is_valid = True
     try:
       data_json = json.loads(data)