Commit 977465d6 by Gregory Nagy

Fixtures

parent ec91e24f
import sys import sys
from src import cnfparse, client, collectables from src import cnfparse
from src import client
from src.collectables import collectables
def main(): def main():
if len(sys.argv) < 2: if len(sys.argv) < 2:
print("usage: manage.py run [options]") print("usage: manage.py run [options]")
if len(sys.argv) is not 2 and sys.argv[1] is not "run": if len(sys.argv) is not 2 and sys.argv[1] is not "run":
print("[ERROR] Command cannot be parsed. Exiting...") print("[ERROR] Command cannot be parsed. Exiting...")
return return
configuration, metrics = cnfparse.import_conf("config/client.conf")
configuration, metrics = cnfparse.importConf("config/client.conf")
cli = client.Client(configuration) cli = client.Client(configuration)
cli.startReporting( metricCollectors = collectables.provide(metrics)
metricCollectors=collectables.collectables.provide(metrics)) cli.run(metricCollectors)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -46,34 +46,38 @@ class Client: ...@@ -46,34 +46,38 @@ class Client:
self.amqp_pass = str(os.getenv(self.env_config['amqp_pass'])) self.amqp_pass = str(os.getenv(self.env_config['amqp_pass']))
self.amqp_queue = str(os.getenv(self.env_config['amqp_queue'])) self.amqp_queue = str(os.getenv(self.env_config['amqp_queue']))
self.amqp_vhost = str(os.getenv(self.env_config['amqp_vhost'])) self.amqp_vhost = str(os.getenv(self.env_config['amqp_vhost']))
if self.server_address is "": host_check = self.__check_envvar(self.server_address)
port_check = self.__check_envvar(self.server_port)
amqp_pass_check = self.__check_envvar(self.amqp_pass)
amqp_user_check = self.__check_envvar(self.amqp_user)
amqp_queue_check = self.__check_envvar(self.amqp_queue)
amqp_vhost_check = self.__check_envvar(self.amqp_vhost)
if host_check:
print(('%(host)s cannot be found in environmental variables.') print(('%(host)s cannot be found in environmental variables.')
% {'host': self.env_config['host']} % {'host': self.env_config['host']}
) )
self.valid = False raise RuntimeError
return if port_check:
if self.server_port is "":
print(('%(port)s cannot be found in environmental variables. ') print(('%(port)s cannot be found in environmental variables. ')
% {'port': self.env_config['port']} % {'port': self.env_config['port']}
) )
self.valid = False raise RuntimeError
return if amqp_user_check or amqp_pass_check:
if self.amqp_user is "" or self.amqp_pass is "":
print(('%(user)s or %(pass)s cannot be ' print(('%(user)s or %(pass)s cannot be '
'found in environmental variables.') 'found in environmental variables.')
% {'user': self.env_config['amqp_user'], % {'user': self.env_config['amqp_user'],
'pass': self.env_config['amqp_pass']} 'pass': self.env_config['amqp_pass']}
) )
self.valid = False raise RuntimeError
return amqp_pass_check = self.__check_envvar(self.amqp_pass)
if self.amqp_queue is "" or self.amqp_vhost is "": amqp_user_check = self.__check_envvar(self.amqp_user)
if amqp_vhost_check or amqp_queue_check:
print(('%(queue)s or %(vhost)s cannot be ' print(('%(queue)s or %(vhost)s cannot be '
'found in environmental variables.') 'found in environmental variables.')
% {'queue': self.env_config['amqp_queue'], % {'queue': self.env_config['amqp_queue'],
'vhost': self.env_config['amqp_vhost']} 'vhost': self.env_config['amqp_vhost']}
) )
self.valid = False raise RuntimeError
return
self.debugMode = config["debugMode"] self.debugMode = config["debugMode"]
self.kvmCPU = int(config["kvmCpuUsage"]) self.kvmCPU = int(config["kvmCpuUsage"])
self.kvmMem = int(config["kvmMemoryUsage"]) self.kvmMem = int(config["kvmMemoryUsage"])
...@@ -81,6 +85,9 @@ class Client: ...@@ -81,6 +85,9 @@ class Client:
self.beat = 1 self.beat = 1
self.valid = True self.valid = True
def __check_envvar(variable):
return variable == "None" or variable == ""
def connect(self): def connect(self):
""" """
This method creates the connection to the queue of the graphite This method creates the connection to the queue of the graphite
...@@ -258,14 +265,12 @@ class Client: ...@@ -258,14 +265,12 @@ class Client:
metricCollectors parameter that should be provided by the collectables metricCollectors parameter that should be provided by the collectables
modul to work properly. modul to work properly.
""" """
if self.valid is False:
print("[ERROR] The client cannot be started.")
raise RuntimeError
if self.connect() is False: if self.connect() is False:
hostdata = self.server_address + ':' + self.server_port hostdata = self.server_address + ':' + str(self.server_port)
print("[ERROR] An error has occured while connecting to the " print("[ERROR] An error has occured while connecting to the "
"server on %(host)s." "server on %(host)s."
% {'host': hostdata}) % {'host': hostdata})
return
else: else:
print('[SUCCESS] Connection established to %(host)s:%(port)s.' print('[SUCCESS] Connection established to %(host)s:%(port)s.'
% {'host': self.server_address, % {'host': self.server_address,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment