Skip to content
Snippets Groups Projects
Commit 50c3b6da authored by root's avatar root
Browse files

Forgot environment variables in check_hadoop_apps

parent 792e8985
No related branches found
No related tags found
No related merge requests found
...@@ -33,11 +33,15 @@ STATE_LABEL = { ...@@ -33,11 +33,15 @@ STATE_LABEL = {
# Default exit code # Default exit code
EXIT_CODE = STATE_OK EXIT_CODE = STATE_OK
py_env = os.environ.copy()
py_env['JAVA_HOME'] = '/usr/lib/jvm/java-8-oracle'
py_env['HADOOP_HOME'] = '/usr/lib/hadoop'
def hadoop_query_running_apps(): def hadoop_query_running_apps():
try: try:
data = {} data = {}
hadoop = subprocess.Popen(["yarn", "application", "-list", "-appStates", "RUNNING"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) hadoop = subprocess.Popen(["yarn", "application", "-list", "-appStates", "RUNNING"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=py_env)
# Format the output data from CSV to an array of dicts for ease-of-use # Format the output data from CSV to an array of dicts for ease-of-use
hadoopStd = str(hadoop.stdout.read(), 'UTF8') hadoopStd = str(hadoop.stdout.read(), 'UTF8')
...@@ -65,7 +69,7 @@ def hadoop_query_app(appID): ...@@ -65,7 +69,7 @@ def hadoop_query_app(appID):
try: try:
data = {} data = {}
yarn = subprocess.Popen(["yarn", "application", "-status", appID], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) yarn = subprocess.Popen(["yarn", "application", "-status", appID], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=py_env)
yarnStd = str(yarn.stdout.read(), 'UTF8') yarnStd = str(yarn.stdout.read(), 'UTF8')
results = yarnStd.splitlines() results = yarnStd.splitlines()
...@@ -83,7 +87,7 @@ def hadoop_query_app(appID): ...@@ -83,7 +87,7 @@ def hadoop_query_app(appID):
def yarn_kill_app(appID): def yarn_kill_app(appID):
try: try:
yarn = subprocess.Popen(["yarn", "application", "-kill", appID], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) yarn = subprocess.Popen(["yarn", "application", "-kill", appID], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=py_env)
except FileNotFoundError as e: except FileNotFoundError as e:
print("UNKNOWN - Could not detect yarn command. |") print("UNKNOWN - Could not detect yarn command. |")
sys.exit(STATE_OK) sys.exit(STATE_OK)
...@@ -114,7 +118,7 @@ def main(): ...@@ -114,7 +118,7 @@ def main():
EXIT_CODE = STATE_WARNING EXIT_CODE = STATE_WARNING
if (APP_STATE == STATE_CRITICAL): if (APP_STATE == STATE_CRITICAL):
print("[{0}] {1}: {2}: Has been running for {3} hours. Killing application... | ".format(id, app['Application-Name'], STATE_LABEL[APP_STATE], str(int(app_info['Running-Time'] / 3600)))) print("[{0}] Application-Name: {1}: State {2}: Has been running for {3} hours. Killing application... | ".format(id, app['Application-Name'], STATE_LABEL[APP_STATE], str(int(app_info['Running-Time'] / 3600))))
sys.exit(EXIT_CODE) sys.exit(EXIT_CODE)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment