Python View Ambari Error

Source: Internet
Author: User
Tags python script

Python script query Ambari error message

Yum-y Install PYTHON-PSYCOPG2

#!/usr/bin/pythonImportSYSImportPSYCOPG2#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 () forRowinchrows:dids.append (row[0]) forIinchDids: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 was null and a.host_name is null)) and a.alert_t Imestamp=x.ftime and A.alert_definition_id="+ STR (i) +" )") Rows=Cur.fetchall () forRowinchrows:if(Row[0] = ="CRITICAL" orRow[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 View Ambari Error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.