Example #1
0
def get_appname(params):
    if 'appname' in params:
        app_name = params['appname']
    else:
        service = common_util.create_splunk_service(
            cherrypy.session.get("sessionKey"), scc.getMgmtUri())
        apps = [app.name for app in service.apps if app.name]

        conf_manager = common_util.create_conf_mgr(
            cherrypy.session.get("sessionKey"), scc.getMgmtUri())
        conf_file = conf_manager.get_conf(tabuilder_status_conf)
        app_name_create = None
        app_name_edit = None
        if tab_conf_manager.is_stanza_exists(conf_file, create_ta_stanza):
            app_name_create = conf_file.get(create_ta_stanza).get(
                cca_key, None)
            create_in_action = conf_file.get(create_ta_stanza).get(
                "action", False)
            if create_in_action and app_name_create in apps:
                return app_name_create

        if tab_conf_manager.is_stanza_exists(conf_file, edit_ta_stanza):
            app_name_edit = conf_file.get(edit_ta_stanza).get(cca_key, None)
            if app_name_edit in apps:
                return app_name_edit

        return builder_constant.ADDON_BUILDER_APP_NAME
Example #2
0
    def handleEdit(self, confInfo):
        logger.info("start edit")

        # all_settings = utils.escape_json_control_chars(
        #    self.callerArgs.data[c.all_settings][0])
        all_settings = self.callerArgs.data[c.all_settings][0]
        all_settings = json.loads(all_settings)
        proxy_settings = all_settings[c.proxy_settings]
        if utils.is_false(proxy_settings.get(c.proxy_enabled, None)):
            del all_settings[c.proxy_settings]

        # 1) Global settings / Proxy settings
        ta_conf_mgr = ta_conf.TAConfManager(
            c.myta_global_settings_conf, scc.getMgmtUri(),
            self.getSessionKey())

        ta_conf_mgr.set_encrypt_keys(self.encrypt_fields)
        for k in (c.global_settings, c.proxy_settings):
            settings = all_settings.get(k, {})
            settings[c.name] = k
            ta_conf_mgr.update(settings)

        # 2) Credentials / Data collections
        for name, conf_file in self.confs:
            settings = all_settings.get(name, {})
            ta_conf_mgr = ta_conf.TAConfManager(
                conf_file, scc.getMgmtUri(), self.getSessionKey(),
                appname=self.appName)
            ta_conf_mgr.set_encrypt_keys(self.encrypt_fields)
            self._updateCredentials(settings, ta_conf_mgr)

        logger.info("end edit")
Example #3
0
 def handleList(self, confInfo):
     logger.info("start list")
     conf_mgr = conf.ConfManager(scc.getMgmtUri(), self.getSessionKey())
     conf_mgr.reload_conf(c.myta_conf)
     conf_mgr.reload_conf(c.myta_credential_conf)
     conf_mgr.reload_conf(c.myta_customized_conf)
     # read globala and proxy settings
     all_settings = conf_mgr.all_stanzas_as_dicts(c.myta_conf)
     if not all_settings:
         all_settings = {}
     self._setNoneValues(all_settings.get(c.global_settings, {}))
     # read account credential settings
     for cred, cred_conf in self.cred_confs:
         ta_conf_mgr = ta_conf.TAConfManager(cred_conf, scc.getMgmtUri(),
                                             self.getSessionKey())
         ta_conf_mgr.set_encrypt_keys(self.encrypt_fields_credential)
         creds = ta_conf_mgr.all(return_acl=False)
         if creds:
             self._setNoneValues(creds)
             all_settings.update({cred: creds})
     # read customized settings
     ta_conf_mgr = ta_conf.TAConfManager(c.myta_customized_conf,
                                         scc.getMgmtUri(),
                                         self.getSessionKey())
     ta_conf_mgr.set_encrypt_keys(self.encrypt_fields_customized)
     customized_settings = ta_conf_mgr.all(return_acl=False)
     all_settings.update({c.myta_customized_settings: customized_settings})
     self._clearPasswords(all_settings, self.cred_fields)
     all_settings = json.dumps(all_settings)
     all_settings = utils.escape_json_control_chars(all_settings)
     confInfo[c.myta_settings].append(c.all_settings, all_settings)
     logger.info("end list")
 def handleList(self, confInfo):
     logger.info("start list")
     conf_mgr = conf.ConfManager(scc.getMgmtUri(), self.getSessionKey())
     conf_mgr.reload_conf(c.myta_conf)
     conf_mgr.reload_conf(c.myta_credential_conf)
     conf_mgr.reload_conf(c.myta_customized_conf)
     # read globala and proxy settings
     all_settings = conf_mgr.all_stanzas_as_dicts(c.myta_conf)
     if not all_settings:
         all_settings = {}
     self._setNoneValues(all_settings.get(c.global_settings, {}))
     # read account credential settings
     for cred, cred_conf in self.cred_confs:
         ta_conf_mgr = ta_conf.TAConfManager(
             cred_conf, scc.getMgmtUri(), self.getSessionKey())
         ta_conf_mgr.set_encrypt_keys(self.encrypt_fields_credential)
         creds = ta_conf_mgr.all(return_acl=False)
         if creds:
             self._setNoneValues(creds)
             all_settings.update({cred: creds})
     # read customized settings
     ta_conf_mgr = ta_conf.TAConfManager(
         c.myta_customized_conf, scc.getMgmtUri(), self.getSessionKey())
     ta_conf_mgr.set_encrypt_keys(self.encrypt_fields_customized)
     customized_settings = ta_conf_mgr.all(return_acl=False)
     all_settings.update({c.myta_customized_settings: customized_settings})
     self._clearPasswords(all_settings, self.cred_fields)
     all_settings = json.dumps(all_settings)
     all_settings = utils.escape_json_control_chars(all_settings)
     confInfo[c.myta_settings].append(c.all_settings, all_settings)
     logger.info("end list")
