def view_source_JSON(self, CollectorListWidget, SourceListWidget, url, id,
                         key):
        logger.info("[Collectors] Viewing Source JSON")
        sourcenames = SourceListWidget.selectedItems()
        if len(sourcenames) > 0:  # make sure at least one source is selected
            try:
                sumo = SumoLogic(id,
                                 key,
                                 endpoint=url,
                                 log_level=self.mainwindow.log_level)
                json_text = ''
                collectornamesqstring = CollectorListWidget.selectedItems(
                )  # get collectors sources have been selected
                collectorname = str(collectornamesqstring[0].text())
                collector = sumo.get_collector_by_name_alternate(collectorname)
                sources = sumo.get_sources_sync(collector['id'])
                for sourcename in sourcenames:
                    for source in sources:
                        if ('name' in source
                                and str(sourcename.text()) == source['name']
                            ) or ('config' in source and str(sourcename.text())
                                  == source['config']['name']):
                            json_text = json_text + json.dumps(
                                source, indent=4, sort_keys=True) + '\n\n'
                self.json_window = ShowTextDialog('JSON', json_text,
                                                  self.mainwindow.basedir)
                self.json_window.show()

            except Exception as e:
                logger.exception(e)
                self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))

        else:
            self.mainwindow.errorbox('No Source Selected.')
예제 #2
0
    def view_json(self, FERListWidget, url, id, key):
        logger.info("[Field Extraction Rules]Viewing FER(s) as JSON")
        selecteditems = FERListWidget.selectedItems()
        if len(selecteditems) > 0:  # make sure something was selected
            try:
                sumo = SumoLogic(id,
                                 key,
                                 endpoint=url,
                                 log_level=self.mainwindow.log_level)
                json_text = ''
                for selecteditem in selecteditems:
                    for object in FERListWidget.currentcontent:
                        if object['name'] == str(selecteditem.text()):
                            item_id = object['id']
                            fer = sumo.get_fer(item_id)
                            json_text = json_text + json.dumps(
                                fer, indent=4, sort_keys=True) + '\n\n'
                self.json_window = ShowTextDialog('JSON', json_text,
                                                  self.mainwindow.basedir)
                self.json_window.show()

            except Exception as e:
                logger.exception(e)
                self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))
                return

        else:
            self.mainwindow.errorbox('No FER selected.')
        return
 def update_source_list(self, CollectorListWidget, SourceListWidget, url,
                        id, key):
     logger.info("[Collectors] Updating Source List")
     SourceListWidget.clear(
     )  # clear the list first since it might already be populated
     collectors = CollectorListWidget.selectedItems()
     if (len(collectors) > 1) or (len(collectors) < 1):
         return
     else:
         collector = self.getcollectorid(collectors[0].text(), url, id, key)
         sumo = SumoLogic(id,
                          key,
                          endpoint=url,
                          log_level=self.mainwindow.log_level)
         # populate the list of sources
         sources = sumo.sources(collector)
         for source in sources:
             if 'name' in source:
                 SourceListWidget.addItem(
                     source['name'])  # populate the display with sources
             elif 'config' in source:
                 SourceListWidget.addItem(
                     source['config']
                     ['name'])  # populate the display with sources
     return
    def create_folder(self, MonitorListWidget, url, id, key, directorylabel):
        if MonitorListWidget.updated == True:

            message = '''
        Please enter the name of the folder you wish to create:

                        '''
            text, result = QtWidgets.QInputDialog.getText(self, 'Create Folder...', message)
            if result:
                for item in MonitorListWidget.currentcontent['children']:
                    if item['name'] == str(text):
                        self.mainwindow.errorbox('That Directory Name Already Exists!')
                        return
                try:

                    logger.info("[Monitors and Connections]Creating New Monitor Folder")
                    sumo = SumoLogic(id, key, endpoint=url, log_level=self.mainwindow.log_level)
                    parent_id = MonitorListWidget.currentcontent['id']
                    error = sumo.create_monitor_folder(parent_id, text)
                    self.update_monitors_list(MonitorListWidget, url, id, key, directorylabel)
                    return

                except Exception as e:
                    logger.exception(e)
                    self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))

        else:
            self.mainwindow.errorbox("Please update the directory list before trying to create a new folder.")
        return
 def view_collector_JSON(self, CollectorListWidget, url, id, key):
     logger.info("[Collectors] Viewing Collector JSON")
     collectornamesqstring = CollectorListWidget.selectedItems(
     )  # get collectors sources have been selected
     if len(collectornamesqstring) > 0:  # make sure something was selected
         try:
             sumo = SumoLogic(id,
                              key,
                              endpoint=url,
                              log_level=self.mainwindow.log_level)
             json_text = ''
             for collectornameqstring in collectornamesqstring:
                 collector = sumo.get_collector_by_name_alternate(
                     str(collectornameqstring.text()))
                 # sources = sumo.get_sources_sync(collector['id'])
                 json_text = json_text + json.dumps(
                     collector, indent=4, sort_keys=True) + '\n\n'
                 # json_text = json_text + json.dumps(sources, indent=4, sort_keys=True) + '\n\n'
             self.json_window = ShowTextDialog('JSON', json_text,
                                               self.mainwindow.basedir)
             self.json_window.show()
         except Exception as e:
             logger.exception(e)
             self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))
     else:
         self.mainwindow.errorbox('No Collector Selected.')
     return
    def update_monitors_list(self, MonitorsListWidget, url, id, key, directorylabel):
        sumo = SumoLogic(id, key, endpoint=url, log_level=self.mainwindow.log_level)
        logger.info("[Monitors and Connections]Updating Monitors List")
        if MonitorsListWidget.currentdirlist:
            currentdir = MonitorsListWidget.currentdirlist[-1]
        else:
            currentdir = {'name': None, 'id': 'TOP'}
        try:
            if (not MonitorsListWidget.currentcontent) or (currentdir['id'] == 'TOP'):
                MonitorsListWidget.currentdirlist = []
                dir = {'name': '/', 'id': 'TOP'}
                MonitorsListWidget.currentdirlist.append(dir)
                MonitorsListWidget.currentcontent = sumo.get_monitor_folder_root()
                self.updatemonitorlistwidget(MonitorsListWidget, directorylabel)
                return
            else:
                MonitorsListWidget.currentcontent = sumo.get_monitor(currentdir['id'])
                self.updatemonitorlistwidget(MonitorsListWidget, directorylabel)
                return

        except Exception as e:
            MonitorsListWidget.updated = False
            logger.exception(e)
            self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))
            return
