浏览代码

AMBARI-8755. Oozie server check alert fails in secured mode (aonishuk)

Andrew Onishuk 10 年之前
父节点
当前提交
ec37c603c9
共有 25 个文件被更改,包括 220 次插入201 次删除
  1. 27 16
      ambari-agent/src/main/python/ambari_agent/alerts/script_alert.py
  2. 3 1
      ambari-agent/src/test/python/ambari_agent/TestAlerts.py
  3. 1 1
      ambari-server/src/main/resources/common-services/AMS/0.1.0/alerts.json
  4. 0 0
      ambari-server/src/main/resources/common-services/AMS/0.1.0/package/alerts/alert_ambari_metrics_monitor.py
  5. 1 1
      ambari-server/src/main/resources/common-services/FLUME/1.4.0.2.0/alerts.json
  6. 0 0
      ambari-server/src/main/resources/common-services/FLUME/1.4.0.2.0/package/alerts/alert_flume_agent_status.py
  7. 2 2
      ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/alerts.json
  8. 0 0
      ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_checkpoint_time.py
  9. 0 0
      ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_ha_namenode_health.py
  10. 2 2
      ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/alerts.json
  11. 4 7
      ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/alerts/alert_hive_thrift_port.py
  12. 0 0
      ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/alerts/alert_webhcat_server.py
  13. 1 1
      ambari-server/src/main/resources/common-services/OOZIE/4.0.0.2.0/alerts.json
  14. 81 0
      ambari-server/src/main/resources/common-services/OOZIE/4.0.0.2.0/package/alerts/alert_check_oozie_server.py
  15. 0 74
      ambari-server/src/main/resources/common-services/OOZIE/4.0.0.2.0/package/files/alert_check_oozie_server.py
  16. 2 2
      ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/alerts.json
  17. 7 10
      ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/package/alerts/alert_hive_thrift_port.py
  18. 0 0
      ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/package/alerts/alert_webhcat_server.py
  19. 1 1
      ambari-server/src/main/resources/stacks/HDP/1.3.2/services/MAPREDUCE/alerts.json
  20. 5 7
      ambari-server/src/main/resources/stacks/HDP/1.3.2/services/MAPREDUCE/package/alerts/alert_mapreduce_directory_space.py
  21. 1 1
      ambari-server/src/main/resources/stacks/HDP/1.3.2/services/OOZIE/alerts.json
  22. 81 0
      ambari-server/src/main/resources/stacks/HDP/1.3.2/services/OOZIE/package/alerts/alert_check_oozie_server.py
  23. 0 74
      ambari-server/src/main/resources/stacks/HDP/1.3.2/services/OOZIE/package/files/alert_check_oozie_server.py
  24. 1 1
      ambari-server/src/main/resources/stacks/HDP/2.0.6/services/YARN/alerts.json
  25. 0 0
      ambari-server/src/main/resources/stacks/HDP/2.0.6/services/YARN/package/alerts/alert_nodemanager_health.py

+ 27 - 16
ambari-agent/src/main/python/ambari_agent/alerts/script_alert.py

@@ -21,7 +21,9 @@ limitations under the License.
 import imp
 import logging
 import os
+import re
 from alerts.base_alert import BaseAlert
+from resource_management.core.environment import Environment
 from symbol import parameters
 
 logger = logging.getLogger()
@@ -43,6 +45,7 @@ class ScriptAlert(BaseAlert):
     self.stacks_dir = None
     self.common_services_dir = None
     self.host_scripts_dir = None
+    self.path_to_script = None
     
     if 'path' in alert_source_meta:
       self.path = alert_source_meta['path']
@@ -81,8 +84,16 @@ class ScriptAlert(BaseAlert):
       parameters = {}
       for key in self.config_value_dict:
         parameters['{{' + key + '}}'] = self.config_value_dict[key]
-      
-      return cmd_module.execute(parameters, self.host_name)
+
+      # try to get basedir for scripts
+      # it's needed for server side scripts to properly use resource management
+      matchObj = re.match( r'((.*)services\/(.*)\/package\/)', self.path_to_script)
+      if matchObj:
+        basedir = matchObj.group(1)
+        with Environment(basedir) as env:
+          return cmd_module.execute(parameters, self.host_name)
+      else:
+        return cmd_module.execute(parameters, self.host_name)
     else:
       return (self.RESULT_UNKNOWN, ["Unable to execute script {0}".format(self.path)])
     
