-
Notifications
You must be signed in to change notification settings - Fork 1
/
nconf_update.py
67 lines (57 loc) · 1.94 KB
/
nconf_update.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
#!/usr/bin/python
import MySQLdb
import socket
import logging
import getpass
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
fh = logging.FileHandler('epic-fails.log')
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
logger.addHandler(fh)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(formatter)
logger.addHandler(ch)
def main():
# host = raw_input('Host: ')
# user = raw_input('User: ')
# password = getpass.getpass('Password: ')
# db_name = raw_input('DB Name: ')
# db = MySQLdb.connect(host, user, password, db_name)
host="localhost";
user="root";
password="";
db_name="nconf";
db = MySQLdb.connect(host, user, password, db_name)
cursor = db.cursor()
cmd = "select * from ConfigValues where fk_id_attr =79;"
#cmd = "select * from ConfigValues"
cursor.execute(cmd)
results = cursor.fetchall()
counter = 0
for row in results:
print row[0];
print 444444;
# addr = row[0]
if "metrics-web.app.uj1.inmobi.com" in row[0]:
print 55555555555555;
newentry=row[0].replace("metrics-web.app.uj1.inmobi.com","app-metrics-web.app.uj1.inmobi.com");
print newentry;
try:
cmd = "update ConfigValues set attr_value='%s' where attr_value='%s'" % (newentry, row[0])
cursor.execute(cmd)
db.commit()
# logger.debug('Something is still happening. Chill... B-)')
except Exception as e:
print e;
# logger.error('Lookup of %s failed.\n' % addr)
# counter += 1
# except:
# # logger.error('Failed to write to DB. Hostname: %s, Address: %s' % (hostname, addr))
# db.rollback()
# counter += 1
#print 'Total Hostname Lookup Failures: %d' % counter
if __name__ == '__main__':
main()