def restore_connection(self, ConnectionListWidget, url, id, key): logger.info("[Users and Roles]Restoring Role(s)") if ConnectionListWidget.updated == True: filter = "JSON (*.json)" filelist, status = QtWidgets.QFileDialog.getOpenFileNames(self, "Open file(s)...", os.getcwd(), filter) if len(filelist) > 0: sumo = SumoLogic(id, key, endpoint=url, log_level=self.mainwindow.log_level) for file in filelist: try: with open(file) as filepointer: connection_backup = json.load(filepointer) except Exception as e: logger.exception(e) self.mainwindow.errorbox( "Something went wrong reading the file. Do you have the right file permissions? Does it contain valid JSON?") return try: status = sumo.create_connection(connection_backup) except Exception as e: logger.exception(e) self.mainwindow.errorbox('Something went wrong:\n\n' + str(e)) return self.update_connection_list(ConnectionListWidget, url, id, key) else: self.mainwindow.errorbox("Please select at least one file to restore.") return else: self.mainwindow.errorbox("Please update the directory list before restoring content") return
def copy_connection(self, ConnectionListWidgetFrom, ConnectionListWidgetTo, fromurl, fromid, fromkey, tourl, toid, tokey): logger.info("[Monitors and Connections]Copying Connection(s)") try: selecteditems = ConnectionListWidgetFrom.selectedItems() if len(selecteditems) > 0: # make sure something was selected fromsumo = SumoLogic(fromid, fromkey, endpoint=fromurl, log_level=self.mainwindow.log_level) tosumo = SumoLogic(toid, tokey, endpoint=tourl, log_level=self.mainwindow.log_level) for selecteditem in selecteditems: for object in ConnectionListWidgetFrom.currentcontent: if object['name'] == str(selecteditem.text()): connection_id = object['id'] connection_type = object['type'] connection = fromsumo.get_connection(connection_id, connection_type) connection['type'] = str(connection['type']).replace('Connection', 'Definition') status = tosumo.create_connection(connection) self.update_connection_list(ConnectionListWidgetTo, tourl, toid, tokey) return else: self.mainwindow.errorbox('You have not made any selections.') return except Exception as e: logger.exception(e) self.mainwindow.errorbox('Something went wrong:' + str(e)) self.update_connection_list(ConnectionListWidgetTo, tourl, toid, tokey) return