コード例 #1
0
def setLocalMgmtPort(args, fromCLI):
    paramReq = ("port", )
    paramOpt = ()
    comm.validateArgs(paramReq, paramOpt, args)
    if fromCLI:
        validate.checkPortNum("port", args["port"])

    retDict = {}
    host = "localhost"
    key = "mgmtHostPort"
    currSetts = comm.readConfFile(fullWebConfig)

    if not webSettingsStanza in currSetts:
        currSetts[webSettingsStanza] = {}
    if key in currSetts[webSettingsStanza]:
        try:
            # this expects the uri as "blah:8000" - or just "a:b", really.
            host, oldPortWhichIsGarbage = currSetts[webSettingsStanza][
                key].split(":", 1)
        except ValueError:
            pass  # leaves localhost value from above

    currSetts[webSettingsStanza][key] = "%s:%s" % (host, args["port"])
    comm.writeConfFile(fullWebConfig, currSetts)
    return retDict
コード例 #2
0
 def _merger(self, src, dst, dryRun):
     try:
         if dryRun:
             # Be less verbose for dry runs. More detailed information is
             # likely to be misleading because of dry run limitations.
             logger.notice(lit("INFO_MIGRATE_MOVE_DRYRUN__S") % src)
             return
         root, ext = os.path.splitext(src)
         if ext == ".conf":
             if os.path.lexists(dst):
                 # Combine src and dst confs; don't override anything in dst.
                 combinedConf = comm.readConfFile(src)
                 dstConf = comm.readConfFile(dst)
                 for k in dstConf.keys():
                     if combinedConf.has_key(k):
                         combinedConf[k].update(dstConf[k])
                     else:
                         combinedConf[k] = dstConf[k]
                 # In case we don't have permission to truncate the
                 # file, just remove it preemptively.
                 safe_remove(dst)
                 logger.notice(
                     lit("INFO_MIGRATE_MERGE_CONF__S_S") % (src, dst))
                 comm.writeConfFile(dst, combinedConf)
             else:
                 comm.copyItem(src, dst)
         else:
             if os.path.lexists(dst):
                 logger.notice(
                     lit("INFO_MIGRATE_IGNORE_DUP__S_S") % (src, dst))
             else:
                 comm.copyItem(src, dst)
     except Exception, e:
         logger.warn(lit("WARN_MIGRATE_NO_CREATE__S") % dst)
         logger.exception(e)
コード例 #3
0
ファイル: bundle_paths.py プロジェクト: DRArpitha/splunk
 def _merger(self, src, dst, dryRun):
     try:
         if dryRun:
             # Be less verbose for dry runs. More detailed information is
             # likely to be misleading because of dry run limitations.
             logger.notice(lit("INFO_MIGRATE_MOVE_DRYRUN__S") % src)
             return
         root, ext = os.path.splitext(src)
         if ext == ".conf":
             if os.path.lexists(dst):
                 # Combine src and dst confs; don't override anything in dst.
                 combinedConf = comm.readConfFile(src)
                 dstConf = comm.readConfFile(dst)
                 for k in dstConf.keys():
                     if combinedConf.has_key(k):
                         combinedConf[k].update(dstConf[k])
                     else:
                         combinedConf[k] = dstConf[k]
                 # In case we don't have permission to truncate the
                 # file, just remove it preemptively.
                 safe_remove(dst)
                 logger.notice(lit("INFO_MIGRATE_MERGE_CONF__S_S") % (src, dst))
                 comm.writeConfFile(dst, combinedConf)
             else:
                 comm.copyItem(src, dst)
         else:
             if os.path.lexists(dst):
                 logger.notice(lit("INFO_MIGRATE_IGNORE_DUP__S_S") % (src, dst))
             else:
                 comm.copyItem(src, dst)
     except Exception, e:
         logger.warn(lit("WARN_MIGRATE_NO_CREATE__S") % dst)
         logger.exception(e)
コード例 #4
0
 def update_config(self, conf, stanza_dict):
     """
     Writes dictionary of dicts to local app context
     :param conf: Splunk conf file name
     :param stanza_dict: dictionary of dicts
     :return: True
     """
     conf = "%s.conf" % conf
     localconfpath = os.path.join(self.dir, "local", conf)
     cli.writeConfFile(localconfpath, stanza_dict)
     return True
コード例 #5
0
ファイル: deploy.py プロジェクト: DRArpitha/splunk
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
コード例 #6
0
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
コード例 #7
0
 def update_config(self, conf, stanzaDict):
     """
     Writes dictionary of dicts to local app context
     :param conf: Splunk conf file name
     :param stanzaDict: dictionary of dicts
     :return: True
     """
     conf = "%s.conf" % conf
     localconfpath = os.path.join(self.dir, "local", conf)
     cli.writeConfFile(localconfpath, stanzaDict)
     return True