예제 #7
0
    def view_role_json(self, RoleListWidget, url, id, key):
        logger.info("[Users and Roles]Viewing Roles(s) JSON")
        selecteditems = RoleListWidget.selectedItems()
        if len(selecteditems) > 0:  # make sure something was selected
            try:
                sumo = SumoLogic(id,
                                 key,
                                 endpoint=url,
                                 log_level=self.mainwindow.log_level)
                json_text = ''
                for selecteditem in selecteditems:
                    role_id = selecteditem.details['id']
                    role = sumo.get_role(role_id)
                    json_text = json_text + json.dumps(
                        role, indent=4, sort_keys=True) + '\n\n'
                self.json_window = ShowTextDialog('JSON', json_text,
                                                  self.mainwindow.basedir)
                self.json_window.show()

            except Exception as e:
                logger.exception(e)
                self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))
                return
        else:
            self.mainwindow.errorbox('No role selected.')
        return
예제 #8
0
    def deletecollectors(self, CollectorListWidget, url, id, key):
        logger.info("Deleting Collectors")
        collectornamesqstring = CollectorListWidget.selectedItems()
        if len(collectornamesqstring) > 0:  # make sure something was selected
            message = "You are about to delete the following collector(s):\n\n"
            for collectornameqstring in collectornamesqstring:
                message = message + str(collectornameqstring.text()) + "\n"
            message = message + '''
This is exceedingly DANGEROUS!!!! 
Please be VERY, VERY, VERY sure you want to do this!
Even if you have backed up your collectors to file you CANNOT
restore installed collectors using this tool or the Sumo Logic API.

If you are absolutely sure, type "DELETE" in the box below.

            '''
            text, result = QtWidgets.QInputDialog.getText(
                self, 'Warning!!', message)
            if (result and (str(text) == 'DELETE')):
                sumo = SumoLogic(id, key, endpoint=url)
                for collectornameqstring in collectornamesqstring:
                    try:
                        collectorid = self.getcollectorid(
                            str(collectornameqstring.text()), url, id, key)
                        sumo.delete_collector(collectorid)
                    except Exception as e:
                        self.mainwindow.errorbox(
                            'Failed to delete collector: ' +
                            str(collectornamesqstring.text()))
                        logger.exception(e)
                self.updatecollectorlist(CollectorListWidget, url, id, key)

        else:
            self.mainwindow.errorbox('No Collector Selected')
        return
