forked from marcosgildavid/dbmonitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·119 lines (74 loc) · 2.16 KB
/
main.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/python
import sys,getopt
import time
from screen import *
from oracle import *
from mysql import *
#GLobals
type=''
username=''
password=''
tnsname=''
hostname=''
database=''
key = ''
def main(argv):
#access to global var must preceeded by global declaration
#otherwise it is used and local var
global type,username,password,tnsname,hostname,database,key
try:
opts,args = getopt.getopt(argv,"t:u:p:n:d:s:h",["type=","username=","password=","tnsname=","help","database=","hostname="])
except getopt.GetoptError:
print_usage()
sys.exit(2)
for opt,arg in opts:
if opt in ('-h','--help'):
print_usage()
elif opt in ('-t','--type'):
type=arg
elif opt in ('-u','--username'):
username=arg
elif opt in ('-p','--password'):
password=arg
elif opt in ('-n','--tnsname'):
tnsname=arg
elif opt in ('-d','--database'):
database=arg
elif opt in ('-s','--hostname'):
hostname=arg
try:
MainWindow=dbtopScreen(type)
#TODO: Validate inputs :D
if type.lower() == "oracle":
dbObject=OracleDatabase(username,password,tnsname)
elif type.lower() == "mysql":
dbObject=MySQLDatabase(username,password,hostname,database)
dbObject.connect()
MainWindow.updateConnectionString(dbObject.getCurrentConnectionData())
while key != ord('q'):
conns=str(dbObject.getCurrentConnections())
MainWindow.updateCurrentConnections(conns);
queries=dbObject.getCurrentQueries()
MainWindow.updateQueries(queries)
locks=dbObject.getCurrentLocks()
MainWindow.updateLocks(locks)
sessions=dbObject.getCurrentSessions()
MainWindow.updateSessions(sessions)
#print(dbObject.getCurrentConnections())
#print (queries)
MainWindow.updateScreen()
key=MainWindow.stdscr.getch()
time.sleep(1)
#Wait...
#MainWindow.getinput()
#time.sleep(10)
except:
print ("Exception:")
raise
def print_usage():
print ("USAGE:")
print (sys.argv[0]," -t type -u username -p password -n tnsname")
print (sys.argv[0]," --type type --username username --password password --tnsname tnsname")
return
if __name__ == "__main__":
main(sys.argv[1:])