標籤:psycopg2 str war png img 錯誤資訊 ica group by color
python指令碼查詢ambari錯誤資訊
yum -y install python-psycopg2
#!/usr/bin/pythonimport sysimport psycopg2# modify the following five optionspsql_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報錯