예제 #9
0
    def backup_partition(self, PartitionListWidget, url, id, key):
        logger.info("[Partitions]Backing Up Partition(s)")
        selecteditems = PartitionListWidget.selectedItems()
        if len(selecteditems) > 0:  # make sure something was selected
            savepath = str(QtWidgets.QFileDialog.getExistingDirectory(self, "Select Backup Directory"))
            if os.access(savepath, os.W_OK):
                message = ''
                sumo = SumoLogic(id, key, endpoint=url, log_level=self.mainwindow.log_level)
                for selecteditem in selecteditems:
                    for object in PartitionListWidget.currentcontent:
                        if object['name'] == str(selecteditem.text()):
                            item_id = object['id']
                            try:
                                export = sumo.get_partition(item_id)

                                savefilepath = pathlib.Path(savepath + r'/' + str(selecteditem.text()) + r'.partition.json')
                                if savefilepath:
                                    with savefilepath.open(mode='w') as filepointer:
                                        json.dump(export, filepointer)
                                    message = message + str(selecteditem.text()) + r'.json' + '\n'
                            except Exception as e:
                                logger.exception(e)
                                self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))
                                return
                self.mainwindow.errorbox('Wrote files: \n\n' + message)
            else:
                self.mainwindow.errorbox("You don't have permissions to write to that directory")

        else:
            self.mainwindow.errorbox('No partition selected.')
        return
예제 #10
0
    def restore_scheduled_view(self, SVListWidget, url, id, key):
        logger.info("Restoring SV(s)")
        if SVListWidget.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)
                for file in filelist:
                    try:
                        with open(file) as filepointer:
                            sv_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:
                        local_time = datetime.now(timezone.utc).astimezone()
                        status = sumo.create_scheduled_view(sv_backup['indexName'], sv_backup['query'], local_time.isoformat())

                    except Exception as e:
                        logger.exception(e)
                        self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))
                        return
                self.update_SV_list(SVListWidget, 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
예제 #11
0
    def parentdircontentlist(self, ContentListWidget, url, id, key,
                             radioselected, directorylabel):
        if ContentListWidget.updated:
            logger.info("Going Up One Content Folder")
            sumo = SumoLogic(id, key, endpoint=url)
            currentdir = ContentListWidget.currentdirlist[-1]
            if currentdir['id'] != 'TOP':
                parentdir = ContentListWidget.currentdirlist[-2]
            else:
                return
            try:

                if parentdir['id'] == 'TOP':
                    ContentListWidget.currentdirlist = []
                    self.updatecontentlist(ContentListWidget, url, id, key,
                                           radioselected, directorylabel)
                    return

                else:
                    ContentListWidget.currentdirlist.pop()
                    ContentListWidget.currentcontent = sumo.get_folder(
                        parentdir['id'])

                    self.updatecontentlist(ContentListWidget, url, id, key,
                                           radioselected, directorylabel)
                    return
            except Exception as e:
                logger.exception(e)
                self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))

            return
    def parentdirmonitorlist(self, MonitorListWidget, url, id, key, directorylabel):
        if MonitorListWidget.updated:
            logger.info("[Monitors and Connections] Going Up One Monitor Folder")
            sumo = SumoLogic(id, key, endpoint=url, log_level=self.mainwindow.log_level)
            currentdir = MonitorListWidget.currentdirlist[-1]
            if currentdir['id'] != 'TOP':
                parentdir = MonitorListWidget.currentdirlist[-2]
            else:
                return
            try:

                if parentdir['id'] == 'TOP':
                    MonitorListWidget.currentdirlist = []
                    self.update_monitors_list(MonitorListWidget, url, id, key, directorylabel)
                    return

                else:
                    MonitorListWidget.currentdirlist.pop()
                    MonitorListWidget.currentcontent = sumo.get_monitor(parentdir['id'])
                    self.update_monitors_list(MonitorListWidget, url, id, key, directorylabel)
                    return
                
            except Exception as e:
                logger.exception(e)
                self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))

            return
    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 restoresources(self, CollectorListWidget, SourceListWidget, url, id,
                       key):
        destinationcollectors = CollectorListWidget.selectedItems()
        if len(destinationcollectors) == 1:
            destinationcollectorqstring = destinationcollectors[0].text()
            destinationcollector = str(destinationcollectorqstring)
            destinationcollectorid = self.getcollectorid(
                destinationcollector, url, id, key)
            filter = "JSON (*.json)"
            restorefile, status = QtWidgets.QFileDialog.getOpenFileName(
                self, "Open file(s)...", os.getcwd(), filter)
            sources = None
            try:
                with open(restorefile) as data_file:
                    sources = json.load(data_file)
            except Exception as e:
                self.mainwindow.errorbox('Failed to load JSON file.')
                logger.exception(e)

            # a sources save file from the UI looks a little different than a save file from this tool, fix it here
            if sources:
                if 'sources' in sources:
                    sources = sources['sources']
                dialog = restoreSourcesDialog(sources)
                dialog.exec()
                dialog.show()
                if str(dialog.result()) == '1':
                    selectedsources = dialog.getresults()
                else:
                    return
                if len(selectedsources) > 0:
                    sumo = SumoLogic(id,
                                     key,
                                     endpoint=url,
                                     log_level=self.mainwindow.log_level)
                    for selectedsource in selectedsources:
                        for sumosource in sources:
                            if ('name' in sumosource and sumosource['name']
                                    == str(selectedsource)) or (
                                        'config' in sumosource
                                        and sumosource['config']['name']
                                        == str(selectedsource)):
                                if 'id' in sumosource:
                                    del sumosource['id']
                                if 'alive' in sumosource:
                                    del sumosource['alive']
                                template = {}
                                template['source'] = sumosource
                                sumo.create_source(destinationcollectorid,
                                                   template)
                    self.update_source_list(CollectorListWidget,
                                            SourceListWidget, url, id, key)
                else:
                    self.mainwindow.errorbox('No sources selected for import.')
        else:
            self.mainwindow.errorbox(
                'Please select 1 and only 1 collector to restore sources to.')
        return
예제 #15
0
    def getcollectorid(self, collectorname, url, id, key):
        logger.info("Getting Collector IDs")
        sumo = SumoLogic(id, key, endpoint=url)
        try:
            sumocollectors = sumo.get_collectors_sync()

            for sumocollector in sumocollectors:
                if sumocollector['name'] == collectorname:
                    return sumocollector['id']
        except Exception as e:
            logger.exception(e)
        return
예제 #16
0
 def update_SV_list(self, SVListWidget, url, id, key):
     sumo = SumoLogic(id, key, endpoint=url)
     try:
         logger.info("Updating SV List")
         SVListWidget.currentcontent = sumo.get_scheduled_views_sync()
         SVListWidget.clear()
         if len(SVListWidget.currentcontent) > 0:
             self.update_SV_listwidget(SVListWidget)
             return
     except Exception as e:
         logger.exception(e)
         self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))
         return