Example #5
0
    def handleList(self, confInfo):
        logger.info("start list")

        conf_mgr = conf.ConfManager(scc.getMgmtUri(),
                                    self.getSessionKey(),
                                    app_name=self.appName)
        conf_mgr.reload_conf(c.myta_conf)
        conf_mgr.reload_conf(c.myta_cred_conf)
        conf_mgr.reload_conf(c.myta_forwarder_conf)

        all_settings = conf_mgr.all_stanzas_as_dicts(c.myta_conf)
        if not all_settings:
            all_settings = {}

        self._setNoneValues(all_settings.get(c.global_settings, {}))
        for cred, cred_conf in self.cred_confs:
            ta_conf_mgr = ta_conf.TAConfManager(cred_conf,
                                                scc.getMgmtUri(),
                                                self.getSessionKey(),
                                                appname=self.appName)
            ta_conf_mgr.set_encrypt_keys(self.encrypt_fields)
            creds = ta_conf_mgr.all(return_acl=False)
            if creds:
                self._setNoneValues(creds)
                all_settings.update({cred: creds})

        self._clearPasswords(all_settings, self.cred_fields)

        all_settings = json.dumps(all_settings)
        all_settings = utils.escape_json_control_chars(all_settings)
        confInfo[c.myta_settings].append(c.all_settings, all_settings)

        logger.info("end list")
Example #6
0
    def handleList(self, confInfo):
        _LOGGER.info("start list")

        conf.reload_confs(("okta", ), self.getSessionKey(), scc.getMgmtUri())
        conf_mgr = oc.OktaConfManager(scc.getMgmtUri(), self.getSessionKey())
        confDict = conf_mgr.get(self.appName, self.okta_endpoint)

        if confDict:
            for key, val in confDict.iteritems():
                if key in self.okta_args:
                    if val is None:
                        val = ""
                    confInfo[self.okta_endpoint].append(key, val)
        _LOGGER.info("end list")
Example #7
0
 def global_settings(self, resource, **params):
     session_key = cherrypy.session.get("sessionKey")
     splunkd_uri = scc.getMgmtUri()
     tabuilder = builder.TABuilder(controller_util.get_current_ta_project(),
                                   splunkd_uri, session_key)
     if cherrypy.request.method == 'GET':
         global_settings = tabuilder.get_global_settings()
         if global_settings is None:
             global_settings = {}
         return self.render_json(global_settings)
     elif cherrypy.request.method == 'POST':
         cl = cherrypy.request.headers["Content-Length"]
         raw_body = cherrypy.request.body.read(int(cl))
         params = json.loads(raw_body)
         try:
             # did some clean up in case frontend does not clean it up
             if 'customized_settings' in params and len(
                     params['customized_settings']) == 0:
                 del params['customized_settings']
             logger.info("global settings params are : %s", params)
             tabuilder.update_global_settings(params)
             return self.render_json({"status": "success"})
         except CommonException as e:
             logger.error("fail to save global settings. Error: %s",
                          traceback.format_exc())
             return self.render_json({
                 'err_code': e.get_err_code(),
                 'err_args': e.get_options()
             })
         except Exception as e:
             logger.error("fail to save global settings. Error: %s",
                          traceback.format_exc())
             raise e
Example #8
0
    def handleList(self, conf_info):
        logger.info("start list google projects")
        if (not self.callerArgs
                or not self.callerArgs.get(ggc.google_credentials_name)):
            logger.error("Missing Google credentials")
            raise Exception("Missing Google credentials")

        stanza_name = self.callerArgs[ggc.google_credentials_name][0]
        logger.info(self.callerArgs[ggc.google_credentials_name])
        config = gconf.get_google_settings(scc.getMgmtUri(),
                                           self.getSessionKey(),
                                           cred_name=stanza_name)
        res_mgr = grm.GoogleResourceManager(logger, config)
        try:
            projects = [project["projectId"] for project in res_mgr.projects()]
        except googleapiclient.errors.HttpError as e:
            if e.resp.status == 403:
                projects = [config[ggc.google_credentials]["project_id"]]
            else:
                raise e
        except Exception as e:
            print(e)
            raise BaseException()
        conf_info["google_projects"].append("projects", projects)
        logger.info("end of listing google projects")
Example #9
0
 def set_level(name, token, level, appName='-'):
     if level in _levelNames:
         HOST = scc.getMgmtUri()
         response=simpleRequest(HOST + '/servicesNS/nobody/%s/properties/log_info/%s' % (appName,name), postargs={'level':level},sessionKey=token)
         return response
     else:
         return None
Example #10
0
    def start_parse_unstructured_data(self, action, **params):
        session = cherrypy.session.get("sessionKey")
        splunk_uri = scc.getMgmtUri()
        app_name = params['app_name']
        sourcetype = params['sourcetype']
        batch_size = params.get("batch_size", None)

        try:
            tabuilder = TABuilder(app_name, splunk_uri, session)
            tabuilder.remove_all_unstructured_data_inputs()
            tabuilder.start_parse_unstructured_data(sourcetype, batch_size)
            return self.render_json({"data": {"successful": True,
                                              "app_name": app_name,
                                              "sourcetype": sourcetype}})

        except CommonException as e:
            tabuilder.cancel_parse_unstructured_data(sourcetype)
            logger.error('Get CommonException when getting auto extraction results. meta:%s, error:%s',
                         params, traceback.format_exc())
            return self.render_json({'err_code': e.get_err_code(),
                                     'err_args': e.get_options()})
        except Exception as e:
            tabuilder.cancel_parse_unstructured_data(sourcetype)
            logger.error("Cannot get extractions for sourcetype %s. error: %s",
                         sourcetype, traceback.format_exc())
            raise e
Example #11
0
    def get_unstructured_data_status(self, action, **params):
        session = cherrypy.session.get("sessionKey")
        splunk_uri = scc.getMgmtUri()
        app_name = params['app_name']
        sourcetype = params['sourcetype']

        try:
            tabuilder = TABuilder(app_name, splunk_uri, session)
            results = tabuilder.get_unstructured_data_status(sourcetype)
            if results.get("error"):
                tabuilder.cancel_parse_unstructured_data(sourcetype)
                return self.render_json(results.get("error"))

            return self.render_json({"data": results})
        except CommonException as e:
            tabuilder.cancel_parse_unstructured_data(sourcetype)
            logger.error('Get CommonException when getting auto extraction results. meta:%s, error:%s',
                         params, traceback.format_exc())
            return self.render_json({'err_code': e.get_err_code(),
                                     'err_args': e.get_options()})
        except Exception as e:
            tabuilder.cancel_parse_unstructured_data(sourcetype)
            logger.error("Cannot get extractions for sourcetype %s. error: %s",
                         sourcetype, traceback.format_exc())
            raise e
Example #12
0
    def app_delete(self, **params):

        session = cherrypy.session.get("sessionKey")
        splunk_uri = scc.getMgmtUri()
        service = common_util.create_splunk_service(session, splunk_uri)
        cl = cherrypy.request.headers["Content-Length"]
        raw_body = cherrypy.request.body.read(int(cl))
        app_context = json.loads(raw_body)
        app_name = app_context["name"]
        try:
            if meta_util.is_app_created_by_aob(service, app_name):
                app_util.delete_app(service, app_name, splunk_uri, session)
            else:
                raise builder_exception.CommonException(
                    err_code=64, options={'current_app': app_name})
            return self.render_json({
                "result":
                "success",
                "message":
                "TA {} has been successfully deleted".format(app_name)
            })
        except builder_exception.CommonException as e:
            logger.error('Fail to delete app. %s', traceback.format_exc())
            return self.render_json({
                "err_code": e.get_err_code(),
                "err_args": e.get_options()
            })
        except Exception as e:
            logger.error('Fail to delete app %s. %s', app_name,
                         traceback.format_exc())
            return self.render_json({'err_code': 1003, 'err_args': app_name})
Example #13
0
    def handleList(self, conf_info):
        logger.info("start listing google subscriptions")
        for required in self.valid_params:
            if not self.callerArgs or not self.callerArgs.get(required):
                logger.error('Missing "%s"', required)
                raise Exception('Missing "{}"'.format(required))

        stanza_name = self.callerArgs[ggc.google_credentials_name][0]
        config = gconf.get_google_settings(scc.getMgmtUri(),
                                           self.getSessionKey(),
                                           cred_name=stanza_name)

        project = self.callerArgs[ggc.google_project][0]
        config.update({
            "service_name":
            "storage",
            "version":
            "v1",
            "scopes":
            ["https://www.googleapis.com/auth/cloud-platform.read-only"]
        })
        storage = create_google_client(config)

        buckets = storage.buckets()
        bucket_names = list()
        request = buckets.list(project=project)
        while request:
            try:
                response = request.execute()
            except googleapiclient.errors.HttpError, exc:
                RH_Err.ctl(400, exc)
            names = [item.get('name') for item in response.get('items')]
            bucket_names.extend(names)
            request = buckets.list_next(request, response)
 def get_modular_alerts_summary(self, action, **params):
     session_key = cherrypy.session.get("sessionKey")
     splunkd_uri = scc.getMgmtUri()
     tabuilder = builder.TAAlertBuilder(
         controller_util.get_current_ta_project(), splunkd_uri, session_key)
     all_modular_alerts = tabuilder.get_all_TA_alerts() or []
     return self.render_json(all_modular_alerts)
