Commit 977465d6 by Gregory Nagy

Fixtures

parent ec91e24f
import sys
from src import cnfparse, client, collectables
from src import cnfparse
from src import client
from src.collectables import collectables
def main():
if len(sys.argv) < 2:
print("usage: manage.py run [options]")
if len(sys.argv) is not 2 and sys.argv[1] is not "run":
print("[ERROR] Command cannot be parsed. Exiting...")
return
configuration, metrics = cnfparse.importConf("config/client.conf")
configuration, metrics = cnfparse.import_conf("config/client.conf")
cli = client.Client(configuration)
cli.startReporting(
metricCollectors=collectables.collectables.provide(metrics))
metricCollectors = collectables.provide(metrics)
cli.run(metricCollectors)
if __name__ == "__main__":
......
......@@ -46,34 +46,38 @@ class Client:
self.amqp_pass = str(os.getenv(self.env_config['amqp_pass']))
self.amqp_queue = str(os.getenv(self.env_config['amqp_queue']))
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.')
% {'host': self.env_config['host']}
)
self.valid = False
return
if self.server_port is "":
raise RuntimeError
if port_check:
print(('%(port)s cannot be found in environmental variables. ')
% {'port': self.env_config['port']}
)
self.valid = False
return
if self.amqp_user is "" or self.amqp_pass is "":
raise RuntimeError
if amqp_user_check or amqp_pass_check:
print(('%(user)s or %(pass)s cannot be '
'found in environmental variables.')
% {'user': self.env_config['amqp_user'],
'pass': self.env_config['amqp_pass']}
)
self.valid = False
return
if self.amqp_queue is "" or self.amqp_vhost is "":
raise RuntimeError
amqp_pass_check = self.__check_envvar(self.amqp_pass)
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 '
'found in environmental variables.')
% {'queue': self.env_config['amqp_queue'],
'vhost': self.env_config['amqp_vhost']}
)
self.valid = False
return
raise RuntimeError
self.debugMode = config["debugMode"]
self.kvmCPU = int(config["kvmCpuUsage"])
self.kvmMem = int(config["kvmMemoryUsage"])
......@@ -81,6 +85,9 @@ class Client:
self.beat = 1
self.valid = True
def __check_envvar(variable):
return variable == "None" or variable == ""
def connect(self):
"""
This method creates the connection to the queue of the graphite
......@@ -258,14 +265,12 @@ class Client:
metricCollectors parameter that should be provided by the collectables
modul to work properly.
"""
if self.valid is False:
print("[ERROR] The client cannot be started.")
raise RuntimeError
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 "
"server on %(host)s."
% {'host': hostdata})
return
else:
print('[SUCCESS] Connection established to %(host)s:%(port)s.'
% {'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