@@ -92,35 +103,35 @@ class ScriptAlert(BaseAlert):
       raise Exception("The attribute 'path' must be specified")
 
     paths = self.path.split('/')
-    path_to_script = self.path
+    self.path_to_script = self.path
     
     # if the path doesn't exist and stacks dir is defined, try that
-    if not os.path.exists(path_to_script) and self.stacks_dir is not None:      
-      path_to_script = os.path.join(self.stacks_dir, *paths)
+    if not os.path.exists(self.path_to_script) and self.stacks_dir is not None:
+      self.path_to_script = os.path.join(self.stacks_dir, *paths)
 
     # if the path doesn't exist and common services dir is defined, try that
-    if not os.path.exists(path_to_script) and self.common_services_dir is not None:
-      path_to_script = os.path.join(self.common_services_dir, *paths)
+    if not os.path.exists(self.path_to_script) and self.common_services_dir is not None:
+      self.path_to_script = os.path.join(self.common_services_dir, *paths)
 
     # if the path doesn't exist and the host script dir is defined, try that
-    if not os.path.exists(path_to_script) and self.host_scripts_dir is not None:
-      path_to_script = os.path.join(self.host_scripts_dir, *paths)
+    if not os.path.exists(self.path_to_script) and self.host_scripts_dir is not None:
+      self.path_to_script = os.path.join(self.host_scripts_dir, *paths)
 
     # if the path can't be evaluated, throw exception      
-    if not os.path.exists(path_to_script) or not os.path.isfile(path_to_script):
+    if not os.path.exists(self.path_to_script) or not os.path.isfile(self.path_to_script):
       raise Exception(
         "Unable to find '{0}' as an absolute path or part of {1} or {2}".format(self.path,
           self.stacks_dir, self.host_scripts_dir))
 
     if logger.isEnabledFor(logging.DEBUG):
-      logger.debug("Executing script check {0}".format(path_to_script))
+      logger.debug("Executing script check {0}".format(self.path_to_script))
 
           
-    if (not path_to_script.endswith('.py')):
-      logger.error("Unable to execute script {0}".format(path_to_script))
+    if (not self.path_to_script.endswith('.py')):
+      logger.error("Unable to execute script {0}".format(self.path_to_script))
       return None
-    
-    return imp.load_source(self._find_value('name'), path_to_script)
+
+    return imp.load_source(self._find_value('name'), self.path_to_script)
 
 
   def _get_reporting_text(self, state):
@@ -132,4 +143,4 @@ class ScriptAlert(BaseAlert):
     :param state: the state of the alert in uppercase (such as OK, WARNING, etc)
     :return:  the parameterized text
     '''
-    return '{0}'
+    return '{0}'

+ 3 - 1
ambari-agent/src/test/python/ambari_agent/TestAlerts.py

@@ -21,6 +21,7 @@ limitations under the License.
 import os
 import socket
 import sys
+import re
 
 from ambari_agent.AlertSchedulerHandler import AlertSchedulerHandler
 from ambari_agent.alerts.collector import AlertCollector
@@ -31,7 +32,7 @@ from ambari_agent.alerts.web_alert import WebAlert
 from ambari_agent.apscheduler.scheduler import Scheduler
 
 from collections import namedtuple
-from mock.mock import patch
+from mock.mock import MagicMock, patch
 from unittest import TestCase
 
 class TestAlerts(TestCase):
@@ -195,6 +196,7 @@ class TestAlerts(TestCase):
     pa.collect()
 
 
+  @patch.object(re, 'match', new = MagicMock())
   def test_script_alert(self):
     json = {
       "name": "namenode_process",

+ 1 - 1
ambari-server/src/main/resources/common-services/AMS/0.1.0/alerts.json

@@ -147,7 +147,7 @@
         "scope": "ANY",
         "source": {
           "type": "SCRIPT",
-          "path": "AMS/0.1.0/package/files/alert_ambari_metrics_monitor.py"
+          "path": "AMS/0.1.0/package/alerts/alert_ambari_metrics_monitor.py"
         }
       }
     ]

+ 0 - 0
ambari-server/src/main/resources/common-services/AMS/0.1.0/package/files/alert_ambari_metrics_monitor.py → ambari-server/src/main/resources/common-services/AMS/0.1.0/package/alerts/alert_ambari_metrics_monitor.py


+ 1 - 1
ambari-server/src/main/resources/common-services/FLUME/1.4.0.2.0/alerts.json

@@ -10,7 +10,7 @@
         "scope": "ANY",
         "source": {
           "type": "SCRIPT",
-          "path": "FLUME/1.4.0.2.0/package/files/alert_flume_agent_status.py"
+          "path": "FLUME/1.4.0.2.0/package/alerts/alert_flume_agent_status.py"
         }
       }
     ]

+ 0 - 0
ambari-server/src/main/resources/common-services/FLUME/1.4.0.2.0/package/files/alert_flume_agent_status.py → ambari-server/src/main/resources/common-services/FLUME/1.4.0.2.0/package/alerts/alert_flume_agent_status.py


+ 2 - 2
ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/alerts.json

@@ -330,7 +330,7 @@
         "enabled": true,
         "source": {
           "type": "SCRIPT",
-          "path": "HDFS/2.1.0.2.0/package/files/alert_checkpoint_time.py"
+          "path": "HDFS/2.1.0.2.0/package/alerts/alert_checkpoint_time.py"
         }
       },
       {
@@ -343,7 +343,7 @@
         "ignore_host": true,
         "source": {
           "type": "SCRIPT",
-          "path": "HDFS/2.1.0.2.0/package/files/alert_ha_namenode_health.py"
+          "path": "HDFS/2.1.0.2.0/package/alerts/alert_ha_namenode_health.py"
         }
       }
     ],

+ 0 - 0
ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/files/alert_checkpoint_time.py → ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_checkpoint_time.py


+ 0 - 0
ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/files/alert_ha_namenode_health.py → ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_ha_namenode_health.py


+ 2 - 2
ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/alerts.json

@@ -38,7 +38,7 @@
         "enabled": true,
         "source": {
           "type": "SCRIPT",
-          "path": "HIVE/0.12.0.2.0/package/files/alert_hive_thrift_port.py"
+          "path": "HIVE/0.12.0.2.0/package/alerts/alert_hive_thrift_port.py"
         }
       }
     ],
@@ -52,7 +52,7 @@
         "enabled": true,
         "source": {
           "type": "SCRIPT",
-          "path": "HIVE/0.12.0.2.0/package/files/alert_webhcat_server.py"
+          "path": "HIVE/0.12.0.2.0/package/alerts/alert_webhcat_server.py"
         }
       }    
     ]

+ 4 - 7
ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/package/files/alert_hive_thrift_port.py → ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/alerts/alert_hive_thrift_port.py

@@ -26,7 +26,6 @@ import urllib2
 from resource_management.libraries.functions import hive_check
 from resource_management.libraries.functions import format
 from resource_management.libraries.functions import get_kinit_path
-from resource_management.core.environment import Environment
 
 OK_MESSAGE = "TCP OK - %.4f response on port %s"
 CRITICAL_MESSAGE = "Connection failed on host {0}:{1}"
@@ -92,9 +91,8 @@ def execute(parameters=None, host_name=None):
     smokeuser_keytab = SMOKEUSER_KEYTAB_DEFAULT
     if SMOKEUSER_KEYTAB_KEY in parameters:
       smokeuser_keytab = parameters[SMOKEUSER_KEYTAB_KEY]
-    with Environment() as env:
-      kinit_path_local = get_kinit_path(["/usr/bin", "/usr/kerberos/bin", "/usr/sbin"])
-      kinitcmd=format("{kinit_path_local} -kt {smokeuser_keytab} {smokeuser}; ")
+    kinit_path_local = get_kinit_path(["/usr/bin", "/usr/kerberos/bin", "/usr/sbin"])
+    kinitcmd=format("{kinit_path_local} -kt {smokeuser_keytab} {smokeuser}; ")
   else:
     hive_server_principal = None
     kinitcmd=None
@@ -105,9 +103,8 @@ def execute(parameters=None, host_name=None):
 
     start_time = time.time()
     try:
-      with Environment() as env:
-        hive_check.check_thrift_port_sasl(host_name, thrift_port, hive_server2_authentication,
-                                          hive_server_principal, kinitcmd, smokeuser)
+      hive_check.check_thrift_port_sasl(host_name, thrift_port, hive_server2_authentication,
+                                        hive_server_principal, kinitcmd, smokeuser)
       is_thrift_port_ok = True
     except:
       is_thrift_port_ok = False

+ 0 - 0
ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/files/alert_webhcat_server.py → ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/alerts/alert_webhcat_server.py


+ 1 - 1
ambari-server/src/main/resources/common-services/OOZIE/4.0.0.2.0/alerts.json

@@ -34,7 +34,7 @@
         "scope": "ANY",
         "source": {
           "type": "SCRIPT",
-          "path": "OOZIE/4.0.0.2.0/package/files/alert_check_oozie_server.py"
+          "path": "OOZIE/4.0.0.2.0/package/alerts/alert_check_oozie_server.py"
         }
       }
     ]

+ 81 - 0
ambari-server/src/main/resources/common-services/OOZIE/4.0.0.2.0/package/alerts/alert_check_oozie_server.py

@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+
+"""
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+
+from resource_management import *
+from resource_management.libraries.functions import format
+from resource_management.libraries.functions import get_kinit_path
+from resource_management.core.environment import Environment
+
+RESULT_CODE_OK = 'OK'
+RESULT_CODE_CRITICAL = 'CRITICAL'
+RESULT_CODE_UNKNOWN = 'UNKNOWN'
+
+OOZIE_URL_KEY = '{{oozie-site/oozie.base.url}}'
+SECURITY_ENABLED = '{{cluster-env/security_enabled}}'
+SMOKEUSER_KEY = '{{cluster-env/smokeuser}}'
+SMOKEUSER_KEYTAB_KEY = '{{cluster-env/smokeuser_keytab}}'
+
+def get_tokens():
+  """
+  Returns a tuple of tokens in the format {{site/property}} that will be used
+  to build the dictionary passed into execute
+  """
+  return (OOZIE_URL_KEY, SMOKEUSER_KEY, SECURITY_ENABLED,SMOKEUSER_KEYTAB_KEY)
+
+def execute(parameters=None, host_name=None):
+  """
+  Returns a tuple containing the result code and a pre-formatted result label
+
+  Keyword arguments:
+  parameters (dictionary): a mapping of parameter key to value
+  host_name (string): the name of this host where the alert is running
+  """
+
+  if parameters is None:
+    return (RESULT_CODE_UNKNOWN, ['There were no parameters supplied to the script.'])
+
+  security_enabled = False
+  if set([OOZIE_URL_KEY, SMOKEUSER_KEY, SECURITY_ENABLED]).issubset(parameters):
+    oozie_url = parameters[OOZIE_URL_KEY]
+    smokeuser = parameters[SMOKEUSER_KEY]
+    security_enabled = str(parameters[SECURITY_ENABLED]).upper() == 'TRUE'
+  else:
+    return (RESULT_CODE_UNKNOWN, ['The Oozie URL and Smokeuser are a required parameters.'])
+
+  try:
+    if security_enabled:
+      if set([SMOKEUSER_KEYTAB_KEY]).issubset(parameters):
+        smokeuser_keytab = parameters[SMOKEUSER_KEYTAB_KEY]
+      else:
+        return (RESULT_CODE_UNKNOWN, ['The Smokeuser keytab is required when security is enabled.'])
+      kinit_path_local = get_kinit_path(["/usr/bin", "/usr/kerberos/bin", "/usr/sbin"])
+      kinitcmd = format("{kinit_path_local} -kt {smokeuser_keytab} {smokeuser}; ")
+
+      Execute(kinitcmd,
+              user=smokeuser,
+              )
+
+    Execute(format("source /etc/oozie/conf/oozie-env.sh ; oozie admin -oozie {oozie_url} -status"),
+            user=smokeuser,
+            )
+    return (RESULT_CODE_OK, ["Oozie check success"])
+
+  except Exception, ex:
+    return (RESULT_CODE_CRITICAL, [str(ex)])

+ 0 - 74
ambari-server/src/main/resources/common-services/OOZIE/4.0.0.2.0/package/files/alert_check_oozie_server.py

@@ -1,74 +0,0 @@
-#!/usr/bin/env python
-
-"""
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-"""
-
-import subprocess
-from subprocess import CalledProcessError
-
-RESULT_CODE_OK = 'OK'
-RESULT_CODE_CRITICAL = 'CRITICAL'
-RESULT_CODE_UNKNOWN = 'UNKNOWN'
-
-OOZIE_URL_KEY = '{{oozie-site/oozie.base.url}}'
-
-def get_tokens():
-  """
-  Returns a tuple of tokens in the format {{site/property}} that will be used
-  to build the dictionary passed into execute
-  """
-  return (OOZIE_URL_KEY)
-  
-
-def execute(parameters=None, host_name=None):
-  """
-  Returns a tuple containing the result code and a pre-formatted result label
-
-  Keyword arguments:
-  parameters (dictionary): a mapping of parameter key to value
-  host_name (string): the name of this host where the alert is running
-  """
-
-  if parameters is None:
-    return (RESULT_CODE_UNKNOWN, ['There were no parameters supplied to the script.'])
-
-  oozie_url = None
-  if OOZIE_URL_KEY in parameters:
-    oozie_url = parameters[OOZIE_URL_KEY]
-
-  if oozie_url is None:
-    return (RESULT_CODE_UNKNOWN, ['The Oozie URL is a required parameter.'])
-
-  try:
-    # oozie admin -oozie http://server:11000/oozie -status
-    oozie_process = subprocess.Popen(['oozie', 'admin', '-oozie',
-      oozie_url, '-status'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
-
-    oozie_output, oozie_error = oozie_process.communicate()
-    oozie_return_code = oozie_process.returncode
-
-    if oozie_return_code == 0:
-      # strip trailing newlines
-      oozie_output = str(oozie_output).strip('\n')
-      return (RESULT_CODE_OK, [oozie_output])
-    else:
-      oozie_error = str(oozie_error).strip('\n')
-      return (RESULT_CODE_CRITICAL, [oozie_error])
-
-  except CalledProcessError, cpe:
-    return (RESULT_CODE_CRITICAL, [str(cpe)])

+ 2 - 2
ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/alerts.json

@@ -38,7 +38,7 @@
         "enabled": true,
         "source": {
           "type": "SCRIPT",
-          "path": "HDP/1.3.2/services/HIVE/package/files/alert_hive_thrift_port.py"
+          "path": "HDP/1.3.2/services/HIVE/package/alerts/alert_hive_thrift_port.py"
         }
       }
     ],
@@ -52,7 +52,7 @@
         "enabled": true,
         "source": {
           "type": "SCRIPT",
-          "path": "HDP/1.3.2/services/HIVE/package/files/alert_webhcat_server.py"
+          "path": "HDP/1.3.2/services/HIVE/package/alerts/alert_webhcat_server.py"
         }
       }    
     ]

+ 7 - 10
ambari-server/src/main/resources/common-services/HIVE/0.12.0.2.0/package/files/alert_hive_thrift_port.py → ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/package/alerts/alert_hive_thrift_port.py

@@ -26,7 +26,6 @@ import urllib2
 from resource_management.libraries.functions import hive_check
 from resource_management.libraries.functions import format
 from resource_management.libraries.functions import get_kinit_path
-from resource_management.core.environment import Environment
 
 OK_MESSAGE = "TCP OK - %.4f response on port %s"
 CRITICAL_MESSAGE = "Connection failed on host {0}:{1}"
@@ -53,7 +52,7 @@ def get_tokens():
   to build the dictionary passed into execute
   """
   return (HIVE_SERVER_THRIFT_PORT_KEY,SECURITY_ENABLED_KEY,HIVE_SERVER2_AUTHENTICATION_KEY,HIVE_SERVER_PRINCIPAL_KEY,SMOKEUSER_KEYTAB_KEY,SMOKEUSER_KEY)
-  
+
 
 def execute(parameters=None, host_name=None):
   """
@@ -69,7 +68,7 @@ def execute(parameters=None, host_name=None):
 
   thrift_port = THRIFT_PORT_DEFAULT
   if HIVE_SERVER_THRIFT_PORT_KEY in parameters:
-    thrift_port = int(parameters[HIVE_SERVER_THRIFT_PORT_KEY])  
+    thrift_port = int(parameters[HIVE_SERVER_THRIFT_PORT_KEY])
 
   security_enabled = False
   if SECURITY_ENABLED_KEY in parameters:
@@ -92,9 +91,8 @@ def execute(parameters=None, host_name=None):
     smokeuser_keytab = SMOKEUSER_KEYTAB_DEFAULT
     if SMOKEUSER_KEYTAB_KEY in parameters:
       smokeuser_keytab = parameters[SMOKEUSER_KEYTAB_KEY]
-    with Environment() as env:
-      kinit_path_local = get_kinit_path(["/usr/bin", "/usr/kerberos/bin", "/usr/sbin"])
-      kinitcmd=format("{kinit_path_local} -kt {smokeuser_keytab} {smokeuser}; ")
+    kinit_path_local = get_kinit_path(["/usr/bin", "/usr/kerberos/bin", "/usr/sbin"])
+    kinitcmd=format("{kinit_path_local} -kt {smokeuser_keytab} {smokeuser}; ")
   else:
     hive_server_principal = None
     kinitcmd=None
@@ -105,9 +103,8 @@ def execute(parameters=None, host_name=None):
 
     start_time = time.time()
     try:
-      with Environment() as env:
-        hive_check.check_thrift_port_sasl(host_name, thrift_port, hive_server2_authentication,
-                                          hive_server_principal, kinitcmd, smokeuser)
+      hive_check.check_thrift_port_sasl(host_name, thrift_port, hive_server2_authentication,
+                                        hive_server_principal, kinitcmd, smokeuser)
       is_thrift_port_ok = True
     except:
       is_thrift_port_ok = False
@@ -123,5 +120,5 @@ def execute(parameters=None, host_name=None):
   except Exception, e:
     label = str(e)
     result_code = 'UNKNOWN'
-        
+
   return ((result_code, [label]))

+ 0 - 0
ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/package/files/alert_webhcat_server.py → ambari-server/src/main/resources/stacks/HDP/1.3.2/services/HIVE/package/alerts/alert_webhcat_server.py


+ 1 - 1
ambari-server/src/main/resources/stacks/HDP/1.3.2/services/MAPREDUCE/alerts.json

@@ -186,7 +186,7 @@
         "enabled": true,
         "source": {
           "type": "SCRIPT",
-          "path": "HDP/1.3.2/services/MAPREDUCE/package/files/alert_mapreduce_directory_space.py"
+          "path": "HDP/1.3.2/services/MAPREDUCE/package/alerts/alert_mapreduce_directory_space.py"
         }
       }
     ],

+ 5 - 7
ambari-server/src/main/resources/stacks/HDP/1.3.2/services/MAPREDUCE/package/files/alert_mapreduce_directory_space.py → ambari-server/src/main/resources/stacks/HDP/1.3.2/services/MAPREDUCE/package/alerts/alert_mapreduce_directory_space.py

@@ -34,7 +34,7 @@ def get_tokens():
   to build the dictionary passed into execute
   """
   return (MAPREDUCE_LOCAL_DIR_KEY,)
-  
+
 
 def execute(parameters=None, host_name=None):
   """
@@ -47,11 +47,9 @@ def execute(parameters=None, host_name=None):
   if parameters is None:
     return (('UNKNOWN', ['There were no parameters supplied to the script.']))
 
-  mapreduce_local_directories = None
-  if MAPREDUCE_LOCAL_DIR_KEY in parameters:
+  if set([MAPREDUCE_LOCAL_DIR_KEY]).issubset(parameters):
     mapreduce_local_directories = parameters[MAPREDUCE_LOCAL_DIR_KEY]
-
-  if MAPREDUCE_LOCAL_DIR_KEY is None:
+  else:
     return (('UNKNOWN', ['The MapReduce Local Directory is required.']))
 
   directory_list = mapreduce_local_directories.split(",")
@@ -82,7 +80,7 @@ def _get_disk_usage(path):
   used = 0
   total = 0
   free = 0
-  
+
   if 'statvfs' in dir(os):
     disk_stats = os.statvfs(path)
     free = disk_stats.f_bavail * disk_stats.f_frsize
@@ -90,6 +88,6 @@ def _get_disk_usage(path):
     used = (disk_stats.f_blocks - disk_stats.f_bfree) * disk_stats.f_frsize
   else:
     raise NotImplementedError("{0} is not a supported platform for this alert".format(platform.platform()))
-  
+
   DiskInfo = collections.namedtuple('DiskInfo', 'total used free')
   return DiskInfo(total=total, used=used, free=free)

+ 1 - 1
ambari-server/src/main/resources/stacks/HDP/1.3.2/services/OOZIE/alerts.json

@@ -34,7 +34,7 @@
         "scope": "ANY",
         "source": {
           "type": "SCRIPT",
-          "path": "HDP/1.3.2/services/OOZIE/package/files/alert_check_oozie_server.py"
+          "path": "HDP/1.3.2/services/OOZIE/package/alerts/alert_check_oozie_server.py"
         }
       }
     ]

+ 81 - 0
ambari-server/src/main/resources/stacks/HDP/1.3.2/services/OOZIE/package/alerts/alert_check_oozie_server.py

@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+
+"""
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+
+from resource_management import *
+from resource_management.libraries.functions import format
+from resource_management.libraries.functions import get_kinit_path
+from resource_management.core.environment import Environment
+
+RESULT_CODE_OK = 'OK'
+RESULT_CODE_CRITICAL = 'CRITICAL'
+RESULT_CODE_UNKNOWN = 'UNKNOWN'
+
+OOZIE_URL_KEY = '{{oozie-site/oozie.base.url}}'
+SECURITY_ENABLED = '{{cluster-env/security_enabled}}'
+SMOKEUSER_KEY = '{{cluster-env/smokeuser}}'
+SMOKEUSER_KEYTAB_KEY = '{{cluster-env/smokeuser_keytab}}'
+
+def get_tokens():
+  """
+  Returns a tuple of tokens in the format {{site/property}} that will be used
+  to build the dictionary passed into execute
+  """
+  return (OOZIE_URL_KEY, SMOKEUSER_KEY, SECURITY_ENABLED,SMOKEUSER_KEYTAB_KEY)
+
+def execute(parameters=None, host_name=None):
+  """
+  Returns a tuple containing the result code and a pre-formatted result label
+
+  Keyword arguments:
+  parameters (dictionary): a mapping of parameter key to value
+  host_name (string): the name of this host where the alert is running
+  """
+
+  if parameters is None:
+    return (RESULT_CODE_UNKNOWN, ['There were no parameters supplied to the script.'])
+
+  security_enabled = False
+  if set([OOZIE_URL_KEY, SMOKEUSER_KEY, SECURITY_ENABLED]).issubset(parameters):
+    oozie_url = parameters[OOZIE_URL_KEY]
+    smokeuser = parameters[SMOKEUSER_KEY]
+    security_enabled = str(parameters[SECURITY_ENABLED]).upper() == 'TRUE'
+  else:
+    return (RESULT_CODE_UNKNOWN, ['The Oozie URL and Smokeuser are a required parameters.'])
+
+  try:
+    if security_enabled:
+      if set([SMOKEUSER_KEYTAB_KEY]).issubset(parameters):
+        smokeuser_keytab = parameters[SMOKEUSER_KEYTAB_KEY]
+      else:
+        return (RESULT_CODE_UNKNOWN, ['The Smokeuser keytab is required when security is enabled.'])
+      kinit_path_local = get_kinit_path(["/usr/bin", "/usr/kerberos/bin", "/usr/sbin"])
+      kinitcmd = format("{kinit_path_local} -kt {smokeuser_keytab} {smokeuser}; ")
+
+      Execute(kinitcmd,
+              user=smokeuser,
+              )
+
+    Execute(format("source /etc/oozie/conf/oozie-env.sh ; oozie admin -oozie {oozie_url} -status"),
+            user=smokeuser,
+            )
+    return (RESULT_CODE_OK, ["Oozie check success"])
+
+  except Exception, ex:
+    return (RESULT_CODE_CRITICAL, [str(ex)])

+ 0 - 74
ambari-server/src/main/resources/stacks/HDP/1.3.2/services/OOZIE/package/files/alert_check_oozie_server.py

@@ -1,74 +0,0 @@
-#!/usr/bin/env python
-
-"""
-Licensed to the Apache Software Foundation (ASF) under one
-or more contributor license agreements.  See the NOTICE file
-distributed with this work for additional information
-regarding copyright ownership.  The ASF licenses this file
-to you under the Apache License, Version 2.0 (the
-"License"); you may not use this file except in compliance
-with the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-"""
-
-import subprocess
-from subprocess import CalledProcessError
-
-RESULT_CODE_OK = 'OK'
-RESULT_CODE_CRITICAL = 'CRITICAL'
-RESULT_CODE_UNKNOWN = 'UNKNOWN'
-
-OOZIE_URL_KEY = '{{oozie-site/oozie.base.url}}'
-
-def get_tokens():
-  """
-  Returns a tuple of tokens in the format {{site/property}} that will be used
-  to build the dictionary passed into execute
-  """
-  return (OOZIE_URL_KEY)
-  
-
-def execute(parameters=None, host_name=None):
-  """
-  Returns a tuple containing the result code and a pre-formatted result label
-
-  Keyword arguments:
-  parameters (dictionary): a mapping of parameter key to value
-  host_name (string): the name of this host where the alert is running
-  """
-
-  if parameters is None:
-    return (RESULT_CODE_UNKNOWN, ['There were no parameters supplied to the script.'])
-
-  oozie_url = None
-  if OOZIE_URL_KEY in parameters:
-    oozie_url = parameters[OOZIE_URL_KEY]
-
-  if oozie_url is None:
-    return (RESULT_CODE_UNKNOWN, ['The Oozie URL is a required parameter.'])
-
-  try:
-    # oozie admin -oozie http://server:11000/oozie -status
-    oozie_process = subprocess.Popen(['oozie', 'admin', '-oozie',
-      oozie_url, '-status'], stderr=subprocess.PIPE, stdout=subprocess.PIPE)
-
-    oozie_output, oozie_error = oozie_process.communicate()
-    oozie_return_code = oozie_process.returncode
-
-    if oozie_return_code == 0:
-      # strip trailing newlines
-      oozie_output = str(oozie_output).strip('\n')
-      return (RESULT_CODE_OK, [oozie_output])
-    else:
-      oozie_error = str(oozie_error).strip('\n')
-      return (RESULT_CODE_CRITICAL, [oozie_error])
-
-  except CalledProcessError, cpe:
-    return (RESULT_CODE_CRITICAL, [str(cpe)])

+ 1 - 1
ambari-server/src/main/resources/stacks/HDP/2.0.6/services/YARN/alerts.json

@@ -199,7 +199,7 @@
         "enabled": true,
         "source": {
           "type": "SCRIPT",
-          "path": "HDP/2.0.6/services/YARN/package/files/alert_nodemanager_health.py"
+          "path": "HDP/2.0.6/services/YARN/package/alerts/alert_nodemanager_health.py"
         }
       }
     ],

+ 0 - 0
ambari-server/src/main/resources/stacks/HDP/2.0.6/services/YARN/package/files/alert_nodemanager_health.py → ambari-server/src/main/resources/stacks/HDP/2.0.6/services/YARN/package/alerts/alert_nodemanager_health.py