Example #15
0
    def get_sourcetype_basic_info(self, action, **params):
        session = cherrypy.session.get("sessionKey")
        splunk_uri = scc.getMgmtUri()
        app_name = params['app_name']

        try:
            tabuilder = TABuilder(app_name, splunk_uri, session)
            data = tabuilder.get_sourcetype_basic_info() or {}
            sourcetypes = []
            for k, v in list(data.items()):
                item = {"name": k}
                item.update(v)
                sourcetypes.append(item)
            sourcetypes.sort(key=lambda x: x.get("name"))
            ret = {
                'status': 'success',
                'data': sourcetypes,
            }
            return self.render_json(ret)
        except CommonException as ce:
            logger.error("Can not get basic info. error:%s",
                         traceback.format_exc())
            return self.render_json({
                'err_code': ce.get_err_code(),
                'err_args': ce.get_options()
            })
        except Exception as e:
            logger.error("Cannot get basic info. error: %s",
                         traceback.format_exc())
            raise e
Example #16
0
 def edit_data_input(self, action, **params):
     cl = cherrypy.request.headers["Content-Length"]
     raw_body = cherrypy.request.body.read(int(cl))
     params = json.loads(raw_body)
     appname = controller_util.get_current_ta_project()
     reload_input = params.get('reload_input', True)
     if 'reload_input' in params:
         del params['reload_input']
     splunkd_uri, session_key = scc.getMgmtUri(), cherrypy.session.get(
         "sessionKey")
     try:
         tabuilder = builder.TABuilder(appname, splunkd_uri, session_key)
         tabuilder.update_TA_input(params, reload_input)
         return self.render_json({"status": "success", "meta": params})
     except CommonException as e:
         logger.error(
             'Get CommonException when update data input. meta:%s, error:%s',
             params, traceback.format_exc())
         return self.render_json({'err_code': e.get_err_code(),
                                  'err_args': e.get_options()})
     except Exception as e:
         logger.error(
             'Get exception when update data input. meta:%s, error:%s',
             params, traceback.format_exc())
         raise e
Example #17
0
    def _handleUpdateProxyAccount(self, confInfo, args):
        settings = ("proxy_url", "proxy_username", "proxy_password",
                    "proxy_port", "proxy_enabled", "proxy_rdns", "proxy_type")

        if not utils.is_true(args["proxy_enabled"][0]):
            _LOGGER.info("Disabling proxy")
            for k in settings:
                if k not in ("proxy_type", "proxy_rdns"):
                    args[k] = [""]
            args["proxy_enabled"][0] = "0"

            confDict = self.readConf("service_now")
            if (confDict.get("snow_proxy")
                    and confDict["snow_proxy"].get("proxy_url")):
                proxy_url = confDict["snow_proxy"]["proxy_url"]
                _LOGGER.info("Remove credentials for proxy %s", proxy_url)
                mgr = cred.CredentialManager(self.getSessionKey(),
                                             scc.getMgmtUri())
                mgr.delete(proxy_url, self.dummy, self.appName)

        if (utils.is_true(args["proxy_enabled"][0])
                and args["proxy_username"][0]
                and not args["proxy_password"][0]):
            _LOGGER.error("Missing proxy password")
            raise Exception("Missing proxy password")

        self._handleUpdateAccount(confInfo, args, "snow_proxy", settings)
Example #18
0
 def delete_alias(self, action, **params):
     cl = cherrypy.request.headers["Content-Length"]
     raw_body = cherrypy.request.body.read(int(cl))
     params = json.loads(raw_body)
     session = cherrypy.session.get("sessionKey")
     splunk_uri = scc.getMgmtUri()
     appname = controller_util.get_current_ta_project()
     sourcetype = params['sourcetype']
     input_field = params['input_field']
     output_field = params['output_field']
     search = params["search"]
     try:
         builder = TACIMBuilder(appname, splunk_uri, session)
         res = builder.delete_alias(sourcetype, output_field, input_field,
                                    search)
         return self.render_json({"data": res})
     except CommonException as e:
         logger.error(
             'Get CommonException when deleting alias. meta:%s, error:%s',
             params, traceback.format_exc())
         return self.render_json({
             'err_code': e.get_err_code(),
             'err_args': e.get_options()
         })
     except Exception as e:
         logger.error("Cannot delete alias %s. error: %s", output_field,
                      traceback.format_exc())
         raise e
Example #19
0
    def code_run(self, action, **params):
        # check the role of current user, only admin can run code
        username = cherrypy.session.get('user').get('name')
        session_key = cherrypy.session.get("sessionKey")
        splunkd_uri = scc.getMgmtUri()
        service = common_util.create_splunk_service(session_key, splunkd_uri)
        params = None
        try:
            r = app_util.is_user_allow_to_create_ta(username, service)
            if r:
                # if getting error code, just render it
                return self.render_json(r)

            cl = cherrypy.request.headers["Content-Length"]
            raw_body = cherrypy.request.body.read(int(cl))
            params = json.loads(raw_body)  # params is the meta for this input
            appname = controller_util.get_current_ta_project()
            input_builder = builder_ta_input.TAInputBuilder(
                appname, splunkd_uri, session_key)
            dryrun_result = input_builder.dryrun_modinput_code(params)
            return self.render_json(dryrun_result)
        except CommonException as ce:
            logger.error('Fail to dryrun data input. meta:%s, error:%s',
                         params, traceback.format_exc())
            return self.render_json({'err_code': ce.get_err_code(),
                                     'err_args': ce.get_options()})
Example #20
0
 def handleEdit(self, confInfo):
     logger.info("start edit setup configure.")
     scheme, host, port = utils.extract_http_scheme_host_port(
         scc.getMgmtUri())
     conf_mgr = conf.ConfManager(self.getSessionKey(),
                                 self.appName,
                                 scheme=scheme,
                                 host=host,
                                 port=port)
     ta_conf_file = get_or_create_conf_file(conf_mgr, setup_const.myta_conf)
     customized_conf_file = get_or_create_conf_file(
         conf_mgr, setup_const.myta_customized_conf)
     all_origin_settings = ta_conf_file.get_all()
     all_settings = utils.escape_json_control_chars(
         self.callerArgs.data[setup_const.all_settings][0])
     all_settings = json.loads(all_settings)
     # write global and proxy settings
     self._updateGlobalSettings(setup_const.global_settings, all_settings,
                                all_origin_settings, ta_conf_file)
     self._updateGlobalSettings(setup_const.proxy_settings, all_settings,
                                all_origin_settings, ta_conf_file)
     # write customized settings
     customized_conf_file = get_or_create_conf_file(
         conf_mgr, setup_const.myta_customized_conf)
     self._updateConfStanzas(
         all_settings.get(setup_const.myta_customized_settings, {}),
         customized_conf_file, self.encrypt_fields_customized)
     logger.info("edit setup configure is done")
Example #21
0
 def create_eventtype(self, action, **params):
     cl = cherrypy.request.headers["Content-Length"]
     raw_body = cherrypy.request.body.read(int(cl))
     params = json.loads(raw_body)
     session = cherrypy.session.get("sessionKey")
     splunk_uri = scc.getMgmtUri()
     appname = controller_util.get_current_ta_project()
     name = params['name']
     search = params['search']
     sourcetype_dict = params['sourcetypes']
     try:
         builder = TACIMBuilder(appname, splunk_uri, session)
         builder.create_eventtype(name, search, sourcetype_dict)
         return self.render_json({"data": {"successful": True}})
     except CommonException as e:
         logger.error(
             'Get CommonException when creating eventtype. meta:%s, error:%s',
             params, traceback.format_exc())
         return self.render_json({
             'err_code': e.get_err_code(),
             'err_args': e.get_options()
         })
     except Exception as e:
         logger.error("Cannot create eventtype %s. error: %s", name,
                      traceback.format_exc())
         raise e
Example #22
0
    def handleList(self, confInfo):
        logger.info("start list setup configure.")
        scheme, host, port = utils.extract_http_scheme_host_port(
            scc.getMgmtUri())
        conf_mgr = conf.ConfManager(self.getSessionKey(),
                                    self.appName,
                                    scheme=scheme,
                                    host=host,
                                    port=port)
        ta_conf_file = get_or_create_conf_file(conf_mgr, setup_const.myta_conf)
        # read globala and proxy settings
        all_settings = ta_conf_file.get_all()
        if not all_settings:
            all_settings = {}
        self._setNoneValues(all_settings.get(setup_const.global_settings, {}))
        # customized conf
        customized_conf_file = get_or_create_conf_file(
            conf_mgr, setup_const.myta_customized_conf)
        settings = customized_conf_file.get_all()
        all_settings[setup_const.myta_customized_settings] = settings

        self._clearPasswords(all_settings, self.cred_fields)
        all_settings = filter_eai_property(all_settings)
        all_settings = json.dumps(all_settings)
        all_settings = utils.escape_json_control_chars(all_settings)
        confInfo[setup_const.myta_settings].append(setup_const.all_settings,
                                                   all_settings)
        logger.info("list setup configure is done.")
Example #23
0
 def get_eventtypes(self, action, **params):
     cl = cherrypy.request.headers["Content-Length"]
     raw_body = cherrypy.request.body.read(int(cl))
     params = json.loads(raw_body)
     session = cherrypy.session.get("sessionKey")
     splunk_uri = scc.getMgmtUri()
     appname = params['app_name']
     name = params['name']
     try:
         builder = TACIMBuilder(appname, splunk_uri, session)
         res = eventtype_util.get_eventtype(builder.tab_conf_mgr,
                                            stanza=None,
                                            with_tags=False)
         return self.render_json({"data": res})
     except CommonException as e:
         logger.error(
             'Get CommonException when getting eventtype. meta:%s, error:%s',
             params, traceback.format_exc())
         return self.render_json({
             'err_code': e.get_err_code(),
             'err_args': e.get_options()
         })
     except Exception as e:
         logger.error("Cannot get eventtype %s. error: %s", name,
                      traceback.format_exc())
         raise e
Example #24
0
 def validate_input_meta(self, action, **params):
     '''
     post body:
         {
             "uuid": uuid // first time to create the input, no uuid yet
             "name": name,
             "title": title,
             "description": description,
             "type": type,
             "sourcetype": sourcetype,
             "interval": interval,
         }
     '''
     session_key = cherrypy.session.get("sessionKey")
     splunkd_uri = scc.getMgmtUri()
     input_builder = builder_ta_input.TAInputBuilder(
         controller_util.get_current_ta_project(), splunkd_uri, session_key)
     alert_builder = builder_ta_alert.TAAlertBuilder(
         controller_util.get_current_ta_project(), splunkd_uri, session_key)
     input_builder.set_alert_builder(alert_builder)
     cl = cherrypy.request.headers["Content-Length"]
     raw_body = cherrypy.request.body.read(int(cl))
     meta = json.loads(raw_body)
     response = {}
     try:
         input_builder.validate_input_name_and_sourcetype(meta)
         response['validate_result'] = 'success'
     except CommonException as ce:
         logger.error('Validate input meta fails. %s',
                      traceback.format_exc())
         response['err_code'] = ce.get_err_code()
         response['err_args'] = ce.get_options()
     return self.render_json(response)
Example #25
0
    def check_cim_available(self, action, **params):
        cl = cherrypy.request.headers["Content-Length"]
        raw_body = cherrypy.request.body.read(int(cl))
        params = json.loads(raw_body)
        session = cherrypy.session.get("sessionKey")
        splunk_uri = scc.getMgmtUri()
        appname = controller_util.get_current_ta_project()
        try:
            builder = TACIMBuilder(appname, splunk_uri, session)
            confs = builder.check_cim_available()

            res = {"data": {"successful": True}}
            if confs:
                res = {"data": {"successful": False, "conf_names": confs}}
            return self.render_json(res)
        except CommonException as e:
            logger.error(
                'Get CommonException when checking CIM available for app %s. meta:%s, error:%s',
                appname, params, traceback.format_exc())
            return self.render_json({
                'err_code': e.get_err_code(),
                'err_args': e.get_options()
            })
        except Exception as e:
            logger.error("Cannot check CIM available for app %s. error: %s",
                         appname, traceback.format_exc())
            raise e
Example #26
0
 def create_eval(self, action, **params):
     cl = cherrypy.request.headers["Content-Length"]
     raw_body = cherrypy.request.body.read(int(cl))
     params = json.loads(raw_body)
     session = cherrypy.session.get("sessionKey")
     splunk_uri = scc.getMgmtUri()
     appname = controller_util.get_current_ta_project()
     sourcetypes = params['sourcetypes']
     output_field = params['output_field']
     expression = params['expression']
     search = params['search']
     try:
         builder = TACIMBuilder(appname, splunk_uri, session)
         res = builder.update_eval(sourcetypes,
                                   output_field,
                                   expression,
                                   search,
                                   check_exist=True)
         return self.render_json({"data": res})
     except CommonException as e:
         logger.error(
             'Get CommonException when creating eval. meta:%s, error:%s',
             params, traceback.format_exc())
         return self.render_json({
             'err_code': e.get_err_code(),
             'err_args': e.get_options()
         })
     except Exception as e:
         logger.error("Cannot create eval %s. error: %s", expression,
                      traceback.format_exc())
         raise e
Example #27
0
    def handleList(self, confInfo):
        """
        Read the initial values of the parameters from the custom file
        service_now.conf, and write them to the setup screen.

        If the app has never been set up, uses default/service_now.conf.

        If app has been set up, looks at local/service_now.conf first,
        then looks at default/service_now.conf only if there is no value for
        a field in local/service_now.conf

        For text fields, if the conf file says None, set to the empty string.
        """

        _LOGGER.info("start list")
        conf.reload_confs(("service_now", ), self.getSessionKey(),
                          scc.getMgmtUri())

        confDict = self.readConf("service_now")

        if confDict is not None:
            self._decrypt_username_password(confDict)

            for stanza, settings in confDict.items():
                for key, val in settings.items():
                    if key in self.snow_args and val is None:
                        val = ""

                    if key in ("password", "proxy_password"):
                        val = ""

                    confInfo[stanza].append(key, val)
        _LOGGER.info("end list")