コード例 #8
0
def setLocalName(args, fromCLI):
  paramReq = ("name",)
  paramOpt = ()
  comm.validateArgs(paramReq, paramOpt, args)
  name = args["name"]
  if name.count(" ") + name.count(":") > 0:
    raise ArgError, "Name '%s' is invalid.  Names cannot contain spaces or colons." % name

  currSetts = comm.readConfFile(fullServerConfig)
  if not serverGeneralStanza in currSetts:
    currSetts[serverGeneralStanza] = {}
  currSetts[serverGeneralStanza]["serverName"] = name
  comm.writeConfFile(fullServerConfig, currSetts)
  return {}
コード例 #9
0
def setLocalName(args, fromCLI):
    paramReq = ("name", )
    paramOpt = ()
    comm.validateArgs(paramReq, paramOpt, args)
    name = args["name"]
    if name.count(" ") + name.count(":") > 0:
        raise ArgError, "Name '%s' is invalid.  Names cannot contain spaces or colons." % name

    currSetts = comm.readConfFile(fullServerConfig)
    if not serverGeneralStanza in currSetts:
        currSetts[serverGeneralStanza] = {}
    currSetts[serverGeneralStanza]["serverName"] = name
    comm.writeConfFile(fullServerConfig, currSetts)
    return {}
コード例 #10
0
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
コード例 #11
0
def setLocalHttp(args, fromCLI):
    paramReq = ("port", )
    paramOpt = ()
    comm.validateArgs(paramReq, paramOpt, args)
    if fromCLI:
        validate.checkPortNum("port", args["port"])

    retDict = {}
    key = "httpport"
    currSetts = comm.readConfFile(fullWebConfig)

    if not webSettingsStanza in currSetts:
        currSetts[webSettingsStanza] = {}
    currSetts[webSettingsStanza][key] = args["port"]

    comm.writeConfFile(fullWebConfig, currSetts)
    return retDict
コード例 #12
0
def setLocalHttp(args, fromCLI):
  paramReq = ("port",)
  paramOpt = ()
  comm.validateArgs(paramReq, paramOpt, args)
  if fromCLI:
    validate.checkPortNum("port", args["port"])

  retDict = {}
  key = "httpport"
  currSetts = comm.readConfFile(fullWebConfig)

  if not webSettingsStanza in currSetts:
    currSetts[webSettingsStanza] = {}
  currSetts[webSettingsStanza][key] = args["port"]

  comm.writeConfFile(fullWebConfig, currSetts)
  return retDict
コード例 #13
0
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
コード例 #14
0
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
コード例 #15
0
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
コード例 #16
0
def setLocalMgmtPort(args, fromCLI):
  paramReq = ("port",)
  paramOpt = ()
  comm.validateArgs(paramReq, paramOpt, args)
  if fromCLI:
    validate.checkPortNum("port", args["port"])

  retDict = {}
  host = "localhost"
  key  = "mgmtHostPort"
  currSetts = comm.readConfFile(fullWebConfig)

  if not webSettingsStanza in currSetts:
    currSetts[webSettingsStanza] = {}
  if key in currSetts[webSettingsStanza]:
    try:
      # this expects the uri as "blah:8000" - or just "a:b", really.
      host, oldPortWhichIsGarbage = currSetts[webSettingsStanza][key].split(":", 1)
    except ValueError:
      pass # leaves localhost value from above

  currSetts[webSettingsStanza][key] = "%s:%s" % (host, args["port"])
  comm.writeConfFile(fullWebConfig, currSetts)
  return retDict
コード例 #17
0
 def _commit_metadata(self, path):
     maybe_makedirs(os.path.dirname(path), True)
     comm.writeConfFile(path, self._dict)
コード例 #18
0
            continue
        new_stanza = migrateFieldActionStanza(parsed_infile[stanza])
        if new_stanza != None:
            output[stanza] = new_stanza
    
    outdir = os.path.abspath(os.path.dirname(outfile))
    try:
        os.makedirs(outdir, 0755)
    except OSError, e:
        if e.errno == errno.EEXIST:
            pass
        else:
            logger.warn("Could not create the directory specified in '%s'." % outfile)
            raise

    comm.writeConfFile(outfile, output)
    return
    
def migFieldActions_4_1(infile, outfile, isDryRun=False):
    '''
    THIS FUNCTION SHOULD NOT BE CALLED MANUALLY. IT IS USED BY THE
    MIGRATION SCRIPT.
    '''
    migrateFieldActions(infile, outfile)
    comm.removeItem(infile, isDryRun)

if __name__ == '__main__':


    def run_tests():
        import unittest
コード例 #19
0
ファイル: bundle_paths.py プロジェクト: DRArpitha/splunk
 def _commit_metadata(self, path):
     maybe_makedirs(os.path.dirname(path), True)
     comm.writeConfFile(path, self._dict)