python查看ambari報錯

來源:互聯網
上載者:User

標籤: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報錯

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.