Pass in passwd-file as an argument
This commit is contained in:
@ -18,10 +18,11 @@ class NotConnected(Exception):
|
||||
pass
|
||||
|
||||
class routerstats_client():
|
||||
def __init__(self, host, port):
|
||||
def __init__(self, host, port, passwd_file):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.connected = False
|
||||
self.passwd_file = passwd_file
|
||||
|
||||
def connect(self):
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
@ -50,7 +51,7 @@ class routerstats_client():
|
||||
if not hello == b'Hello':
|
||||
logging.error('No Hello from server: %s', hello)
|
||||
raise ConnectionError('Server did not greet us with Hello during login')
|
||||
with open('passwd.client', 'r') as passwd_file:
|
||||
with open(self.passwd_file, 'r') as passwd_file:
|
||||
passwd = passwd_file.readline()
|
||||
passwd = passwd.rstrip()
|
||||
logging.debug('Sending password: %s', passwd)
|
||||
@ -233,9 +234,16 @@ def main():
|
||||
rrdfile = sys.argv[3]
|
||||
except IndexError:
|
||||
logging.error('Need rrdfile as third argument')
|
||||
sys.exit()
|
||||
|
||||
try:
|
||||
passwd_file = sys.argv[4]
|
||||
except IndexError:
|
||||
logging.error('Need passwd-file as fourth argument')
|
||||
sys.exit()
|
||||
|
||||
rrdupdater = UpdateRRD(rrdfile)
|
||||
client = routerstats_client(client_host, client_port)
|
||||
client = routerstats_client(client_host, client_port, passwd_file)
|
||||
while True:
|
||||
try:
|
||||
client.connect()
|
||||
|
||||
Reference in New Issue
Block a user