mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix connecting via socket (#11523)
When trying to use this services-wrapper.py on FreeBSD I was unable to connect to my database. When using the socket logic from the other wrapper python scripts it works fine. Streamline this wrapper with that same logic from poller-wrapper.py and discovery-wrapper.py.
This commit is contained in:
@@ -89,30 +89,22 @@ service_path = config['install_dir'] + '/check-services.php'
|
|||||||
log_dir = config['log_dir']
|
log_dir = config['log_dir']
|
||||||
db_username = config['db_user']
|
db_username = config['db_user']
|
||||||
db_password = config['db_pass']
|
db_password = config['db_pass']
|
||||||
|
db_port = int(config['db_port'])
|
||||||
|
|
||||||
if config['db_host'][:5].lower() == 'unix:':
|
if config['db_socket']:
|
||||||
db_server = config['db_host']
|
db_server = config['db_host']
|
||||||
db_port = 0
|
db_socket = config['db_socket']
|
||||||
elif config['db_socket']:
|
|
||||||
db_server = config['db_socket']
|
|
||||||
db_port = 0
|
|
||||||
elif ':' in config['db_host']:
|
|
||||||
db_server = config['db_host'].rsplit(':')[0]
|
|
||||||
db_port = int(config['db_host'].rsplit(':')[1])
|
|
||||||
elif 'db_port' in config:
|
|
||||||
db_server = config['db_host']
|
|
||||||
db_port = int(config['db_port'])
|
|
||||||
else:
|
else:
|
||||||
db_server = config['db_host']
|
db_server = config['db_host']
|
||||||
db_port = 0
|
db_socket = None
|
||||||
|
|
||||||
db_dbname = config['db_name']
|
db_dbname = config['db_name']
|
||||||
|
|
||||||
|
|
||||||
def db_open():
|
def db_open():
|
||||||
try:
|
try:
|
||||||
if db_port == 0:
|
if db_socket:
|
||||||
db = MySQLdb.connect(host=db_server, user=db_username, passwd=db_password, db=db_dbname)
|
db = MySQLdb.connect(host=db_server, unix_socket=db_socket, user=db_username, passwd=db_password, db=db_dbname)
|
||||||
else:
|
else:
|
||||||
db = MySQLdb.connect(host=db_server, port=db_port, user=db_username, passwd=db_password, db=db_dbname)
|
db = MySQLdb.connect(host=db_server, port=db_port, user=db_username, passwd=db_password, db=db_dbname)
|
||||||
return db
|
return db
|
||||||
@@ -120,6 +112,7 @@ def db_open():
|
|||||||
print "ERROR: Could not connect to MySQL database!"
|
print "ERROR: Could not connect to MySQL database!"
|
||||||
sys.exit(2)
|
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:
|
||||||
service_group = str(config['distributed_poller_group'])
|
service_group = str(config['distributed_poller_group'])
|
||||||
|
Reference in New Issue
Block a user