diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba0430d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ \ No newline at end of file diff --git a/Snap-Tool/modules/ConfigurationClass.py b/Snap-Tool/modules/ConfigurationClass.py index 42063cd..a3cb072 100644 --- a/Snap-Tool/modules/ConfigurationClass.py +++ b/Snap-Tool/modules/ConfigurationClass.py @@ -3,8 +3,7 @@ from modules.LoggerClass import Logger """ -Class that manages everything related to the Snap-Tool -configuration file. +Class that manages everything related to the Snap-Tool configuration file. """ class Configuration: """ @@ -18,7 +17,7 @@ class Configuration: logger = None """ - Property that stores an object of type FormDialogs. + Property that stores an object of type FormDialog. """ form_dialog = None @@ -32,6 +31,7 @@ class Configuration: Parameters: self -- An instantiated object of the Configuration class. + form_dialog -- FormDialog class object. """ def __init__(self, form_dialog): self.logger = Logger() @@ -60,7 +60,7 @@ def createConfiguration(self): valid_certificate = self.form_dialog.getDataYesOrNo("\nDo you want the certificate for SSL/TLS communication to be validated?", "Certificate Validation") if valid_certificate == "ok": data_conf.append(True) - path_cert_file = self.form_dialog.getFile('/etc/Snap-Tool', "Select the CA certificate:") + path_cert_file = self.form_dialog.getFile('/etc/Snap-Tool', "Select the CA certificate:", ".pem") data_conf.append(path_cert_file) else: data_conf.append(False) @@ -86,10 +86,10 @@ def createConfiguration(self): data_conf.append(False) self.createFileConfiguration(data_conf) if path.exists(self.conf_file): - self.form_dialog.d.msgbox("\nConfiguration file created", 7, 50, title = "Notification Message") + self.form_dialog.d.msgbox(text = "\nConfiguration file created", height = 7, width = 50, title = "Notification Message") self.logger.createSnapToolLog("Configuration file created", 2) else: - self.form_dialog.d.msgbox("\nError creating configuration file. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nError creating configuration file. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() """ @@ -190,13 +190,13 @@ def updateConfiguration(self): del data_conf['path_certificate'] data_conf['valid_certificate'] = False elif opt_valid_cert_true == "Certificate File": - path_cert_file = self.form_dialog.getFile(data_conf['path_certificate'], "Select the CA certificate:") + path_cert_file = self.form_dialog.getFile(data_conf['path_certificate'], "Select the CA certificate:", ".pem") data_conf['path_certificate'] = path_cert_file else: opt_valid_cert_false = self.form_dialog.getDataRadioList("Select a option:", options_valid_cert_false, "Certificate Validation") if opt_valid_cert_false == "Enable": data_conf['valid_certificate'] = True - path_cert_file = self.form_dialog.getFile('/etc/Snap-Tool', "Select the CA certificate:") + path_cert_file = self.form_dialog.getFile('/etc/Snap-Tool', "Select the CA certificate:", ".pem") valid_cert_json = { 'path_certificate' : path_cert_file } data_conf.update(valid_cert_json) else: @@ -205,7 +205,7 @@ def updateConfiguration(self): data_conf['use_ssl'] = True valid_certificate = self.form_dialog.getDataYesOrNo("\nDo you want the certificates for SSL/TLS communication to be validated?", "Certificate Validation") if valid_certificate == "ok": - path_cert_file = self.form_dialog.getFile('/etc/Snap-Tool', "Select the CA certificate:") + path_cert_file = self.form_dialog.getFile('/etc/Snap-Tool', "Select the CA certificate:", ".pem") valid_cert_json = { 'valid_certificate' : True, 'path_certificate' : path_cert_file } else: valid_cert_json = { 'valid_certificate' : False } @@ -258,14 +258,14 @@ def updateConfiguration(self): self.utils.createYamlFile(data_conf, self.conf_file, 'w') hash_data_conf_upd = self.utils.getHashToFile(self.conf_file) if hash_data_conf == hash_data_conf_upd: - self.form_dialog.d.msgbox("\nThe configuration file was not modified.", 7, 50, title = "Notification Message") + self.form_dialog.d.msgbox(text = "\nThe configuration file was not modified.", height = 7, width = 50, title = "Notification Message") else: self.logger.createSnapToolLog("The configuration file was modified", 1) - self.form_dialog.d.msgbox("\nThe configuration file was modified.", 7, 50, title = "Notification Message") + self.form_dialog.d.msgbox(text = "\nThe configuration file was modified.", height = 7, width = 50, title = "Notification Message") self.form_dialog.mainMenu() except (OSError, KeyError) as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nError modifying the configuration file. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nError modifying the configuration file. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() """ diff --git a/Snap-Tool/modules/ElasticClass.py b/Snap-Tool/modules/ElasticClass.py index 93b0fcf..1a31b5e 100644 --- a/Snap-Tool/modules/ElasticClass.py +++ b/Snap-Tool/modules/ElasticClass.py @@ -117,33 +117,11 @@ def getConnectionElastic(self): self.logger.createSnapToolLog("Established connection with: " + self.snap_tool_conf['es_host'] + ':' + str(self.snap_tool_conf['es_port']), 1) except (KeyError, exceptions.ConnectionError, exceptions.AuthenticationException, exceptions.AuthorizationException, InvalidURL) as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nFailed to connect to ElasticSearch. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nFailed to connect to ElasticSearch. For more information, see the logs.", height = 8, width = 50, title = "Error Message") exit(1) else: return conn_es - """ - Method that creates a snapshot of an index. - - Parameters: - self -- An instantiated object of the Elastic class. - conn_es -- Object that contains the connection to ElasticSearch. - repository_name -- Repository where the snapshot will be stored. - index_name -- Name of the index to be backed up in the snapshot. - - Exceptions: - exceptions.RequestError -- Exception representing a 400 status code. - exceptions.NotFoundError -- Exception representing a 404 status code. - exceptions.AuthorizationException -- Exception representing a 403 status code. - """ - def createSnapshot(self, conn_es, repository_name, index_name): - try: - conn_es.snapshot.create(repository = repository_name, snapshot = index_name, body = { 'indices' : index_name, "include_global_state" : False }, wait_for_completion = False) - except (exceptions.AuthorizationException, exceptions.RequestError, exceptions.NotFoundError) as exception: - self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nFailed to create snapshot. For more information, see the logs.", 8, 50, title = "Error Message") - self.form_dialog.mainMenu() - """ Method that creates a repository type FS. @@ -165,7 +143,7 @@ def createRepositoryFS(self, conn_es, repository_name, path_repository, compress body = { "type": "fs", "settings": { "location": path_repository, "compress" : compress_repository }}) except (exceptions.AuthorizationException, exceptions.ConnectionError, exceptions.TransportError) as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nError creating repository. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nError creating repository. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() """ @@ -179,155 +157,177 @@ def createRepositoryFS(self, conn_es, repository_name, path_repository, compress Exceptions: exceptions.NotFoundError -- Exception representing a 404 status code. exceptions.AuthorizationException -- Exception representing a 403 status code. + exceptions.ConnectionError -- Error raised when there was an exception while talking to ES. """ def deleteRepositoryFS(self, conn_es, repository_name): try: conn_es.snapshot.delete_repository(repository = repository_name) - except (exceptions.NotFoundError, exceptions.AuthorizationException) as exception: + except (exceptions.NotFoundError, exceptions.AuthorizationException, exceptions.ConnectionError) as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nFailed to delete repository. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nFailed to delete repository. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() """ - Method that gets the status of a snapshot. + Method that creates a snapshot of an index. Parameters: self -- An instantiated object of the Elastic class. conn_es -- Object that contains the connection to ElasticSearch. - repository_name -- Repository where the snapshot is stored. - snapshot_name -- Name of the snapshot from which the status will be obtained. + repository_name -- Repository where the snapshot will be stored. + index_name -- Name of the index to be backed up in the snapshot. - Return: - status_snapshot -- Status of the snapshot. + Exceptions: + exceptions.RequestError -- Exception representing a 400 status code. + exceptions.NotFoundError -- Exception representing a 404 status code. + exceptions.AuthorizationException -- Exception representing a 403 status code. + exceptions.ConnectionError -- Error raised when there was an exception while talking to ES. + """ + def createSnapshot(self, conn_es, repository_name, index_name): + try: + conn_es.snapshot.create(repository = repository_name, snapshot = index_name, body = { 'indices' : index_name, "include_global_state" : False }, wait_for_completion = False) + except (exceptions.AuthorizationException, exceptions.RequestError, exceptions.NotFoundError, exceptions.ConnectionError) as exception: + self.logger.createSnapToolLog(exception, 3) + self.form_dialog.d.msgbox(text = "\nFailed to create snapshot. For more information, see the logs.", height = 8, width = 50, title = "Error Message") + self.form_dialog.mainMenu() + + """ + Method that removes a snapshot. + + Parameters: + conn_es -- Object that contains the connection to ElasticSearch. + repository_name -- Name of the repository where the snapshot to delete is stored. + snapshot_name -- Name of the snapshot to delete. Exceptions: exceptions.NotFoundError -- Exception representing a 404 status code. exceptions.AuthorizationException -- Exception representing a 403 status code. + exceptions.ConnectionError -- Error raised when there was an exception while talking to ES. """ - def getStatusSnapshot(self, conn_es, repository_name, snapshot_name): + def deleteSnapshotElastic(self, conn_es, repository_name, snapshot_name): try: - status_aux = conn_es.snapshot.status(repository = repository_name, snapshot = snapshot_name) - status_snapshot = status_aux['snapshots'][0]['state'] - except (exceptions.NotFoundError, exceptions.AuthorizationException) as exception: + conn_es.snapshot.delete(repository = repository_name, snapshot = snapshot_name, request_timeout = 7200) + except (exceptions.NotFoundError, exceptions.AuthorizationException, exceptions.ConnectionError) as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nFailed to get snapshot status. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nFailed to delete snapshot. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() - else: - return status_snapshot """ - Method that gets the status of a snapshot. + Method that restores a snapshot. Parameters: - self -- An instantiated object of the Elastic class. conn_es -- Object that contains the connection to ElasticSearch. repository_name -- Repository where the snapshot is stored. - snapshot_name -- Name of the snapshot from which the information will be obtained. - - Return: - snapshot_info -- Information obtained from the snapshot. + snapshot_name -- Name of the snapshot to restore. Exceptions: exceptions.NotFoundError -- Exception representing a 404 status code. exceptions.AuthorizationException -- Exception representing a 403 status code. + exceptions.ConnectionError -- Error raised when there was an exception while talking to ES. """ - def getSnapshotInfo(self, conn_es, repository_name, snapshot_name): + def restoreSnapshot(self, conn_es, repository_name, snapshot_name): try: - snapshot_info = conn_es.snapshot.get(repository = repository_name, snapshot = snapshot_name) - except (exceptions.NotFoundError, exceptions.AuthorizationException) as exception: + conn_es.snapshot.restore(repository = repository_name, snapshot = snapshot_name) + except (exceptions.NotFoundError, exceptions.AuthorizationException, exceptions.ConnectionError) as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nFailed to get snapshot status. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nFailed to restore snapshot. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() - else: - return snapshot_info """ - Method that gets a list of all the snapshots created so far. + Method that mounts a snapshot as a searchable snapshot. Parameters: conn_es -- Object that contains the connection to ElasticSearch. - repository_name -- Repository where the snapshots are stored. - - Return: - list_all_snapshots -- List with the names of all snapshots found in the repository. + repository_name -- Name of the repository where the snapshot that will be mounted as a searchable snapshot is stored. + snapshot_name -- Name of the snapshot to be mounted as a searchable snapshot. Exceptions: exceptions.NotFoundError -- Exception representing a 404 status code. exceptions.AuthorizationException -- Exception representing a 403 status code. + exceptions.ConnectionError -- Error raised when there was an exception while talking to ES. """ - def getAllSnapshots(self, conn_es, repository_name): - list_all_snapshots = [] + def mountSearchableSnapshot(self, conn_es, repository_name, snapshot_name): try: - snapshots_info = conn_es.snapshot.get(repository = repository_name, snapshot = '_all') - for snapshot in snapshots_info['snapshots']: - list_all_snapshots.append(snapshot['snapshot']) - list_all_snapshots = sorted(list_all_snapshots) - except (exceptions.NotFoundError, exceptions.AuthorizationException) as exception: + conn_es.searchable_snapshots.mount(repository = repository_name, snapshot = snapshot_name, body = { "index" : snapshot_name }, wait_for_completion = False, request_timeout = 7200) + except (exceptions.NotFoundError, exceptions.AuthorizationException, exceptions.ConnectionError) as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nFailed to get snapshots. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nFailed to mount snapshot as a searchable snapshot. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() - else: - return list_all_snapshots """ - Method that restores a snapshot. + Method that removes an index from ElasticSearch. Parameters: + self -- An instantiated object of the Elastic class. conn_es -- Object that contains the connection to ElasticSearch. - repository_name -- Repository where the snapshot is stored. - snapshot_name -- Name of the snapshot to restore. + index_name -- Name of the index to be removed. Exceptions: exceptions.NotFoundError -- Exception representing a 404 status code. exceptions.AuthorizationException -- Exception representing a 403 status code. + exceptions.ConnectionError -- Error raised when there was an exception while talking to ES. """ - def restoreSnapshot(self, conn_es, repository_name, snapshot_name): + def deleteIndex(self, conn_es, index_name): try: - conn_es.snapshot.restore(repository = repository_name, snapshot = snapshot_name) - except (exceptions.NotFoundError, exceptions.AuthorizationException) as exception: + conn_es.indices.delete(index = index_name) + except (exceptions.NotFoundError, exceptions.AuthorizationException, exceptions.ConnectionError) as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nFailed to restore snapshot. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nFailed to delete index. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() - + """ - Method that removes a snapshot. + Method that gets the status of a snapshot. Parameters: + self -- An instantiated object of the Elastic class. conn_es -- Object that contains the connection to ElasticSearch. - repository_name -- Name of the repository where the snapshot to delete is stored. - snapshot_name -- Name of the snapshot to delete. + repository_name -- Repository where the snapshot is stored. + snapshot_name -- Name of the snapshot from which the status will be obtained. + + Return: + status_snapshot -- Status of the snapshot. Exceptions: exceptions.NotFoundError -- Exception representing a 404 status code. exceptions.AuthorizationException -- Exception representing a 403 status code. + exceptions.ConnectionError -- Error raised when there was an exception while talking to ES. """ - def deleteSnapshotElastic(self, conn_es, repository_name, snapshot_name): + def getStatusSnapshot(self, conn_es, repository_name, snapshot_name): try: - conn_es.snapshot.delete(repository = repository_name, snapshot = snapshot_name, request_timeout = 7200) - except (exceptions.NotFoundError, exceptions.AuthorizationException) as exception: + status_aux = conn_es.snapshot.status(repository = repository_name, snapshot = snapshot_name) + status_snapshot = status_aux['snapshots'][0]['state'] + except (exceptions.NotFoundError, exceptions.AuthorizationException, exceptions.ConnectionError) as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nFailed to delete snapshot. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nFailed to get snapshot status. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() + else: + return status_snapshot """ - Method that mounts a snapshot as a searchable snapshot. + Method that gets the status of a snapshot. Parameters: + self -- An instantiated object of the Elastic class. conn_es -- Object that contains the connection to ElasticSearch. - repository_name -- Name of the repository where the snapshot that will be mounted as a searchable snapshot is stored. - snapshot_name -- Name of the snapshot to be mounted as a searchable snapshot. + repository_name -- Repository where the snapshot is stored. + snapshot_name -- Name of the snapshot from which the information will be obtained. + + Return: + snapshot_info -- Information obtained from the snapshot. Exceptions: exceptions.NotFoundError -- Exception representing a 404 status code. exceptions.AuthorizationException -- Exception representing a 403 status code. + exceptions.ConnectionError -- Error raised when there was an exception while talking to ES. """ - def mountSearchableSnapshot(self, conn_es, repository_name, snapshot_name): + def getSnapshotInfo(self, conn_es, repository_name, snapshot_name): try: - conn_es.searchable_snapshots.mount(repository = repository_name, snapshot = snapshot_name, body = { "index" : snapshot_name }, wait_for_completion = False, request_timeout = 7200) - except (exceptions.NotFoundError, exceptions.AuthorizationException) as exception: + snapshot_info = conn_es.snapshot.get(repository = repository_name, snapshot = snapshot_name) + except (exceptions.NotFoundError, exceptions.AuthorizationException, exceptions.ConnectionError) as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nFailed to mount snapshot as a searchable snapshot. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nFailed to get snapshot status. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() + else: + return snapshot_info """ Method that obtains a list with the names of the ElasticSearch indexes. @@ -341,82 +341,93 @@ def mountSearchableSnapshot(self, conn_es, repository_name, snapshot_name): Exceptions: exceptions.AuthorizationException -- Exception representing a 403 status code. + exceptions.ConnectionError -- Error raised when there was an exception while talking to ES. """ def getIndices(self, conn_es): list_all_indices = [] try: list_all_indices = conn_es.indices.get('*') list_all_indices = sorted([index for index in list_all_indices if not index.startswith(".")]) - except exceptions.AuthorizationException as exception: + except (exceptions.AuthorizationException, exceptions.ConnectionError) as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nFailed to get created repositories. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nFailed to get created repositories. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() else: return list_all_indices """ - Method that gets the repositories created in ElasticSearch. + Method that gets a list of all the snapshots created so far. Parameters: - self -- An instantiated object of the Elastic class. conn_es -- Object that contains the connection to ElasticSearch. + repository_name -- Repository where the snapshots are stored. Return: - list_all_repositories -- List with the names of the repositories found. + list_all_snapshots -- List with the names of all snapshots found in the repository. Exceptions: + exceptions.NotFoundError -- Exception representing a 404 status code. exceptions.AuthorizationException -- Exception representing a 403 status code. + exceptions.ConnectionError -- Error raised when there was an exception while talking to ES. """ - def getAllRepositories(self, conn_es): - list_all_repositories = [] + def getAllSnapshots(self, conn_es, repository_name): + list_all_snapshots = [] try: - repositories_info = conn_es.cat.repositories(format = "json") - for repository in repositories_info: - list_all_repositories.append(repository['id']) - except exceptions.AuthorizationException as exception: + snapshots_info = conn_es.snapshot.get(repository = repository_name, snapshot = '_all') + for snapshot in snapshots_info['snapshots']: + list_all_snapshots.append(snapshot['snapshot']) + list_all_snapshots = sorted(list_all_snapshots) + except (exceptions.NotFoundError, exceptions.AuthorizationException, exceptions.ConnectionError) as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nFailed to get created repositories. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nFailed to get snapshots. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() else: - return list_all_repositories + return list_all_snapshots """ - Method that obtains information related to the disk space corresponding to the nodes belonging to the elasticsearch cluster. + Method that gets the repositories created in ElasticSearch. Parameters: self -- An instantiated object of the Elastic class. conn_es -- Object that contains the connection to ElasticSearch. + Return: + list_all_repositories -- List with the names of the repositories found. + Exceptions: exceptions.AuthorizationException -- Exception representing a 403 status code. + exceptions.ConnectionError -- Error raised when there was an exception while talking to ES. """ - def getNodesInformation(self, conn_es): + def getAllRepositories(self, conn_es): + list_all_repositories = [] try: - nodes_info = conn_es.nodes.stats(metric = 'fs')['nodes'] - except exceptions.AuthorizationException as exception: + repositories_info = conn_es.cat.repositories(format = "json") + for repository in repositories_info: + list_all_repositories.append(repository['id']) + except (exceptions.AuthorizationException, exceptions.ConnectionError) as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nError when obtaining the information of the nodes. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nFailed to get created repositories. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() else: - return nodes_info + return list_all_repositories """ - Method that removes an index from ElasticSearch. + Method that obtains information related to the disk space corresponding to the nodes belonging to the elasticsearch cluster. Parameters: self -- An instantiated object of the Elastic class. conn_es -- Object that contains the connection to ElasticSearch. - index_name -- Name of the index to be removed. Exceptions: - exceptions.NotFoundError -- Exception representing a 404 status code. exceptions.AuthorizationException -- Exception representing a 403 status code. exceptions.ConnectionError -- Error raised when there was an exception while talking to ES. """ - def deleteIndex(self, conn_es, index_name): + def getNodesInformation(self, conn_es): try: - conn_es.indices.delete(index = index_name) - except (exceptions.NotFoundError, exceptions.AuthorizationException, exceptions.ConnectionError) as exception: + nodes_info = conn_es.nodes.stats(metric = 'fs')['nodes'] + except (exceptions.AuthorizationException, exceptions.ConnectionError) as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nFailed to delete index. For more information, see the logs.", 8, 50, title = "Error Message") - self.form_dialog.mainMenu() \ No newline at end of file + self.form_dialog.d.msgbox(text = "\nError when obtaining the information of the nodes. For more information, see the logs.", height = 8, width = 50, title = "Error Message") + self.form_dialog.mainMenu() + else: + return nodes_info \ No newline at end of file diff --git a/Snap-Tool/modules/FormClass.py b/Snap-Tool/modules/FormClass.py index efdd15e..da4836d 100644 --- a/Snap-Tool/modules/FormClass.py +++ b/Snap-Tool/modules/FormClass.py @@ -100,7 +100,7 @@ def getDataNumberDecimal(self, text, initial_value): init = initial_value) if code_inputbox == self.d.OK: if(not self.utils.validateRegularExpression(decimal_reg_exp, tag_inputbox)): - self.d.msgbox("\nInvalid data entered. Required value (decimal or float).", 8, 50, title = "Error Message") + self.d.msgbox(text = "\nInvalid data entered. Required value (decimal or float).", height = 8, width = 50, title = "Error Message") else: return tag_inputbox elif code_inputbox == self.d.CANCEL: @@ -126,7 +126,7 @@ def getDataIP(self, text, initial_value): init = initial_value) if code_inputbox == self.d.OK: if(not self.utils.validateRegularExpression(ip_reg_exp, tag_inputbox)): - self.d.msgbox("\nInvalid data entered. Required value (IP address).", 8, 50, title = "Error Message") + self.d.msgbox(text = "\nInvalid data entered. Required value (IP address).", height = 8, width = 50, title = "Error Message") else: return tag_inputbox elif code_inputbox == self.d.CANCEL: @@ -152,7 +152,7 @@ def getDataPort(self, text, initial_value): init = initial_value) if code_inputbox == self.d.OK: if(not self.utils.validateRegularExpression(port_reg_exp, tag_inputbox)): - self.d.msgbox("\nInvalid data entered. Required value (0 - 65535).", 8, 50, title = "Error Message") + self.d.msgbox(text = "\nInvalid data entered. Required value (0 - 65535).", height = 8, width = 50, title = "Error Message") else: return tag_inputbox elif code_inputbox == self.d.CANCEL: @@ -177,7 +177,7 @@ def getDataInputText(self, text, initial_value): init = initial_value) if code_inputbox == self.d.OK: if tag_inputbox == "": - self.d.msgbox("\nInvalid data entered. Required value (not empty).", 8, 50, title = "Error Message") + self.d.msgbox(text = "\nInvalid data entered. Required value (not empty).", height = 8, width = 50, title = "Error Message") else: return tag_inputbox elif code_inputbox == self.d.CANCEL: @@ -203,7 +203,7 @@ def getDataPassword(self, text, initial_value): insecure = True) if code_passwordbox == self.d.OK: if tag_passwordbox == "": - self.d.msgbox("\nInvalid data entered. Required value (not empty).", 8, 50, title = "Error Message") + self.d.msgbox(text = "\nInvalid data entered. Required value (not empty).", height = 8, width = 50, title = "Error Message") else: return tag_passwordbox elif code_passwordbox == self.d.CANCEL: @@ -247,7 +247,7 @@ def getDataRadioList(self, text, options, title): title = title) if code_radiolist == self.d.OK: if len(tag_radiolist) == 0: - self.d.msgbox("\nSelect at least one option.", 7, 50, title = "Error Message") + self.d.msgbox(text = "\nSelect at least one option.", height = 7, width = 50, title = "Error Message") else: return tag_radiolist elif code_radiolist == self.d.CANCEL: @@ -273,7 +273,7 @@ def getDataCheckList(self, text, options, title): title = title) if code_checklist == self.d.OK: if len(tag_checklist) == 0: - self.d.msgbox("\nSelect at least one option.", 7, 50, title = "Error Message") + self.d.msgbox(text = "\nSelect at least one option.", height = 7, width = 50, title = "Error Message") else: return tag_checklist elif code_checklist == self.d.CANCEL: @@ -286,11 +286,12 @@ def getDataCheckList(self, text, options, title): self -- An instantiated object of the FormDialogs class. initial_path -- Initial path in the interface. title -- Title displayed on the interface. + extension_file -- Allowed file extension. Return: tag_fselect -- Path of the selected file. """ - def getFile(self, initial_path, title): + def getFile(self, initial_path, title, extension_file): while True: code_fselect, tag_fselect = self.d.fselect(filepath = initial_path, height = 8, @@ -298,11 +299,11 @@ def getFile(self, initial_path, title): title = title) if code_fselect == self.d.OK: if tag_fselect == "": - self.d.msgbox("\nSelect a file. Required value (PEM file).", 7, 50, title = "Error Message") + self.d.msgbox(text = "\nSelect a file. Required value: " + extension_file + " file.", height = 7, width = 50, title = "Error Message") else: ext_file = Path(tag_fselect).suffix - if not ext_file == ".pem": - self.d.msgbox("\nSelect a file. Required value (PEM file).", 7, 50, title = "Error Message") + if not ext_file == extension_file: + self.d.msgbox(text = "\nSelect a file. Required value: " + extension_file + " file.", height = 7, width = 50, title = "Error Message") else: return tag_fselect elif code_fselect == self.d.CANCEL: @@ -327,7 +328,7 @@ def getDirectory(self, initial_path, title): title = title) if code_dselect == self.d.OK: if tag_dselect == "": - self.d.msgbox("\nSelect a directory. Required value (not empty).", 7, 50, title = "Error Message") + self.d.msgbox(text = "\nSelect a directory. Required value (not empty).", height = 7, width = 50, title = "Error Message") else: return tag_dselect elif code_dselect == self.d.CANCEL: @@ -381,7 +382,7 @@ def defineConfiguration(self): def createRepository(self): try: if not path.exists(self.path_conf_file): - self.d.msgbox("\nConfiguration file not found.", 7, 50, title = "Error Message") + self.d.msgbox(text = "\nConfiguration file not found.", height = 7, width = 50, title = "Error Message") else: repository_name = self.getDataInputText("Enter the name to be assigned to the repository:", "repository_name") path_repository = self.getDirectory("/etc/Snap-Tool", "Repository path") @@ -396,12 +397,12 @@ def createRepository(self): message_create_repository = self.telegram.getMessageCreateRepository(repository_name, path_repository, compress_repository) self.telegram.sendTelegramAlert(self.utils.decryptAES(snap_tool_conf['telegram_chat_id']).decode('utf-8'), self.utils.decryptAES(snap_tool_conf['telegram_bot_token']).decode('utf-8'), message_create_repository) self.logger.createSnapToolLog("Repository created: " + repository_name, 1) - self.d.msgbox("\nRepository created: " + repository_name, 7, 50, title = "Notification Message") + self.d.msgbox(text = "\nRepository created: " + repository_name, height = 7, width = 50, title = "Notification Message") conn_es.transport.close() self.mainMenu() except KeyError as exception: - self.logger.createSnapToolLog(exception, 3) - self.d.msgbox("\nFailed to create snapshot. For more information, see the logs.", 8, 50, title = "Error Message") + self.logger.createSnapToolLog("Key Error: " + exception, 3) + self.d.msgbox(text = "\nFailed to create snapshot. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.mainMenu() """ @@ -416,14 +417,14 @@ def createRepository(self): def deleteRepository(self): try: if not path.exists(self.path_conf_file): - self.d.msgbox("\nConfiguration file not found.", 7, 50, title = "Error Message") + self.d.msgbox(text = "\nConfiguration file not found.", height = 7, width = 50, title = "Error Message") else: - snap_tool_conf = self.utils.readYamlFile(self.path_conf_file, 'r') conn_es = self.elastic.getConnectionElastic() list_aux_repositories = self.elastic.getAllRepositories(conn_es) if len(list_aux_repositories) == 0: - self.d.msgbox("\nThere are no repositories created.", 7, 50, title = "Notification Message") + self.d.msgbox(text = "\nThere are no repositories created.", height = 7, width = 50, title = "Notification Message") else: + snap_tool_conf = self.utils.readYamlFile(self.path_conf_file, 'r') list_all_repositories = self.utils.convertListToCheckOrRadioList(list_aux_repositories, "Repository Name") opt_repos = self.getDataCheckList("Select a option:", list_all_repositories, "Repositories") confirm_delete_repos = self.getDataYesOrNo("\nAre you sure to delete the following repository(s)?", "Delete repositories") @@ -440,7 +441,7 @@ def deleteRepository(self): self.mainMenu() except KeyError as exception: self.logger.createSnapToolLog("Key Error: " + exception, 3) - self.d.msgbox("\nFailed to delete repository. For more information, see the logs.", 8, 50, title = "Error Message") + self.d.msgbox(text = "\nFailed to delete repository. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.mainMenu() """ @@ -455,51 +456,57 @@ def deleteRepository(self): def createSnapshot(self): try: if not path.exists(self.path_conf_file): - self.d.msgbox("\nConfiguration file not found.", 7, 50, title = "Error Message") + self.d.msgbox(text = "\nConfiguration file not found.", height = 7, width = 50, title = "Error Message") else: - snap_tool_conf = self.utils.readYamlFile(self.path_conf_file, 'r') conn_es = self.elastic.getConnectionElastic() list_aux_indices = self.elastic.getIndices(conn_es) - list_all_indices = self.utils.convertListToCheckOrRadioList(list_aux_indices, "Index name") - opt_index = self.getDataRadioList("Select a option:", list_all_indices, "Indices") - list_aux_repositories = self.elastic.getAllRepositories(conn_es) - list_all_repositories = self.utils.convertListToCheckOrRadioList(list_aux_repositories, "Repository name") - opt_repo = self.getDataRadioList("Select a option:", list_all_repositories, "Repositories") - self.elastic.createSnapshot(conn_es, opt_repo, opt_index) - message_creation_start = self.telegram.getMessageStartCreationSnapshot(opt_index, opt_repo) - self.telegram.sendTelegramAlert(self.utils.decryptAES(snap_tool_conf['telegram_chat_id']).decode('utf-8'), self.utils.decryptAES(snap_tool_conf['telegram_bot_token']).decode('utf-8'), message_creation_start) - self.logger.createSnapToolLog("Snapshot creation has started: " + opt_index, 1) - while True: - status_snapshot = self.elastic.getStatusSnapshot(conn_es, opt_repo, opt_index) - if status_snapshot == "SUCCESS": - break - sleep(60) - snapshot_info = self.elastic.getSnapshotInfo(conn_es, opt_repo, opt_index) - self.logger.createSnapToolLog("Snapshot creation has finished: " + opt_index, 1) - message_creation_end = self.telegram.getMessageEndSnapshot(opt_index, opt_repo, snapshot_info['snapshots'][0]['start_time'], snapshot_info['snapshots'][0]['end_time']) - self.telegram.sendTelegramAlert(self.utils.decryptAES(snap_tool_conf['telegram_chat_id']).decode('utf-8'), self.utils.decryptAES(snap_tool_conf['telegram_bot_token']).decode('utf-8'), message_creation_end) - self.d.msgbox("\nSnapshot created: " + opt_index, 7, 50, title = "Notification Message") - if snap_tool_conf['is_delete_index'] == True: - self.elastic.deleteIndex(conn_es, opt_index) - if not conn_es.indices.exists(opt_index): - self.logger.createSnapToolLog("Index removed: " + opt_index, 1) - message_delete_index = self.telegram.getMessageDeleteIndex(opt_index) - self.telegram.sendTelegramAlert(self.utils.decryptAES(snap_tool_conf['telegram_chat_id']).decode('utf-8'), self.utils.decryptAES(snap_tool_conf['telegram_bot_token']).decode('utf-8'), message_delete_index) - self.d.msgbox("\nIndex removed: " + opt_index, 7, 50, title = "Notification Message") + if len(list_aux_indices) == 0: + self.d.msgbox(text = "\nThere are no indexes to back up.", height = 7, width = 50, title = "Notification Message") else: - delete_index = self.getDataYesOrNo("\nDo you want to delete the index?\n\n- " + opt_index, "Delete Index") - if delete_index == "ok": - self.elastic.deleteIndex(conn_es, opt_index) - if not conn_es.indices.exists(opt_index): - self.logger.createSnapToolLog("Index removed: " + opt_index, 1) - message_delete_index = self.telegram.getMessageDeleteIndex(opt_index) - self.telegram.sendTelegramAlert(self.utils.decryptAES(snap_tool_conf['telegram_chat_id']).decode('utf-8'), self.utils.decryptAES(snap_tool_conf['telegram_bot_token']).decode('utf-8'), message_delete_index) - self.d.msgbox("\nIndex removed: " + opt_index, 7, 50, title = "Notification Message") + list_all_indices = self.utils.convertListToCheckOrRadioList(list_aux_indices, "Index name") + opt_index = self.getDataRadioList("Select a option:", list_all_indices, "Indices") + list_aux_repositories = self.elastic.getAllRepositories(conn_es) + if len(list_aux_repositories) == 0: + self.d.msgbox(text = "\nThere are no repositories.", height = 7, width = 50, title = "Notification Message") + else: + snap_tool_conf = self.utils.readYamlFile(self.path_conf_file, 'r') + list_all_repositories = self.utils.convertListToCheckOrRadioList(list_aux_repositories, "Repository name") + opt_repo = self.getDataRadioList("Select a option:", list_all_repositories, "Repositories") + self.elastic.createSnapshot(conn_es, opt_repo, opt_index) + message_creation_start = self.telegram.getMessageStartCreationSnapshot(opt_index, opt_repo) + self.telegram.sendTelegramAlert(self.utils.decryptAES(snap_tool_conf['telegram_chat_id']).decode('utf-8'), self.utils.decryptAES(snap_tool_conf['telegram_bot_token']).decode('utf-8'), message_creation_start) + self.logger.createSnapToolLog("Snapshot creation has started: " + opt_index, 1) + while True: + status_snapshot = self.elastic.getStatusSnapshot(conn_es, opt_repo, opt_index) + if status_snapshot == "SUCCESS": + break + sleep(60) + snapshot_info = self.elastic.getSnapshotInfo(conn_es, opt_repo, opt_index) + self.logger.createSnapToolLog("Snapshot creation has finished: " + opt_index, 1) + message_creation_end = self.telegram.getMessageEndSnapshot(opt_index, opt_repo, snapshot_info['snapshots'][0]['start_time'], snapshot_info['snapshots'][0]['end_time']) + self.telegram.sendTelegramAlert(self.utils.decryptAES(snap_tool_conf['telegram_chat_id']).decode('utf-8'), self.utils.decryptAES(snap_tool_conf['telegram_bot_token']).decode('utf-8'), message_creation_end) + self.d.msgbox(text = "\nSnapshot created: " + opt_index, height = 7, width = 50, title = "Notification Message") + if snap_tool_conf['is_delete_index'] == True: + self.elastic.deleteIndex(conn_es, opt_index) + if not conn_es.indices.exists(opt_index): + self.logger.createSnapToolLog("Index removed: " + opt_index, 1) + message_delete_index = self.telegram.getMessageDeleteIndex(opt_index) + self.telegram.sendTelegramAlert(self.utils.decryptAES(snap_tool_conf['telegram_chat_id']).decode('utf-8'), self.utils.decryptAES(snap_tool_conf['telegram_bot_token']).decode('utf-8'), message_delete_index) + self.d.msgbox(text = "\nIndex removed: " + opt_index, height = 7, width = 50, title = "Notification Message") + else: + delete_index = self.getDataYesOrNo("\nDo you want to delete the index?\n\n- " + opt_index, "Delete Index") + if delete_index == "ok": + self.elastic.deleteIndex(conn_es, opt_index) + if not conn_es.indices.exists(opt_index): + self.logger.createSnapToolLog("Index removed: " + opt_index, 1) + message_delete_index = self.telegram.getMessageDeleteIndex(opt_index) + self.telegram.sendTelegramAlert(self.utils.decryptAES(snap_tool_conf['telegram_chat_id']).decode('utf-8'), self.utils.decryptAES(snap_tool_conf['telegram_bot_token']).decode('utf-8'), message_delete_index) + self.d.msgbox(text = "\nIndex removed: " + opt_index, height = 7, width = 50, title = "Notification Message") conn_es.transport.close() self.mainMenu() except KeyError as exception: - self.logger.createSnapToolLog(exception, 3) - self.d.msgbox("\nFailed to create snapshot. For more information, see the logs.", 8, 50, title = "Error Message") + self.logger.createSnapToolLog("Key Error: " + exception, 3) + self.d.msgbox(text = "\nFailed to create snapshot. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.mainMenu() """ @@ -514,20 +521,20 @@ def createSnapshot(self): def deleteSnapshot(self): try: if not path.exists(self.path_conf_file): - self.d.msgbox("\nConfiguration file not found.", 7, 50, title = "Error Message") + self.d.msgbox(text = "\nConfiguration file not found.", height = 7, width = 50, title = "Error Message") else: - snap_tool_conf = self.utils.readYamlFile(self.path_conf_file, 'r') conn_es = self.elastic.getConnectionElastic() list_aux_repositories = self.elastic.getAllRepositories(conn_es) if len(list_aux_repositories) == 0: - self.d.msgbox("\nThere are no repositories created.", 7, 50, title = "Notification Message") + self.d.msgbox(text = "\nThere are no repositories created.", height = 7, width = 50, title = "Notification Message") else: list_all_repositories = self.utils.convertListToCheckOrRadioList(list_aux_repositories, "Repository Name") opt_repo = self.getDataRadioList("Select a option:", list_all_repositories, "Repositories") list_aux_snapshots = self.elastic.getAllSnapshots(conn_es, opt_repo) if len(list_aux_snapshots) == 0: - self.d.msgbox("\nThere are no snapshots created.", 7, 50, title = "Notification Message") + self.d.msgbox(text = "\nThere are no snapshots created.", height = 7, width = 50, title = "Notification Message") else: + snap_tool_conf = self.utils.readYamlFile(self.path_conf_file, 'r') list_all_snapshots = self.utils.convertListToCheckOrRadioList(list_aux_snapshots, "Snapshot Name") opt_snapshots = self.getDataCheckList("Select one or more options:", list_all_snapshots, "Snapshots") delete_snapshot = self.getDataYesOrNo("\nAre you sure to delete the selected snapshot(s)?", "Delete Snapshot(s)") @@ -540,9 +547,10 @@ def deleteSnapshot(self): message += self.utils.convertListToString(opt_snapshots) self.getScrollBox(message, "Snapshot(s) deleted") conn_es.transport.close() + self.mainMenu() except KeyError as exception: - self.logger.createSnapToolLog(exception, 3) - self.d.msgbox("\nFailed to delete snapshot(s). For more information, see the logs.", 8, 50, title = "Error Message") + self.logger.createSnapToolLog("Key Error: " + exception, 3) + self.d.msgbox(text = "\nFailed to delete snapshot(s). For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.mainMenu() """ @@ -557,32 +565,32 @@ def deleteSnapshot(self): def restoreSnapshot(self): try: if not path.exists(self.path_conf_file): - self.d.msgbox("\nConfiguration file not found.", 7, 50, title = "Error Message") + self.d.msgbox(text = "\nConfiguration file not found.", height = 7, width = 50, title = "Error Message") else: - snap_tool_conf = self.utils.readYamlFile(self.path_conf_file, 'r') conn_es = self.elastic.getConnectionElastic() list_aux_repositories = self.elastic.getAllRepositories(conn_es) if len(list_aux_repositories) == 0: - self.d.msgbox("\nThere are no repositories created.", 7, 50, title = "Notification Message") + self.d.msgbox(text = "\nThere are no repositories created.", height = 7, width = 50, title = "Notification Message") else: list_all_repositories = self.utils.convertListToCheckOrRadioList(list_aux_repositories, "Repository Name") opt_repo = self.getDataRadioList("Select a option:", list_all_repositories, "Repositories") list_aux_snapshots = self.elastic.getAllSnapshots(conn_es, opt_repo) if len(list_aux_snapshots) == 0: - self.d.msgbox("\nThere are no snapshots created.", 7, 50, title = "Notification Message") + self.d.msgbox(text = "\nThere are no snapshots created.", height = 7, width = 50, title = "Notification Message") else: + snap_tool_conf = self.utils.readYamlFile(self.path_conf_file, 'r') list_all_snapshots = self.utils.convertListToCheckOrRadioList(list_aux_snapshots, "Snapshot Name") opt_snapshot = self.getDataRadioList("Select a option:", list_all_snapshots, "Snapshots") self.elastic.restoreSnapshot(conn_es, opt_repo, opt_snapshot) message_restore_snapshot = self.telegram.getMessageRestoreSnapshot(opt_repo, opt_snapshot) self.telegram.sendTelegramAlert(self.utils.decryptAES(snap_tool_conf['telegram_chat_id']).decode('utf-8'), self.utils.decryptAES(snap_tool_conf['telegram_bot_token']).decode('utf-8'), message_restore_snapshot) self.logger.createSnapToolLog("Snapshot restored: " + opt_snapshot, 1) - self.d.msgbox("\nSnapshot restored: " + opt_snapshot + '.', 7, 50, title = "Notification Message") + self.d.msgbox(text = "\nSnapshot restored: " + opt_snapshot + '.', height = 7, width = 50, title = "Notification Message") conn_es.transport.close() - self.mainMenu() + self.mainMenu() except KeyError as exception: - self.logger.createSnapToolLog(exception, 3) - self.d.msgbox("\nFailed to restore snapshot. For more information, see the logs.", 8, 50, title = "Error Message") + self.logger.createSnapToolLog("Key Error: " + exception, 3) + self.d.msgbox(text = "\nFailed to restore snapshot. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.mainMenu() """ @@ -597,32 +605,32 @@ def restoreSnapshot(self): def mountSearchableSnapshot(self): try: if not path.exists(self.path_conf_file): - self.d.msgbox("\nConfiguration file not found.", 7, 50, title = "Error Message") + self.d.msgbox(text = "\nConfiguration file not found.", height = 7, width = 50, title = "Error Message") else: - snap_tool_conf = self.utils.readYamlFile(self.path_conf_file, 'r') conn_es = self.elastic.getConnectionElastic() list_aux_repositories = self.elastic.getAllRepositories(conn_es) if len(list_aux_repositories) == 0: - self.d.msgbox("\nThere are no repositories created.", 7, 50, title = "Notification Message") + self.d.msgbox(text = "\nThere are no repositories created.", height = 7, width = 50, title = "Notification Message") else: list_all_repositories = self.utils.convertListToCheckOrRadioList(list_aux_repositories, "Repository Name") opt_repo = self.getDataRadioList("Select a option:", list_all_repositories, "Repositories") list_aux_snapshots = self.elastic.getAllSnapshots(conn_es, opt_repo) if len(list_aux_snapshots) == 0: - self.d.msgbox("\nThere are no snapshots created.", 7, 50, title = "Notification Message") + self.d.msgbox(text = "\nThere are no snapshots created.", height = 7, width = 50, title = "Notification Message") else: + snap_tool_conf = self.utils.readYamlFile(self.path_conf_file, 'r') list_all_snapshots = self.utils.convertListToCheckOrRadioList(list_aux_snapshots, "Snapshot Name") opt_snapshot = self.getDataRadioList("Select a option:", list_all_snapshots, "Snapshots") self.elastic.mountSearchableSnapshot(conn_es, opt_repo, opt_snapshot) message_searchable_snapshot = self.telegram.getMessageSearchableSnapshot(opt_repo, opt_snapshot) self.telegram.sendTelegramAlert(self.utils.decryptAES(snap_tool_conf['telegram_chat_id']).decode('utf-8'), self.utils.decryptAES(snap_tool_conf['telegram_bot_token']).decode('utf-8'), message_searchable_snapshot) self.logger.createSnapToolLog("Snapshot mounted as searchable snapshot: " + opt_snapshot, 1) - self.d.msgbox("\nSnapshot mounted as searchable snapshot: " + opt_snapshot + '.', 8, 50, title = "Notification Message") + self.d.msgbox(text = "\nSnapshot mounted as searchable snapshot: " + opt_snapshot + '.', height = 8, width = 50, title = "Notification Message") conn_es.transport.close() - self.mainMenu() + self.mainMenu() except KeyError as exception: - self.logger.createSnapToolLog(exception, 3) - self.d.msgbox("\nFailed to mount snapshot as a searchable snapshot. For more information, see the logs.", 8, 50, title = "Error Message") + self.logger.createSnapToolLog("Key Error: " + exception, 3) + self.d.msgbox(text = "\nFailed to mount snapshot as a searchable snapshot. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.mainMenu() """ @@ -637,7 +645,7 @@ def mountSearchableSnapshot(self): def deleteIndices(self): try: if not path.exists(self.path_conf_file): - self.d.msgbox("\nConfiguration file not found.", 7, 50, title = "Error Message") + self.d.msgbox(text = "\nConfiguration file not found.", height = 7, width = 50, title = "Error Message") else: conn_es = self.elastic.getConnectionElastic() list_aux_indices = self.elastic.getIndices(conn_es) @@ -661,7 +669,7 @@ def deleteIndices(self): self.mainMenu() except KeyError as exception: self.logger.createSnapToolLog("Key Error: " + exception, 3) - self.d.msgbox("\nFailed to delete indices. For more information, see the logs.", 8, 50, title = "Error Message") + self.d.msgbox(text = "\nFailed to delete indices. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.mainMenu() """ @@ -671,17 +679,17 @@ def deleteIndices(self): self -- An instantiated object of the FormDialog class. """ def showNodesDiskSpace(self): - message = "Occupied space in nodes:\n\n" + message_to_display = "Occupied space in nodes:\n\n" conn_es = self.elastic.getConnectionElastic() nodes_info = self.elastic.getNodesInformation(conn_es) for node in nodes_info: - message += "- " + nodes_info[node]['name'] + "\n" + message_to_display += "- " + nodes_info[node]['name'] + '\n' total_disk = nodes_info[node]['fs']['total']['total_in_bytes'] available_disk = nodes_info[node]['fs']['total']['available_in_bytes'] percentage = 100 - (available_disk * 100 / total_disk) - message += "Percent occupied on disk: " + str(round(percentage, 2)) + "%\n\n" + message_to_display += "Percent occupied on disk: " + str(round(percentage, 2)) + "%\n\n" conn_es.transport.close() - self.getScrollBox(message, "Node Information") + self.getScrollBox(message_to_display, "Node Information") self.mainMenu() """ @@ -719,34 +727,34 @@ def switchMmenu(self, option): exit(0) """ - Method that launches an action based on the option chosen in the Snapshots menu. + Method that launches an action based on the option chosen in the Repositories menu. Parameters: self -- An instantiated object of the FormDialog class. option -- Chosen option. """ - def switchSmenu(self, option): + def switchRmenu(self, option): if option == 1: - self.createSnapshot() + self.createRepository() elif option == 2: self.deleteSnapshot() - elif option == 3: - self.restoreSnapshot() - elif option == 4: - self.mountSearchableSnapshot() """ - Method that launches an action based on the option chosen in the Repositories menu. + Method that launches an action based on the option chosen in the Snapshots menu. Parameters: self -- An instantiated object of the FormDialog class. option -- Chosen option. """ - def switchRmenu(self, option): + def switchSmenu(self, option): if option == 1: - self.createRepository() + self.createSnapshot() elif option == 2: self.deleteSnapshot() + elif option == 3: + self.restoreSnapshot() + elif option == 4: + self.mountSearchableSnapshot() """ Method that launches an action based on the option chosen in the Indices menu. @@ -760,19 +768,22 @@ def switchImenu(self, option): self.deleteIndices() """ - Method that defines the menu of actions that can be performed in relation to snaphosts. + Method that defines the menu on the actions to be carried out in the main menu. Parameters: self -- An instantiated object of the FormDialog class. """ - def snapshotMenu(self): - options_sm = [("1", "Create Snapshot"), - ("2", "Delete Snapshot(s)"), - ("3", "Restore snapshot"), - ("4", "Mount searchable snapshot")] + def mainMenu(self): + options_mm = [("1", "Snap-Tool Configuration"), + ("2", "Repositories"), + ("3", "Snapshots"), + ("4", "Indices"), + ("5", "Nodes information"), + ("6", "About"), + ("7", "Exit")] - option_sm = self.getMenu("Select a option:", options_sm, "Snapshots Menu") - self.switchSmenu(int(option_sm)) + option_mm = self.getMenu("Select a option:", options_mm, "Main Menu") + self.switchMmenu(int(option_mm)) """ Method that defines the menu of actions that can be performed in relation to repositories. @@ -788,31 +799,28 @@ def repositoryMenu(self): self.switchRmenu(int(option_rm)) """ - Method that defines the menu of actions that can be performed in relation to indices. + Method that defines the menu of actions that can be performed in relation to snaphosts. Parameters: self -- An instantiated object of the FormDialog class. """ - def indicesMenu(self): - options_im = [("1", "Delete indices")] + def snapshotMenu(self): + options_sm = [("1", "Create Snapshot"), + ("2", "Delete Snapshot(s)"), + ("3", "Restore snapshot"), + ("4", "Mount searchable snapshot")] - option_im = self.getMenu("Select a option:", options_im, "Indices Menu") - self.switchImenu(int(option_im)) + option_sm = self.getMenu("Select a option:", options_sm, "Snapshots Menu") + self.switchSmenu(int(option_sm)) """ - Method that defines the menu on the actions to be carried out in the main menu. + Method that defines the menu of actions that can be performed in relation to indices. Parameters: self -- An instantiated object of the FormDialog class. """ - def mainMenu(self): - options_mm = [("1", "Snap-Tool Configuration"), - ("2", "Repositories"), - ("3", "Snapshots"), - ("4", "Indices"), - ("5", "Nodes information"), - ("6", "About"), - ("7", "Exit")] + def indicesMenu(self): + options_im = [("1", "Delete indices")] - option_mm = self.getMenu("Select a option:", options_mm, "Main Menu") - self.switchMmenu(int(option_mm)) \ No newline at end of file + option_im = self.getMenu("Select a option:", options_im, "Indices Menu") + self.switchImenu(int(option_im)) \ No newline at end of file diff --git a/Snap-Tool/modules/LoggerClass.py b/Snap-Tool/modules/LoggerClass.py index 9d22ac8..ecfba45 100644 --- a/Snap-Tool/modules/LoggerClass.py +++ b/Snap-Tool/modules/LoggerClass.py @@ -2,13 +2,11 @@ from logging import getLogger, INFO, Formatter, FileHandler """ -Class that manages everything related to the application's -records. +Class that manages everything related to the application's records. """ class Logger: """ - Method that writes the logs generated by the application - in a file. + Method that writes the logs generated by the application in a file. Parameters: self -- An instantiated object of the Logger class. diff --git a/Snap-Tool/modules/TelegramClass.py b/Snap-Tool/modules/TelegramClass.py index cd0078f..3cb5956 100644 --- a/Snap-Tool/modules/TelegramClass.py +++ b/Snap-Tool/modules/TelegramClass.py @@ -63,7 +63,7 @@ def sendTelegramAlert(self, telegram_chat_id, telegram_bot_token, message): header -- Header of the message. """ def getHeaderMessage(self): - header = u'\u26A0\uFE0F' + " " + 'Snap-Tool' + " " + u'\u26A0\uFE0F' + '\n\n' + u'\u23F0' + " Alert sent: " + strftime("%c") + "\n\n\n" + header = u'\u26A0\uFE0F' + " " + 'Snap-Tool' + " " + u'\u26A0\uFE0F' + "\n\n" + u'\u23F0' + " Alert sent: " + strftime("%c") + "\n\n\n" return header """ @@ -115,12 +115,12 @@ def getMessageDeleteRepository(self, repository_name): def getMessageDeleteSnapshot(self, snapshot_name): message = self.getHeaderMessage() message += u'\u2611\uFE0F' + " Action: Snaphot removed\n" - message += u'\u2611\uFE0F' + " Snapshot name: " + snapshot_name +"\n" + message += u'\u2611\uFE0F' + " Snapshot name: " + snapshot_name + '\n' message += u'\u2611\uFE0F' + " Index name: " + snapshot_name return message """ - Method that generates the message in Telegram when a snapshot is restored. + Method that generates the message in Telegram for when a snapshot is restored. Parameters: self -- An instantiated object of the Telegram class. @@ -133,12 +133,12 @@ def getMessageDeleteSnapshot(self, snapshot_name): def getMessageRestoreSnapshot(self, repository_name, snapshot_name): message = self.getHeaderMessage() message += u'\u2611\uFE0F' + " Action: Snapshot restore\n" - message += u'\u2611\uFE0F' + " Snapshot name: " + snapshot_name +"\n" + message += u'\u2611\uFE0F' + " Snapshot name: " + snapshot_name + '\n' message += u'\u2611\uFE0F' + " Repository name: " + repository_name return message """ - Method that generates the message in Telegram when a snapshot is mounted as a searchable snapshot. + Method that generates the message in Telegram for when a snapshot is mounted as a searchable snapshot. Parameters: self -- An instantiated object of the Telegram class. @@ -151,7 +151,7 @@ def getMessageRestoreSnapshot(self, repository_name, snapshot_name): def getMessageSearchableSnapshot(self, repository_name, snapshot_name): message = self.getHeaderMessage() message += u'\u2611\uFE0F' + " Action: Snapshot mounted as a searchable snapshot\n" - message += u'\u2611\uFE0F' + " Snapshot name: " + snapshot_name +"\n" + message += u'\u2611\uFE0F' + " Snapshot name: " + snapshot_name + '\n' message += u'\u2611\uFE0F' + " Repository name: " + repository_name return message @@ -169,8 +169,8 @@ def getMessageSearchableSnapshot(self, repository_name, snapshot_name): def getMessageStartCreationSnapshot(self, index_name, repository_name): message = self.getHeaderMessage() message += u'\u2611\uFE0F' + " Action: Snapshot creation has started\n" - message += u'\u2611\uFE0F' + " Snapshot name: " + index_name +"\n" - message += u'\u2611\uFE0F' + " Index name: " + index_name + "\n" + message += u'\u2611\uFE0F' + " Snapshot name: " + index_name + '\n' + message += u'\u2611\uFE0F' + " Index name: " + index_name + '\n' message += u'\u2611\uFE0F' + " Repository name: " + repository_name return message @@ -190,9 +190,9 @@ def getMessageStartCreationSnapshot(self, index_name, repository_name): def getMessageEndSnapshot(self, snapshot_name, repository_name, start_time, end_time): message = self.getHeaderMessage() message += u'\u2611\uFE0F' + " Action: Snapshot creation completed\n" - message += u'\u2611\uFE0F' + " Snapshot name: " + snapshot_name +"\n" - message += u'\u2611\uFE0F' + " Repository name: " + repository_name + "\n" - message += u'\u2611\uFE0F' + " Start time: " + str(start_time) + "\n" + message += u'\u2611\uFE0F' + " Snapshot name: " + snapshot_name + '\n' + message += u'\u2611\uFE0F' + " Repository name: " + repository_name + '\n' + message += u'\u2611\uFE0F' + " Start time: " + str(start_time) + '\n' message += u'\u2611\uFE0F' + " End time: " + str(end_time) return message diff --git a/Snap-Tool/modules/UtilsClass.py b/Snap-Tool/modules/UtilsClass.py index cee31b7..fe91a28 100644 --- a/Snap-Tool/modules/UtilsClass.py +++ b/Snap-Tool/modules/UtilsClass.py @@ -56,7 +56,7 @@ def createYamlFile(self, data, path_file_yaml, mode): safe_dump(data, file_yaml, default_flow_style = False) except IOError as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nError creating YAML file. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nError creating YAML file. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() """ @@ -79,7 +79,7 @@ def readYamlFile(self, path_file_yaml, mode): data_file_yaml = safe_load(file_yaml) except IOError as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nError opening or reading the YAML file. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nError opening or reading the YAML file. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() else: return data_file_yaml @@ -104,7 +104,7 @@ def getPathSnapTool(self, path_dir): path_final = path.join(path_main, path_dir) except (OSError, TypeError) as exception: self.logger.createLogSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nAn error has occurred. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nAn error has occurred. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() else: return path_final @@ -128,7 +128,7 @@ def getPassphrase(self): file_key.close() except FileNotFoundError as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nError opening or reading the Key file. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nError opening or reading the Key file. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() else: return pass_key @@ -203,7 +203,7 @@ def getHashToFile(self, path_file): hash_sha.update(block) except IOError as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nError getting the file's hash function. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nError getting the file's hash function. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() else: return hash_sha.hexdigest() @@ -219,7 +219,7 @@ def getHashToFile(self, path_file): Encrypted text. Exceptions: - binascii.Error -- Is raised if were incorrectly padded or if there are non-alphabet characters present in the string. + Exception -- It is thrown when any exception is found. """ def encryptAES(self, text): try: @@ -229,7 +229,7 @@ def encryptAES(self, text): aes = AES.new(key, AES.MODE_CBC, IV) except Exception as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nFailed to encrypt the data. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nFailed to encrypt the data. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() else: return b64encode(IV + aes.encrypt(pad(text_bytes, AES.block_size))) @@ -255,7 +255,7 @@ def decryptAES(self, text_encrypt): aes = AES.new(key, AES.MODE_CBC, IV) except binascii.Error as exception: self.logger.createSnapToolLog(exception, 3) - self.form_dialog.d.msgbox("\nFailed to decrypt the data. For more information, see the logs.", 8, 50, title = "Error Message") + self.form_dialog.d.msgbox(text = "\nFailed to decrypt the data. For more information, see the logs.", height = 8, width = 50, title = "Error Message") self.form_dialog.mainMenu() else: return unpad(aes.decrypt(text_encrypt[AES.block_size:]), AES.block_size) \ No newline at end of file diff --git a/Snap-Tool/modules/__pycache__/ConfigurationClass.cpython-36.pyc b/Snap-Tool/modules/__pycache__/ConfigurationClass.cpython-36.pyc index 2ccdbbb..f1c0d90 100644 Binary files a/Snap-Tool/modules/__pycache__/ConfigurationClass.cpython-36.pyc and b/Snap-Tool/modules/__pycache__/ConfigurationClass.cpython-36.pyc differ diff --git a/Snap-Tool/modules/__pycache__/ElasticClass.cpython-36.pyc b/Snap-Tool/modules/__pycache__/ElasticClass.cpython-36.pyc index c6362ca..8270de8 100644 Binary files a/Snap-Tool/modules/__pycache__/ElasticClass.cpython-36.pyc and b/Snap-Tool/modules/__pycache__/ElasticClass.cpython-36.pyc differ diff --git a/Snap-Tool/modules/__pycache__/FormClass.cpython-36.pyc b/Snap-Tool/modules/__pycache__/FormClass.cpython-36.pyc index a14ba49..5301581 100644 Binary files a/Snap-Tool/modules/__pycache__/FormClass.cpython-36.pyc and b/Snap-Tool/modules/__pycache__/FormClass.cpython-36.pyc differ diff --git a/Snap-Tool/modules/__pycache__/LoggerClass.cpython-36.pyc b/Snap-Tool/modules/__pycache__/LoggerClass.cpython-36.pyc index 12bc3cf..cc90fc8 100644 Binary files a/Snap-Tool/modules/__pycache__/LoggerClass.cpython-36.pyc and b/Snap-Tool/modules/__pycache__/LoggerClass.cpython-36.pyc differ diff --git a/Snap-Tool/modules/__pycache__/TelegramClass.cpython-36.pyc b/Snap-Tool/modules/__pycache__/TelegramClass.cpython-36.pyc index 9d77980..f8903bf 100644 Binary files a/Snap-Tool/modules/__pycache__/TelegramClass.cpython-36.pyc and b/Snap-Tool/modules/__pycache__/TelegramClass.cpython-36.pyc differ diff --git a/Snap-Tool/modules/__pycache__/UtilsClass.cpython-36.pyc b/Snap-Tool/modules/__pycache__/UtilsClass.cpython-36.pyc index 76c1108..ca8bdb6 100644 Binary files a/Snap-Tool/modules/__pycache__/UtilsClass.cpython-36.pyc and b/Snap-Tool/modules/__pycache__/UtilsClass.cpython-36.pyc differ