예제 #17
0
 def update_partition_list(self, PartitionListWidget, url, id, key):
     sumo = SumoLogic(id, key, endpoint=url, log_level=self.mainwindow.log_level)
     try:
         logger.info("[Partitions] Updating Partition List")
         PartitionListWidget.currentcontent = sumo.get_partitions_sync()
         PartitionListWidget.clear()
         if len(PartitionListWidget.currentcontent) > 0:
             self.update_partition_listwidget(PartitionListWidget)
             return
     except Exception as e:
         logger.exception(e)
         self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))
         return
예제 #18
0
    def getsourceid(self, collectorid, sourcename, url, id, key):
        logger.info("Getting Source IDs")
        sumo = SumoLogic(id, key, endpoint=url)
        try:
            sumosources = sumo.sources(collectorid)

            for sumosource in sumosources:
                if sumosource['name'] == sourcename:
                    return sumosource['id']
            return False
        except Exception as e:
            logger.exception(e)
        return
예제 #19
0
    def copy_saml(self, SAMLListWidgetFrom, SAMLListWidgetTo, fromurl, fromid,
                  fromkey, tourl, toid, tokey):

        logger.info("[SAML]Copying SAML config(s)")
        try:
            selecteditems = SAMLListWidgetFrom.selectedItems()
            if len(selecteditems) > 0:  # make sure something was selected
                message = "You are about to copy the following item(s):\n\n"
                for selecteditem in selecteditems:
                    message = message + str(selecteditem.text()) + "\n"
                message = message + '''
                    This is exceedingly DANGEROUS!!!! 
                    Please be VERY, VERY, VERY sure you want to do this!
                    You could cross the streams if you copy the wrong thing(s).

                    If you are absolutely sure, type "COPY" in the box below.

                                        '''
                text, result = QtWidgets.QInputDialog.getText(
                    self, 'Warning!!', message)
                if (result and (str(text) == 'COPY')):
                    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 SAMLListWidgetFrom.currentcontent:
                            if object['configurationName'] == str(
                                    selecteditem.text()):
                                item_id = object['id']
                                saml_export = fromsumo.get_saml_config_by_id(
                                    item_id)
                                import_saml_config(saml_export, tosumo)
                                break
                    self.update_SAML_list(SAMLListWidgetTo, 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_SAML_list(SAMLListWidgetTo, tourl, toid, tokey)
        return
예제 #20
0
    def delete_content(self, ContentListWidget, url, id, key, radioselected,
                       directorylabel):
        logger.info("Deleting Content")
        if radioselected == -3 or radioselected == -4:  # Admin or Global folders selected
            adminmode = True
        else:
            adminmode = False

        selecteditems = ContentListWidget.selectedItems()
        if len(selecteditems) > 0:  # make sure something was selected
            message = "You are about to delete the following item(s):\n\n"
            for selecteditem in selecteditems:
                message = message + str(selecteditem.text()) + "\n"
            message = message + '''
This is exceedingly DANGEROUS!!!! 
Please be VERY, VERY, VERY sure you want to do this!
You could lose quite a bit of work if you delete the wrong thing(s).

If you are absolutely sure, type "DELETE" in the box below.

                    '''
            text, result = QtWidgets.QInputDialog.getText(
                self, 'Warning!!', message)
            if (result and (str(text) == 'DELETE')):
                try:
                    sumo = SumoLogic(id, key, endpoint=url)
                    for selecteditem in selecteditems:

                        for child in ContentListWidget.currentcontent[
                                'children']:
                            if child['name'] == str(selecteditem.text()):
                                item_id = child['id']

                        result = sumo.delete_content_job_sync(
                            item_id, adminmode=adminmode)

                    self.updatecontentlist(ContentListWidget, url, id, key,
                                           radioselected, directorylabel)
                    return

                except Exception as e:
                    logger.exception(e)
                    self.mainwindow.errorbox('Something went wrong:\n\n' +
                                             str(e))

        else:
            self.mainwindow.errorbox(
                'You need to select something before you can delete it.')
        return
예제 #21
0
    def getcollectorid(self, collectorname, url, id, key):
        logger.info("[Source Update] Getting Collector IDs")
        sumo = SumoLogic(id,
                         key,
                         endpoint=url,
                         log_level=self.mainwindow.log_level)
        try:
            sumocollectors = sumo.get_collectors_sync()

            for sumocollector in sumocollectors:
                if sumocollector['name'] == collectorname:
                    return sumocollector['id']
        except Exception as e:
            logger.exception(e)
        return
    def backup_monitor(self, MonitorListWidget, url, id, key):
        logger.info("[Monitors and Connections]Backing Up Monitors(s)")
        selecteditems = MonitorListWidget.selectedItems()
        if len(selecteditems) > 0:  # make sure something was selected
            savepath = str(QtWidgets.QFileDialog.getExistingDirectory(self, "Select Backup Directory"))
            if os.access(savepath, os.W_OK):
                message = ''
                sumo = SumoLogic(id, key, endpoint=url, log_level=self.mainwindow.log_level)
                for selecteditem in selecteditems:
                    for object in MonitorListWidget.currentcontent['children']:
                        if object['name'] == str(selecteditem.text()):
                            item_id = object['id']
                            try:
                                export = export_monitor_and_connections(item_id, sumo)
                                for index, connection in enumerate(export['connections']):
                                    export['connections'][index]['type'] = str(connection['type']).replace('Connection', 'Definition')

                                savefilepath = pathlib.Path(savepath + r'/' + str(selecteditem.text()) + r'.monitor.json')
                                if savefilepath:
                                    with savefilepath.open(mode='w') as filepointer:
                                        json.dump(export, filepointer)
                                    message = message + str(selecteditem.text()) + r'.monitor.json' + '\n'
                            except Exception as e:
                                logger.exception(e)
                                self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))
                                return
                self.mainwindow.infobox('Wrote files: \n\n' + message)
            else:
                self.mainwindow.errorbox("You don't have permissions to write to that directory")

        else:
            self.mainwindow.errorbox('No monitor selected.')
        return
