mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Attempted fix for schema update issues
Closes database connection while pollers are running and reopens at the end.
This commit is contained in:
@ -83,18 +83,30 @@ db_username = config['db_user']
|
|||||||
db_password = config['db_pass']
|
db_password = config['db_pass']
|
||||||
|
|
||||||
if config['db_host'][:5].lower() == 'unix:':
|
if config['db_host'][:5].lower() == 'unix:':
|
||||||
db_server = config['db_host']
|
db_server = config['db_host']
|
||||||
db_port = 0
|
db_port = 0
|
||||||
elif ':' in config['db_host']:
|
elif ':' in config['db_host']:
|
||||||
db_server = config['db_host'].rsplit(':')[0]
|
db_server = config['db_host'].rsplit(':')[0]
|
||||||
db_port = int(config['db_host'].rsplit(':')[1])
|
db_port = int(config['db_host'].rsplit(':')[1])
|
||||||
else:
|
else:
|
||||||
db_server = config['db_host']
|
db_server = config['db_host']
|
||||||
db_port =0
|
db_port = 0
|
||||||
|
|
||||||
db_dbname = config['db_name']
|
db_dbname = config['db_name']
|
||||||
|
|
||||||
|
|
||||||
|
def db_open():
|
||||||
|
try:
|
||||||
|
if db_port == 0:
|
||||||
|
db = MySQLdb.connect(host=db_server, user=db_username, passwd=db_password, db=db_dbname)
|
||||||
|
else:
|
||||||
|
db = MySQLdb.connect(host=db_server, port=db_port, user=db_username, passwd=db_password, db=db_dbname)
|
||||||
|
return db
|
||||||
|
except:
|
||||||
|
print "ERROR: Could not connect to MySQL database!"
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
|
||||||
# (c) 2015, GPLv3, Daniel Preussker <f0o@devilcode.org> <<<EOC1
|
# (c) 2015, GPLv3, Daniel Preussker <f0o@devilcode.org> <<<EOC1
|
||||||
if 'distributed_poller_group' in config:
|
if 'distributed_poller_group' in config:
|
||||||
poller_group = str(config['distributed_poller_group'])
|
poller_group = str(config['distributed_poller_group'])
|
||||||
@ -180,16 +192,6 @@ except:
|
|||||||
|
|
||||||
devices_list = []
|
devices_list = []
|
||||||
|
|
||||||
try:
|
|
||||||
if db_port == 0:
|
|
||||||
db = MySQLdb.connect(host=db_server, user=db_username, passwd=db_password, db=db_dbname)
|
|
||||||
else:
|
|
||||||
db = MySQLdb.connect(host=db_server, port=db_port, user=db_username, passwd=db_password, db=db_dbname)
|
|
||||||
cursor = db.cursor()
|
|
||||||
except:
|
|
||||||
print "ERROR: Could not connect to MySQL database!"
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This query specificly orders the results depending on the last_polled_timetaken variable
|
This query specificly orders the results depending on the last_polled_timetaken variable
|
||||||
Because this way, we put the devices likely to be slow, in the top of the queue
|
Because this way, we put the devices likely to be slow, in the top of the queue
|
||||||
@ -203,6 +205,9 @@ else:
|
|||||||
query = "select device_id from devices where disabled = 0 order by last_polled_timetaken desc"
|
query = "select device_id from devices where disabled = 0 order by last_polled_timetaken desc"
|
||||||
# EOC2
|
# EOC2
|
||||||
|
|
||||||
|
|
||||||
|
db = db_open()
|
||||||
|
cursor = db.cursor()
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
devices = cursor.fetchall()
|
devices = cursor.fetchall()
|
||||||
for row in devices:
|
for row in devices:
|
||||||
@ -215,6 +220,7 @@ if distpoll and not IsNode:
|
|||||||
maxlocks = devices[0][0]
|
maxlocks = devices[0][0]
|
||||||
minlocks = devices[0][1]
|
minlocks = devices[0][1]
|
||||||
# EOC3
|
# EOC3
|
||||||
|
db.close()
|
||||||
|
|
||||||
"""
|
"""
|
||||||
A seperate queue and a single worker for printing information to the screen prevents
|
A seperate queue and a single worker for printing information to the screen prevents
|
||||||
@ -358,6 +364,8 @@ if distpoll or memc_alive():
|
|||||||
|
|
||||||
show_stopper = False
|
show_stopper = False
|
||||||
|
|
||||||
|
db = db_open()
|
||||||
|
cursor = db.cursor()
|
||||||
query = "update pollers set last_polled=NOW(), devices='%d', time_taken='%d' where poller_name='%s'" % (polled_devices,
|
query = "update pollers set last_polled=NOW(), devices='%d', time_taken='%d' where poller_name='%s'" % (polled_devices,
|
||||||
total_time, config['distributed_poller_name'])
|
total_time, config['distributed_poller_name'])
|
||||||
response = cursor.execute(query)
|
response = cursor.execute(query)
|
||||||
|
Reference in New Issue
Block a user