-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetRs.py
32 lines (26 loc) · 1.21 KB
/
getRs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/python
#coding=utf-8
import psycopg2 , sys
import psycopg2.extras
class function(object):
@staticmethod
def getDbResult(start_time , end_time):
conn = psycopg2.connect(host="10.10.60.45",port=5432,user="postgres",password="postgres",database="zabbix")
cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
sql = "SELECT count(*) as cnt ,substring(subject , '.*时间') as new_subject from alerts where subject ~ '告警.*时间' and to_timestamp(clock) >= '" +start_time + "' and to_timestamp(clock) <= '" + end_time + "' and userid=3 and mediatypeid=4 group by new_subject order by cnt desc"
print sql
cur.execute(sql)
list = cur.fetchall()
conn.close()
# list = []
# list.append(['1','asdfasdf'])
# list.append(['3','fffffffff'])
return list
def getHostAlert(self , sql):
from configAlert import host , port , user , passwd , databases
conn = psycopg2.connect(host=host,port=port,user=user,password=passwd,database=databases)
cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute(sql)
list = cur.fetchall()
conn.close()
return list