예제 #23
0
 def update_SAML_list(self, SAMLListWidget, url, id, key):
     sumo = SumoLogic(id,
                      key,
                      endpoint=url,
                      log_level=self.mainwindow.log_level)
     try:
         logger.info("[SAML]Updating SAML config List")
         SAMLListWidget.currentcontent = sumo.get_saml_configs()
         SAMLListWidget.clear()
         self.update_SAML_listwidget(SAMLListWidget)
         return
     except Exception as e:
         logger.exception(e)
         SAMLListWidget.updated = False
         self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))
         return
예제 #24
0
 def update_users_and_roles_lists(self, UserListWidget, RoleListWidget, url,
                                  id, key):
     sumo = SumoLogic(id, key, endpoint=url)
     try:
         logger.info("Updating Users and Roles Lists")
         UserListWidget.currentcontent = sumo.get_users_sync()
         RoleListWidget.currentcontent = sumo.get_roles_sync()
         self.update_users_and_roles_listwidgets(UserListWidget,
                                                 RoleListWidget)
         return
     except Exception as e:
         UserListWidget.updated = False
         RoleListWidget.updated = False
         logger.exception(e)
         self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))
         return
    def doubleclickedmonitorlist(self, item, MonitorListWidget, url, id, key, directorylabel):
        logger.info("[Monitors and Connections] Going Down One Monitor Folder")
        sumo = SumoLogic(id, key, endpoint=url, log_level=self.mainwindow.log_level)
        try:
            for child in MonitorListWidget.currentcontent['children']:
                if (child['name'] == item.text()) and (child['contentType'] == 'Folder'):
                    MonitorListWidget.currentcontent = sumo.get_monitor(child['id'])
                    dir = {'name': item.text(), 'id': child['id']}
                    MonitorListWidget.currentdirlist.append(dir)
                    self.update_monitors_list(MonitorListWidget, url, id, key, directorylabel)
                    break

        except Exception as e:
            logger.exception(e)
            self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))
            return
