码迷,mamicode.com
首页 > 编程语言 > 详细

python查看ambari报错

时间:2018-08-13 13:55:49      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:psycopg2   str   war   png   img   错误信息   ica   group by   color   

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报错

标签:psycopg2   str   war   png   img   错误信息   ica   group by   color   

原文地址:https://www.cnblogs.com/nhs3217/p/9467240.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!