Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 f1383f236 -> a41608ec0


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/a41608ec
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a41608ec
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a41608ec

Branch: refs/heads/branch-2.4
Commit: a41608ec0d5bc395459bf17347b9f9cd89d3ebc7
Parents: f1383f2
Author: Miklos Gergely <mgerg...@hortonworks.com>
Authored: Thu Jun 2 10:43:51 2016 +0200
Committer: oleewere <oleew...@gmail.com>
Committed: Thu Jun 2 10:53:54 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/a41608ec/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)

Reply via email to