예제 #26
0
    def restorecontent(self, ContentListWidget, url, id, key, radioselected,
                       directorylabel):
        logger.info("Restoring Content")
        if ContentListWidget.updated == True:
            if 'id' in ContentListWidget.currentcontent:  # make sure the current folder has a folder id
                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)
                    for file in filelist:
                        try:
                            with open(file) as filepointer:
                                content = 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:
                            folder_id = ContentListWidget.currentcontent['id']
                            if radioselected == -4 or radioselected == -3:  # Admin Recommended Folders or Global folders Selected
                                adminmode = True
                            else:
                                adminmode = False
                            sumo.import_content_job_sync(folder_id,
                                                         content,
                                                         adminmode=adminmode)
                        except Exception as e:
                            logger.exception(e)
                            self.mainwindow.errorbox(
                                'Something went wrong:\n\n' + str(e))
                            return
                    self.updatecontentlist(ContentListWidget, url, id, key,
                                           radioselected, directorylabel)

            else:
                self.mainwindow.errorbox(
                    "You can't restore content to this folder. Does it belong to another user?"
                )
                return
        else:
            self.mainwindow.errorbox(
                "Please update the directory list before restoring content")
        return
예제 #27
0
    def update_FER_list(self, FERListWidget, url, id, key):
        sumo = SumoLogic(id,
                         key,
                         endpoint=url,
                         log_level=self.mainwindow.log_level)
        try:
            logger.info("[Field Extraction Rules]Updating FER List")
            FERListWidget.currentcontent = sumo.get_fers_sync()
            FERListWidget.clear()
            if len(FERListWidget.currentcontent) > 0:
                self.update_FER_listwidget(FERListWidget)
                return

        except Exception as e:
            logger.exception(e)
            self.mainwindow.errorbox('Something went wrong:\n\n' + str(e))
            return
    def deletesources(self, CollectorListWidget, SourceListWidget, url, id,
                      key):
        logger.info("[Collectors] Deleting Sources")
        collectornamesqstring = CollectorListWidget.selectedItems()
        if len(collectornamesqstring) == 1:  # make sure something was selected
            collectorid = self.getcollectorid(
                str(collectornamesqstring[0].text()), url, id, key)
            sourcenamesqstring = SourceListWidget.selectedItems()
            if len(sourcenamesqstring) > 0:  # make sure something was selected
                message = "You are about to delete the following source(s):\n\n"
                for sourcenameqstring in sourcenamesqstring:
                    message = message + str(sourcenameqstring.text()) + "\n"
                message = message + '''
This could be exceedingly DANGEROUS!!!! 
Please be VERY, VERY, VERY sure you want to do this!

If you are absolutely sure, type "DELETE" in the box below.

                        '''
                text, result = QtWidgets.QInputDialog.getText(
                    self, 'Warning!!', message)
                if (result and (str(text) == 'DELETE')):
                    sumo = SumoLogic(id,
                                     key,
                                     endpoint=url,
                                     log_level=self.mainwindow.log_level)
                    for sourcenameqstring in sourcenamesqstring:
                        try:
                            sourceid = self.getsourceid(
                                collectorid, str(sourcenameqstring.text()),
                                url, id, key)
                            sumo.delete_source(collectorid, sourceid)
                        except Exception as e:
                            self.mainwindow.errorbox(
                                'Failed to delete source: ' +
                                str(sourcenameqstring.text()))
                            logger.exception(e)
                    self.update_source_list(CollectorListWidget,
                                            SourceListWidget, url, id, key)

            else:
                self.mainwindow.errorbox('No Source(s) Selected')
        else:
            self.mainwindow.errorbox('You must select 1 and only 1 collector.')
        return
