def editClient(args, fromCLI): """ Edits the various options of a deployment client. THIS WORKS ON THE LOCAL FILESYSTEM. We usually don't want this, so this will only be used for certain options. """ paramsReq = () paramsOpt = tuple(optionMapClient.keys()) comm.validateArgs(paramsReq, paramsOpt, args) returnDict = {} if 0 == len(args): raise cex.ArgError, "No changes have been specified." if not module.deplClientStatus({}, fromCLI)["enabled"]: raise cex.ServerState, ERR_CLIENT_DIS currConf = comm.getMergedConf(module.DEPL_CLI_CONFIG) if not module.DEPL_CLI_STANZA in currConf: raise cex.ParsingError, ERR_CLI_STANZA # assuming that we only support one of each of these tags - replace every tag found, and add if non-existent. for arg, val in args.items(): paramName = optionMapClient[arg] # validate the few types of args we recognize, ignore anything else. try: if arg in (ARG_MCASTURI, ARG_DEPSERVURI): validate.checkIPPortOrHostPort(arg, val) elif arg == ARG_MCASTIP: validate.checkIP(arg, val) elif arg == ARG_POLLFREQ: validate.checkPosInt(arg, val) except cex.ValidationError: if "0" != val: # we use 0 to disable these things, i guess. raise # remove if 0. if "0" == val and paramName in currConf[module.DEPL_CLI_STANZA]: currConf[module.DEPL_CLI_STANZA].pop(paramName) # or add/set. else: currConf[module.DEPL_CLI_STANZA][paramName] = val # if we're at this point, *something* has changed. returnDict["restartRequired"] = True comm.writeConfFile( bundle_paths.make_path(module.DEPL_CLI_CONFIG + ".conf"), currConf) if fromCLI: logger.info("Configuration updated.") return returnDict
def editClient(args, fromCLI): """ Edits the various options of a deployment client. THIS WORKS ON THE LOCAL FILESYSTEM. We usually don't want this, so this will only be used for certain options. """ paramsReq = () paramsOpt = tuple(optionMapClient.keys()) comm.validateArgs(paramsReq, paramsOpt, args) returnDict = {} if 0 == len(args): raise cex.ArgError, "No changes have been specified." if not module.deplClientStatus({}, fromCLI)["enabled"]: raise cex.ServerState, ERR_CLIENT_DIS currConf = comm.getMergedConf(module.DEPL_CLI_CONFIG) if not module.DEPL_CLI_STANZA in currConf: raise cex.ParsingError, ERR_CLI_STANZA # assuming that we only support one of each of these tags - replace every tag found, and add if non-existent. for arg, val in args.items(): paramName = optionMapClient[arg] # validate the few types of args we recognize, ignore anything else. try: if arg in (ARG_MCASTURI, ARG_DEPSERVURI): validate.checkIPPortOrHostPort(arg, val) elif arg == ARG_MCASTIP: validate.checkIP(arg, val) elif arg == ARG_POLLFREQ: validate.checkPosInt(arg, val) except cex.ValidationError: if "0" != val: # we use 0 to disable these things, i guess. raise # remove if 0. if "0" == val and paramName in currConf[module.DEPL_CLI_STANZA]: currConf[module.DEPL_CLI_STANZA].pop(paramName) # or add/set. else: currConf[module.DEPL_CLI_STANZA][paramName] = val # if we're at this point, *something* has changed. returnDict["restartRequired"] = True comm.writeConfFile(bundle_paths.make_path(module.DEPL_CLI_CONFIG + ".conf"), currConf) if fromCLI: logger.info("Configuration updated.") return returnDict
def stanzaDisable(args, fromCLI): """ Disables a given stanza in a given conf file. """ paramsReq = (ARG_CONFIG, ARG_MODNAME, ARG_STANZA) paramsOpt = (ARG_AUTHSTR, ARG_USEFS) comm.validateArgs(paramsReq, paramsOpt, args) returnDict = {} stanza = args[ARG_STANZA] confFile = bundle_paths.make_path(args[ARG_CONFIG] + ".conf") authStr = (ARG_AUTHSTR in args) and args[ARG_AUTHSTR] or "" # see if it's currently enabled. currStatus = stanzaStatusInternal( { ARG_CONFIG: args[ARG_CONFIG], ARG_MODNAME: args[ARG_MODNAME], ARG_STANZA: stanza, ARG_AUTHSTR: authStr }, fromCLI) currEnabled = currStatus["enabled"] # get the local .conf file. don't use the stanzas given to us from "status", # because they're merged - we don't want to write out all the merged settings. # btw, readConfFile checks to see if the path exists and does the right thing. confStanzas = comm.readConfFile(confFile) if currEnabled: # then disable it returnDict["restartRequired"] = True # create the stanza if it's not in the .conf already (could be on via default bundle) if not stanza in confStanzas: confStanzas[stanza] = {} # and make sure we set the disabled key in local to be true. confStanzas[stanza][KEY_DISABLED] = "true" stanzaXml = comm.flatDictToXML(confStanzas[stanza]) # the following is now always true: # in order to support "splunk set deploy-poll", we allow this stuff to also write to the local filesystem. logger.debug("Attempting to disable module via local filesystem.") comm.writeConfFile(confFile, confStanzas) if not currEnabled: logger.info("%s is already disabled." % args[ARG_MODNAME]) else: logger.info("%s disabled." % args[ARG_MODNAME]) return returnDict
def stanzaEnable(args, fromCLI): """ Enables a given stanza in a given conf file. """ paramsReq = (ARG_CONFIG, ARG_MODNAME, ARG_STANZA) paramsOpt = (ARG_AUTHSTR, ARG_USEFS) comm.validateArgs(paramsReq, paramsOpt, args) returnDict = {} authStr = (ARG_AUTHSTR in args) and args[ARG_AUTHSTR] or "" stanza = args[ARG_STANZA] confFile = bundle_paths.make_path(args[ARG_CONFIG] + ".conf") currStatus = stanzaStatusInternal( { ARG_CONFIG: args[ARG_CONFIG], ARG_MODNAME: args[ARG_MODNAME], ARG_STANZA: stanza, ARG_AUTHSTR: authStr }, fromCLI) currEnabled = currStatus["enabled"] # get the local .conf file. don't use the stanzas given to us from "status", # because they're merged - we don't want to write out all the merged settings. # btw, readConfFile checks to see if the path exists and does the right thing. confStanzas = comm.readConfFile(confFile) if not currEnabled: # then enable it returnDict["restartRequired"] = True # create the stanza if it's not in the .conf already (if it was never enabled) if not stanza in confStanzas: confStanzas[stanza] = {} # at this point the only way for it to be disabled is for the disabled key to be true. # set it false regardless of whether or not it exists. confStanzas[stanza][KEY_DISABLED] = "false" stanzaXml = comm.flatDictToXML(confStanzas[stanza]) # the following is now always true: # if applicable, just write to the local FS (used by splunk set deploy-poll). logger.debug("Attempting to enable module via local filesystem.") comm.writeConfFile(confFile, confStanzas) if currEnabled: logger.info("%s is already enabled." % args[ARG_MODNAME]) else: logger.info("%s enabled." % args[ARG_MODNAME]) return returnDict
def stanzaDisable(args, fromCLI): """ Disables a given stanza in a given conf file. """ paramsReq = (ARG_CONFIG, ARG_MODNAME, ARG_STANZA) paramsOpt = (ARG_AUTHSTR, ARG_USEFS) comm.validateArgs(paramsReq, paramsOpt, args) returnDict = {} stanza = args[ARG_STANZA] confFile = bundle_paths.make_path(args[ARG_CONFIG] + ".conf") authStr = (ARG_AUTHSTR in args) and args[ARG_AUTHSTR] or "" # see if it's currently enabled. currStatus = stanzaStatusInternal({ARG_CONFIG : args[ARG_CONFIG], ARG_MODNAME : args[ARG_MODNAME], ARG_STANZA : stanza, ARG_AUTHSTR: authStr}, fromCLI) currEnabled = currStatus["enabled"] # get the local .conf file. don't use the stanzas given to us from "status", # because they're merged - we don't want to write out all the merged settings. # btw, readConfFile checks to see if the path exists and does the right thing. confStanzas = comm.readConfFile(confFile) if currEnabled: # then disable it returnDict["restartRequired"] = True # create the stanza if it's not in the .conf already (could be on via default bundle) if not stanza in confStanzas: confStanzas[stanza] = {} # and make sure we set the disabled key in local to be true. confStanzas[stanza][KEY_DISABLED] = "true" stanzaXml = comm.flatDictToXML(confStanzas[stanza]) # the following is now always true: # in order to support "splunk set deploy-poll", we allow this stuff to also write to the local filesystem. logger.debug("Attempting to disable module via local filesystem.") comm.writeConfFile(confFile, confStanzas) if not currEnabled: logger.info("%s is already disabled." % args[ARG_MODNAME]) else: logger.info("%s disabled." % args[ARG_MODNAME]) return returnDict
def stanzaEnable(args, fromCLI): """ Enables a given stanza in a given conf file. """ paramsReq = (ARG_CONFIG, ARG_MODNAME, ARG_STANZA) paramsOpt = (ARG_AUTHSTR, ARG_USEFS) comm.validateArgs(paramsReq, paramsOpt, args) returnDict = {} authStr = (ARG_AUTHSTR in args) and args[ARG_AUTHSTR] or "" stanza = args[ARG_STANZA] confFile = bundle_paths.make_path(args[ARG_CONFIG] + ".conf") currStatus = stanzaStatusInternal({ARG_CONFIG : args[ARG_CONFIG], ARG_MODNAME : args[ARG_MODNAME], ARG_STANZA : stanza, ARG_AUTHSTR: authStr}, fromCLI) currEnabled = currStatus["enabled"] # get the local .conf file. don't use the stanzas given to us from "status", # because they're merged - we don't want to write out all the merged settings. # btw, readConfFile checks to see if the path exists and does the right thing. confStanzas = comm.readConfFile(confFile) if not currEnabled: # then enable it returnDict["restartRequired"] = True # create the stanza if it's not in the .conf already (if it was never enabled) if not stanza in confStanzas: confStanzas[stanza] = {} # at this point the only way for it to be disabled is for the disabled key to be true. # set it false regardless of whether or not it exists. confStanzas[stanza][KEY_DISABLED] = "false" stanzaXml = comm.flatDictToXML(confStanzas[stanza]) # the following is now always true: # if applicable, just write to the local FS (used by splunk set deploy-poll). logger.debug("Attempting to enable module via local filesystem.") comm.writeConfFile(confFile, confStanzas) if currEnabled: logger.info("%s is already enabled." % args[ARG_MODNAME]) else: logger.info("%s enabled." % args[ARG_MODNAME]) return returnDict
#### ## global consts in this module #### CONFIG_SERVER = "server" CONFIG_WEB = "web" STANZA_SSL = "sslConfig" STANZA_SETTINGS = "settings" _searchConfigPath = os.path.join("myinstall", "search.xml") _userConfigPath = os.path.join("myinstall", "search.user.xml") fullSearchConfig = os.path.join(comm.splunk_home, "etc", _searchConfigPath) userSearchConfig = os.path.join(comm.splunk_home, "etc", _userConfigPath) fullSplunkdConfig = os.path.join(comm.splunk_home, "etc", "myinstall", "splunkd.xml") fullServerConfig = bundle_paths.make_path("server.conf") fullWebConfig = bundle_paths.make_path("web.conf") # regex's for input validation _URLpattern = '^http[s]?://[\w\S\-\./]*(:[\d]+)?[\w\S\-\./%~\(\)]*$' _namespacepattern = '^[\w\S\-\.:/%~\(\)]+$' _truefalsepattern = '[(true)(false)10]?' webSettingsStanza = "settings" serverGeneralStanza = "general" prettyNameMap = {"uiversion": "Web version", "sslport": "SSL Web port"} # map of command line params to xml tags tagmap = { 'mgmturl': 'managerURL', 'mgmtns': 'managerNamespace',
#### ## global consts in this module #### CONFIG_SERVER = "server" CONFIG_WEB = "web" STANZA_SSL = "sslConfig" STANZA_SETTINGS = "settings" _searchConfigPath = os.path.join("myinstall", "search.xml") _userConfigPath = os.path.join("myinstall", "search.user.xml") fullSearchConfig = os.path.join(comm.splunk_home, "etc", _searchConfigPath) userSearchConfig = os.path.join(comm.splunk_home, "etc", _userConfigPath) fullSplunkdConfig = os.path.join(comm.splunk_home, "etc", "myinstall", "splunkd.xml") fullServerConfig = bundle_paths.make_path("server.conf") fullWebConfig = bundle_paths.make_path("web.conf") # regex's for input validation _URLpattern = '^http[s]?://[\w\S\-\./]*(:[\d]+)?[\w\S\-\./%~\(\)]*$' _namespacepattern = '^[\w\S\-\.:/%~\(\)]+$' _truefalsepattern = '[(true)(false)10]?' webSettingsStanza = "settings" serverGeneralStanza = "general" prettyNameMap = {"uiversion" : "Web version", "sslport" : "SSL Web port"} # map of command line params to xml tags tagmap = { 'mgmturl' : 'managerURL', 'mgmtns' : 'managerNamespace',