python查看ambari报错
Posted nhs3217
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python查看ambari报错相关的知识,希望对你有一定的参考价值。
python脚本查询ambari错误信息
yum -y install python-psycopg2
#!/usr/bin/python import sys import psycopg2 # modify the following five options psql_database = "ambari" psql_user = "ambari" psql_password = "bigdata" psql_host = "127.0.0.1" psql_port = "5432" conn = psycopg2.connect(database=psql_database, user=psql_user, password=psql_password, host=psql_host, port=psql_port) cur = conn.cursor() dids=[] cur.execute("select distinct(definition_id) from alert_current") rows = cur.fetchall() for row in rows: dids.append(row[0]) for i in dids: cur.execute("select alert_state,service_name,component_name,host_name,alert_label,alert_text from alert_history a where exists( select * from ( select host_name,max(alert_timestamp) as FTime from alert_history where alert_definition_id=" + str(i) + " group by host_name ) x where (x.host_name=a.host_name or (x.host_name is null and a.host_name is null)) and a.alert_timestamp=x.FTime and a.alert_definition_id=" + str(i) + " )") rows = cur.fetchall() for row in rows: if (row[0] == "CRITICAL" or row[0] == "WARNING"): line = "did=" + str(i) + " || alert_STATE=" + row[0] + " || " + str(row[1])+ " || " + str(row[2])+ " || " + str(row[3])+ " || " + str(row[4])+ " || " + str(row[5]) print(line) conn.close()
以上是关于python查看ambari报错的主要内容,如果未能解决你的问题,请参考以下文章