Example #28
0
 def upgrade_app_project(self, action, **params):
     session = cherrypy.session.get("sessionKey")
     splunkd_uri = scc.getMgmtUri()
     cl = cherrypy.request.headers["Content-Length"]
     raw_body = cherrypy.request.body.read(int(cl))
     app_context = json.loads(raw_body)
     app_name = app_context.get('app_name', '')
     try:
         service = common_util.create_splunk_service(
             session, splunkd_uri, builder_constant.ADDON_BUILDER_APP_NAME)
         app_project = app.App(app_name, service)
         ta_builder = builder.TABuilder(app_name,
                                        uri=splunkd_uri,
                                        session_key=session)
         app_project.upgrade(ta_builder)
         return self.render_json({})
     except CommonException as ce:
         logger.error("Fail to upgrade app. %s", traceback.format_exc())
         return self.render_json({
             'err_code': ce.get_err_code(),
             'err_args': ce.get_options()
         })
     except Exception as e:
         logger.error("Fail to upgrade app. %s", traceback.format_exc())
         return self.render_json({'err_code': 19})
Example #29
0
 def get_global_is_secure(session_key):
     conf_manager = ConfManager(scc.getMgmtUri(), session_key)
     conn = conf_manager.get_stanza('aws_global_settings',
                                    'aws_connection',
                                    do_reload=False)
     return (utils.is_true(conn["is_secure"]),
             utils.is_true(conn["verify_certificates"]))
Example #30
0
    def set_tab_global_settings(self, action, **params):
        session_key = cherrypy.session.get("sessionKey")
        splunkd_uri = scc.getMgmtUri()
        settings = json.loads(params['settings'])

        try:
            encrypt_keys = ("password", "username", "proxy_username",
                            "proxy_password")
            conf_mgr = common_util.create_conf_mgr(session_key, splunkd_uri)
            conf = conf_mgr.get_conf(builder_constant.GLOBAL_SETTING_CONF_NAME)
            conf_settings = conf.get_all()

            app_cert = AppCert(splunkd_uri, session_key,
                               builder_constant.ADDON_BUILDER_APP_NAME)
            app_cert_settings = conf_settings.get("app_cert", {}).copy()
            app_cert_settings.update(settings.get("app_cert"))
            app_cert.validate_settings(app_cert_settings)

            for stanza, key_values in list(settings.items()):
                conf.update(stanza, key_values, encrypt_keys)

            return self.render_json({"data": settings})
        except CommonException as ce:
            return self.render_json({
                'err_code': ce.get_err_code(),
                'err_args': ce.get_options()
            })
Example #31
0
    def current_creating_app(self, action, **params):
        # POST
        cl = cherrypy.request.headers["Content-Length"]
        raw_body = cherrypy.request.body.read(int(cl))
        app_context = json.loads(raw_body)
        app_name = app_context.get('app_name', '')
        if app_name:
            controller_util.set_current_ta_project(app_name)
        else:
            controller_util.delete_current_ta_project()

        app_display_name = app_context.get('app_display_name', '')
        controller_util.set_current_ta_display_name(app_display_name)

        # default is built by tabuilder
        built = app_context.get('built', 'yes')
        controller_util.set_built_flag(built)

        if app_name:
            mgr = meta_manager.create_meta_manager(
                cherrypy.session.get("sessionKey"), scc.getMgmtUri(),
                meta_const.APP_CONTEXT, app_name)
        return self.render_json({
            'app_name':
            app_name,
            'app_display_name':
            app_display_name,
            'built':
            built,
            'cookies':
            controller_util.format_response_cookie()
        })
Example #32
0
 def save_models(self, action, **params):
     cl = cherrypy.request.headers["Content-Length"]
     raw_body = cherrypy.request.body.read(int(cl))
     params = json.loads(raw_body)
     session = cherrypy.session.get("sessionKey")
     splunk_uri = scc.getMgmtUri()
     appname = controller_util.get_current_ta_project()
     eventtype_name = params["eventtype_name"]
     new_models = params['new_models']
     old_models = params['old_models']
     try:
         builder = TACIMBuilder(appname, splunk_uri, session)
         res = builder.save_models(eventtype_name, new_models, old_models)
         return self.render_json({"data": {"successful": True}})
     except CommonException as e:
         logger.error(
             'Get CommonException when saving models for eventtype %s. meta:%s, error:%s',
             eventtype_name, params, traceback.format_exc())
         return self.render_json({
             'err_code': e.get_err_code(),
             'err_args': e.get_options()
         })
     except Exception as e:
         logger.error(
             "Cannot save models objects for eventtype %s. error: %s",
             eventtype_name, traceback.format_exc())
         raise e
Example #33
0
    def handleList(self, conf_info):
        logger.info("start get iwork orgchart")

        config = {
            c.session_key: self.getSessionKey(),
            c.server_uri: scc.getMgmtUri(),
        }
        emp = ckpt.EmployeeDetailLookup(config)
        lookups = emp.all()
        conf_info[self.key].append(self.key, json.dumps(lookups))
        logger.info("end of getting iwork orgchart")
Example #34
0
    def setup(self):
        """
        Set up supported arguments
        """

        if self.requestedAction == admin.ACTION_EDIT:
            for arg in self.valid_args:
                self.supportedArgs.addOptArg(arg)

        conf_mgr = conf.ConfManager(scc.getMgmtUri(), self.getSessionKey(),
                                    app_name=self.appName)
        reload_confs(conf_mgr)