예제 #29
0
    def updatecontentlistwidget(self, ContentListWidget, url, id, key,
                                radioselected, directorylabel):
        try:
            ContentListWidget.clear()
            sumo = SumoLogic(id, key, endpoint=url)
            for object in ContentListWidget.currentcontent['children']:
                item_name = ''
                # if radioselected == -3:
                #     logger.info("Getting User info for Global Folder")
                #     user_info = sumo.get_user(object['createdBy'])
                #     item_name = '[' + user_info['firstName'] + ' ' + user_info['lastName'] + ']'
                item_name = item_name + object['name']
                if object['itemType'] == 'Folder':
                    item = QtWidgets.QListWidgetItem(self.icons['Folder'],
                                                     item_name)
                    item.setIcon(self.icons['Folder'])
                    ContentListWidget.addItem(
                        item)  # populate the list widget in the GUI
                elif object['itemType'] == 'Search':
                    item = QtWidgets.QListWidgetItem(self.icons['Search'],
                                                     item_name)
                    item.setIcon(self.icons['Search'])
                    ContentListWidget.addItem(
                        item)  # populate the list widget in the GUI
                elif object['itemType'] == 'Dashboard':
                    item = QtWidgets.QListWidgetItem(self.icons['Dashboard'],
                                                     item_name)
                    item.setIcon(self.icons['Dashboard'])
                    ContentListWidget.addItem(
                        item)  # populate the list widget in the GUI
                elif object['itemType'] == 'Lookups':
                    item = QtWidgets.QListWidgetItem(self.icons['Dashboard'],
                                                     item_name)
                    item.setIcon(self.icons['Lookups'])
                    ContentListWidget.addItem(
                        item)  # populate the list widget in the GUI
                else:
                    ContentListWidget.addItem(
                        item_name
                    )  # populate the list widget in the GUI with no icon (fallthrough)

            dirname = ''
            for dir in ContentListWidget.currentdirlist:
                dirname = dirname + '/' + dir['name']
            directorylabel.setText(dirname)
            ContentListWidget.updated = True
            # if we are in the root (Top) of the global folders then we can't manipulate stuff as the entries are actually users, not content
            # so turn off the buttons until we change folder type or move down a level
            currentdir = ContentListWidget.currentdirlist[-1]
            if currentdir['id'] == 'TOP' and radioselected == -3:
                self.togglecontentbuttons(ContentListWidget.side, False)
            else:
                self.togglecontentbuttons(ContentListWidget.side, True)

        except Exception as e:
            logger.exception(e)
        return
예제 #30
0
    def backupcontent(self, ContentListWidget, url, id, key, radioselected):
        logger.info("Backing Up Content")
        if radioselected == -3 or radioselected == -4:  # Admin or Global folders selected
            adminmode = True
        else:
            adminmode = False
        selecteditems = ContentListWidget.selectedItems()
        if len(selecteditems) > 0:  # make sure something was selected
            savepath = str(
                QtWidgets.QFileDialog.getExistingDirectory(
                    self, "Select Backup Directory"))
            if os.access(savepath, os.W_OK):
                message = ''
                sumo = SumoLogic(id, key, endpoint=url)
                for selecteditem in selecteditems:
                    for child in ContentListWidget.currentcontent['children']:
                        if child['name'] == str(selecteditem.text()):
                            item_id = child['id']
                            try:
                                content = sumo.export_content_job_sync(
                                    item_id, adminmode=adminmode)
                                savefilepath = pathlib.Path(
                                    savepath + r'/' +
                                    str(selecteditem.text()) +
                                    r'.sumocontent.json')
                                if savefilepath:
                                    with savefilepath.open(
                                            mode='w') as filepointer:
                                        json.dump(content, filepointer)
                                    message = message + str(selecteditem.text(
                                    )) + r'.sumocontent.json' + '\n'
                            except Exception as e:
                                logger.exception(e)
                                self.mainwindow.errorbox(
                                    'Something went wrong:\n\n' + str(e))
                                return
                self.mainwindow.infobox('Wrote files: \n\n' + message)
            else:
                self.mainwindow.errorbox(
                    "You don't have permissions to write to that directory")

        else:
            self.mainwindow.errorbox('No content selected.')
        return