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