Example #35
0
    def handleList(self, confInfo):
        logger.info("start list")

        all_settings = {}

        # 1) Global settings / Proxy settings
        ta_conf_mgr = ta_conf.TAConfManager(
            c.myta_global_settings_conf, scc.getMgmtUri(),
            self.getSessionKey())

        ta_conf_mgr.set_encrypt_keys(self.encrypt_fields)
        all_settings = ta_conf_mgr.all(return_acl=False)
        if not all_settings:
            all_settings = {}
        self._setNoneValues(all_settings.get(c.global_settings, {}))
        self._setNoneValues(all_settings.get(c.proxy_settings, {}))

        # 2) Credentials / Data colletions
        for name, conf_file in self.confs:
            ta_conf_mgr = ta_conf.TAConfManager(
                conf_file, scc.getMgmtUri(), self.getSessionKey())
            ta_conf_mgr.set_encrypt_keys(self.encrypt_fields)
            settings = ta_conf_mgr.all(return_acl=False)
            if settings:
                for setting in settings.itervalues():
                    cred = setting.get(gpc.google_credentials)
                    if cred:
                        setting[gpc.google_credentials] = b64decode(cred)
                self._setNoneValues(settings)
                all_settings.update({name: settings})

        # self._clearPasswords(all_settings, self.encrypt_fields)

        all_settings = json.dumps(all_settings)
        # all_settings = utils.unescape_json_control_chars(all_settings)
        confInfo[c.myta_settings].append(c.all_settings, all_settings)

        logger.info("end list")
 def handleEdit(self, confInfo):
     logger.info("start edit")
     conf_mgr = conf.ConfManager(scc.getMgmtUri(), self.getSessionKey(),
                                 app_name=self.appName)
     conf_mgr.reload_conf(c.myta_conf)
     conf_mgr.reload_conf(c.myta_credential_conf)
     conf_mgr.reload_conf(c.myta_customized_conf)
     all_origin_settings = conf_mgr.all_stanzas_as_dicts(c.myta_conf)
     all_settings = utils.escape_json_control_chars(
         self.callerArgs.data[c.all_settings][0])
     all_settings = json.loads(all_settings)
     # write globala and proxy settings
     self._updateGlobalSettings(c.global_settings, all_settings,
                                all_origin_settings, conf_mgr)
     # write account credential settings
     for cred, conf_file in self.cred_confs:
         creds = all_settings.get(cred, {})
         if creds == c.ignore_backend_req:
             logger.info("Ignore backend rest request")
             continue
         ta_conf_mgr = ta_conf.TAConfManager(
             conf_file, scc.getMgmtUri(), self.getSessionKey(),
             appname=self.appName)
         ta_conf_mgr.set_encrypt_keys(self.encrypt_fields_credential)
         self._updateCredentials(creds, ta_conf_mgr)
     # write customized settings
     customized_settings = all_settings.get(c.myta_customized_settings, {})
     ta_conf_mgr = ta_conf.TAConfManager(
         c.myta_customized_conf, scc.getMgmtUri(), self.getSessionKey(),
         appname=self.appName)
     ta_conf_mgr.set_encrypt_keys(self.encrypt_fields_customized)
     self._updateCredentials(customized_settings, ta_conf_mgr)
     conf_mgr.reload_conf(c.myta_conf)
     conf_mgr.reload_conf(c.myta_credential_conf)
     conf_mgr.reload_conf(c.myta_customized_conf)
     logger.info("end edit")
Example #37
0
    def handleCreate(self, conf_info):
        logger.info("start creating iwork settings")
        if not self.callerArgs or not self.callerArgs.get(self.key):
            logger.error("Missing iwork settings")
            raise Exception("Missing iwork settings")

        mgr = tcm.TAConfManager(
            c.iwork, scc.getMgmtUri(), self.getSessionKey(),
            c.splunk_app_iwork)
        mgr.set_encrypt_keys([c.password])

        settings = json.loads(self.callerArgs[self.key][0])
        for stanza_name in (c.iemail_settings, c.icalendar_settings):
            settings[c.name] = stanza_name
            mgr.update(settings)
        logger.info("end of creating iwork settings")
Example #38
0
    def handleList(self, conf_info):
        logger.info("start listing iwork settings")

        mgr = tcm.TAConfManager(
            c.iwork, scc.getMgmtUri(), self.getSessionKey(),
            c.splunk_app_iwork)
        mgr.reload()
        mgr.set_encrypt_keys([c.password])
        stanzas = mgr.all(return_acl=False)
        result = {}
        for key in self.valid_params:
            if key is "password":
                continue
            result[key] = stanzas[c.iemail_settings].get(key)

        conf_info[self.key].append(self.key, json.dumps(result))
        logger.info("end of listing iwork settings")
def _getSplunkdUri():
    return comm.getMgmtUri().replace('127.0.0.1',socket.gethostname().lower())