diff --git a/code/scripts/main/core/modules/mod_analyst.py b/code/scripts/main/core/modules/mod_analyst.py index 95cd330..21fe53c 100644 --- a/code/scripts/main/core/modules/mod_analyst.py +++ b/code/scripts/main/core/modules/mod_analyst.py @@ -4,7 +4,7 @@ Langage: Python Minimum version require: 3.4 Module function: -The goal of this module is to analyse the differents clusters and node +The goal of this module is to analyse clusters and nodes to allocate news instances. """ @@ -56,6 +56,10 @@ class Analyse: self.clusters_conf = self.mongo.get_clusters_conf()["value"] + + def threadcrawl(self): + return + def run(self, instancetype="all"): """ Active logger""" self.logger.write({"thread":threading.get_ident(), "result": "INFO", "type": "HYPERPROXMOX", "value": "Start logger - Analyst Module"}) @@ -180,33 +184,34 @@ class Analyse: instance["macaddr"] = maclist """ Following instance ID """ - getidfromdesc = re.search("id=\"([A-Z\.\d\_]+)\"", currentdesc) - # Set unique id if not found - if getidfromdesc is None: - # ajouter un test de duplicateid - """ General description """ - randtext = ''.join(random.choice('AZERTYUIOPQSDFGHJKLMWXCVBN') for i in range(8)) - uniqid = "-- Please, do not change or delete this ID -- \n" \ - "id=\"{0}_{1}\"\n------------------\n{2}".format(insert_time, randtext, - currentdesc) - instance["description"] = uniqid + if self.generalconf["analyst"]["walker_uid"]: + getidfromdesc = re.search("id=\"([A-Z\.\d\_]+)\"", currentdesc) + # Set unique id if not found + if getidfromdesc is None: + # ajouter un test de duplicateid + """ General description """ + randtext = ''.join(random.choice('AZERTYUIOPQSDFGHJKLMWXCVBN') for i in range(8)) + uniqid = "-- Please, do not change or delete this ID -- \n" \ + "id=\"{0}_{1}\"\n------------------\n{2}".format(insert_time, randtext, + currentdesc) + instance["description"] = uniqid - idlist.append(uniqid) - """ INSTANCE DEFINITION """ - datadesc = {'description': uniqid} - resultsetdesc = proxmox.change_instances("{0}:{1}".format(cluster["url"], int(cluster["port"])), - value_nodes_list["node"], instance["type"], instance["vmid"], datadesc) - instance["uniqid"] = "{0}_{1}".format(insert_time, randtext) + idlist.append(uniqid) + """ INSTANCE DEFINITION """ + datadesc = {'description': uniqid} + resultsetdesc = proxmox.change_instances("{0}:{1}".format(cluster["url"], int(cluster["port"])), + value_nodes_list["node"], instance["type"], instance["vmid"], datadesc) + instance["uniqid"] = "{0}_{1}".format(insert_time, randtext) - else: - instance["uniqid"] = getidfromdesc.group(1) - if getidfromdesc.group(1) in idlist: - self.logger.write( - {"thread":threading.get_ident(), "result": "WARNING", "type": "HYPERPROXMOX", "value": "Double ID detected: {0}".format(getidfromdesc.group(1))}) - self.logger.write({"thread":threading.get_ident(), "result": "WARNING", "type": "HYPERPROXMOX", "value": json.dumps(instance)}) - self.logger.write({"thread":threading.get_ident(), "result": "WARNING", "type": "HYPERPROXMOX", "value": "-------------------"}) else: - idlist.append(getidfromdesc.group(1)) + instance["uniqid"] = getidfromdesc.group(1) + if getidfromdesc.group(1) in idlist: + self.logger.write( + {"thread":threading.get_ident(), "result": "WARNING", "type": "HYPERPROXMOX", "value": "Double ID detected: {0}".format(getidfromdesc.group(1))}) + self.logger.write({"thread":threading.get_ident(), "result": "WARNING", "type": "HYPERPROXMOX", "value": json.dumps(instance)}) + self.logger.write({"thread":threading.get_ident(), "result": "WARNING", "type": "HYPERPROXMOX", "value": "-------------------"}) + else: + idlist.append(getidfromdesc.group(1)) self.mongo.insert_instances(instance) diff --git a/code/scripts/main/private/conf/config b/code/scripts/main/private/conf/config index 29c1c3a..c936df1 100644 --- a/code/scripts/main/private/conf/config +++ b/code/scripts/main/private/conf/config @@ -8,7 +8,6 @@ key_pub: private/keys/Ragnarok.pub.key admin_mail: tlams@localhost - [web] user: www-data @@ -45,6 +44,9 @@ walker: 300 ; Lock file -- prevent concurrent crawling walker_lock: /tmp/hyperproxmoxwalker.lock +; Set an unique ID (change comment part) +uid = False + [logger] ; logs level 1: "INFO", 2: "WARNING", 3: "ERROR", 4: "CRITICAL", 5: "DEBUG" logs_level = 5 diff --git a/code/scripts/main/startup.py b/code/scripts/main/startup.py index 14237ec..a57e4bd 100644 --- a/code/scripts/main/startup.py +++ b/code/scripts/main/startup.py @@ -37,7 +37,9 @@ if __name__ == "__main__": "logs_dir": localconf['logger']['logs_dir'], "bulk_write": localconf['logger']['bulk_write'], "bulk_size": localconf['logger']['bulk_size']}, - "analyst": {"walker": localconf['walker']['walker'], "walker_lock": localconf['walker']['walker_lock']}, + "analyst": {"walker": localconf['walker']['walker'], "walker_lock": localconf['walker']['walker_lock'], + "walker_uid": localconf['walker']['uid'] + }, "mongodb": {"ip": localconf['databases']['mongodb_ip'], 'port': localconf['databases']['mongodb_port']},