Beispiel #1
0
def migrate_bundles(args, fromCLI):
    ARG_DRYRUN = "dry-run"
    ARG_NAME = "name"
    comm.validateArgs((), (ARG_NAME, ARG_DRYRUN), args)
    isDryRun = comm.getBoolValue(ARG_DRYRUN, args.get(ARG_DRYRUN, "false"))
    name = args.get(ARG_NAME)
    found = False
    logger.info(lit("INFO_MIGRATE_START__S") % name)
    for b in bundles_iterator(True):
        if b.is_legacy() and ((name is None) or (name == b.name())):
            b.migrate(isDryRun)
            found = True
    if name and (not found):
        raise cex.ArgError, "Cannot find a legacy bundle named '%s'." % name
    else:
        logger.info(lit("INFO_MIGRATE_END__S") % name)
Beispiel #2
0
def migrate_bundles(args, fromCLI):
    ARG_DRYRUN = "dry-run"
    ARG_NAME = "name"
    comm.validateArgs(( ), (ARG_NAME, ARG_DRYRUN), args)
    isDryRun = comm.getBoolValue(ARG_DRYRUN, args.get(ARG_DRYRUN, "false"))
    name = args.get(ARG_NAME)
    found = False
    logger.info(lit("INFO_MIGRATE_START__S") % name)
    for b in bundles_iterator(True):
        if b.is_legacy() and ((name is None) or (name == b.name())):
            b.migrate(isDryRun)
            found = True
    if name and (not found):
        raise cex.ArgError, "Cannot find a legacy bundle named '%s'." % name
    else:
        logger.info(lit("INFO_MIGRATE_END__S") % name)
def isDisabledIndex(dbDict):
  return "disabled" in dbDict and comm.getBoolValue("disabled", dbDict["disabled"])
Beispiel #4
0
def firstTimeRun(args, fromCLI):
    """
  All of our first time run checks that used to happen in the former bin/splunk shell script.
  Does any number of things, such as config migration, directory validation, and so on.  For
  the most up to date info, read the code.  It tends to be fairly well documented.
  """

    paramReq = (
        ARG_DRYRUN,
        ARG_FRESHINST,
    )
    paramOpt = (ARG_LOGFILE, )
    comm.validateArgs(paramReq, paramOpt, args)

    isFirstInstall = comm.getBoolValue(ARG_FRESHINST, args[ARG_FRESHINST])
    isDryRun = comm.getBoolValue(ARG_DRYRUN, args[ARG_DRYRUN])
    retDict = {}

    # ...arg parsing done now.

    # NOTE:
    # none of the changes that are made in this function are subjected to isDryRun.
    # these things just have to be done - they're not considered to be migration.

    ##### if user doesn't have a ldap.conf, put our default in its place.
    if not os.path.exists(migration.PATH_LDAP_CONF):
        comm.copyItem(migration.PATH_LDAP_CONF_DEF, migration.PATH_LDAP_CONF)

    if not os.path.exists(PATH_AUDIT_PRIV_KEY) and not os.path.exists(
            PATH_AUDIT_PUB_KEY):
        kCmd = ["splunk", "createssl", "audit-keys"]
        kPriv, kPub, kDir = PATH_AUDIT_PRIV_KEY, PATH_AUDIT_PUB_KEY, PATH_AUDIT_KEY_DIR
        retCode = comm.runAndLog(kCmd + ["-p", kPriv, "-k", kPub, "-d", kDir])
        if 0 != retCode:
            raise cex.FilePath, "Could not create audit keys (returned %d)." % retCode

    try:
        keyScript = comm.getConfKeyValue("distsearch", "tokenExchKeys",
                                         "genKeyScript")
        keyCmdList = [
            os.path.expandvars(x.strip()) for x in keyScript.split(",")
            if len(x) > 0
        ]  # a,b,,d -> [a,b,d]
        pubFilename = comm.getConfKeyValue("distsearch", "tokenExchKeys",
                                           "publicKey")
        privateFilename = comm.getConfKeyValue("distsearch", "tokenExchKeys",
                                               "privateKey")
        certDir = comm.getConfKeyValue("distsearch", "tokenExchKeys",
                                       "certDir")
        certDir = os.path.expandvars(certDir)
        privateFilename = os.path.join(certDir, privateFilename)
        pubFilename = os.path.join(certDir, pubFilename)
        if not (os.path.exists(os.path.join(certDir, privateFilename))
                or os.path.exists(os.path.join(certDir, pubFilename))):
            cmdList = keyCmdList + [
                "-p", privateFilename, "-k", pubFilename, "-d", certDir
            ]
            success = comm.runAndLog(cmdList) == 0
            if not success:
                logger.warn("Unable to generate distributed search keys.")
                #TK mgn 06/19/09
                raise cex.FilePath, "Unable to generate distributed search keys."  #TK mgn 06/19/09
    except:
        logger.warn("Unable to generate distributed search keys.")
        #TK mgn 06/19/09
        raise

    if isFirstInstall:
        ##### if user doesn't have a ui modules dir, put our default in its place. only run this in this block - otherwise,
        #     in an upgrade, we run the same code during migration and show an incorrect warning ("oh noes dir is missing").
        if not os.path.exists(migration.PATH_UI_MOD_ACTIVE):
            comm.moveItem(migration.PATH_UI_MOD_NEW,
                          migration.PATH_UI_MOD_ACTIVE)
    ##### we're in an upgrade situation.
    else:
        ##### now do the actual migration (or fake it, if the user wants).
        #     upon faking, this function will throw an exception.
        if not ARG_LOGFILE in args:
            raise cex.ArgError, "Cannot migrate without the '%s' parameter." % ARG_LOGFILE
        migration.autoMigrate(args[ARG_LOGFILE], isDryRun)

    ##### FTR succeeded.  johnvey's never gonna have eggs. T_T

    # --- done w/ FTR, now i can has bucket?? ---
    return retDict
Beispiel #5
0
def firstTimeRun(args, fromCLI):
  """
  All of our first time run checks that used to happen in the former bin/splunk shell script.
  Does any number of things, such as config migration, directory validation, and so on.  For
  the most up to date info, read the code.  It tends to be fairly well documented.
  """

  paramReq = (ARG_DRYRUN, ARG_FRESHINST,)
  paramOpt = (ARG_LOGFILE,)
  comm.validateArgs(paramReq, paramOpt, args)

  isFirstInstall = comm.getBoolValue(ARG_FRESHINST, args[ARG_FRESHINST])
  isDryRun = comm.getBoolValue(ARG_DRYRUN, args[ARG_DRYRUN])
  retDict  = {}

  # ...arg parsing done now.

  # NOTE:
  # none of the changes that are made in this function are subjected to isDryRun.
  # these things just have to be done - they're not considered to be migration.

  ##### if user doesn't have a ldap.conf, put our default in its place.
  if not os.path.exists(migration.PATH_LDAP_CONF):
    comm.copyItem(migration.PATH_LDAP_CONF_DEF, migration.PATH_LDAP_CONF)

  if not os.path.exists(PATH_AUDIT_PRIV_KEY) and not os.path.exists(PATH_AUDIT_PUB_KEY):
    kCmd = ["splunk", "createssl", "audit-keys"]
    kPriv, kPub, kDir = PATH_AUDIT_PRIV_KEY, PATH_AUDIT_PUB_KEY, PATH_AUDIT_KEY_DIR
    retCode = comm.runAndLog(kCmd + ["-p", kPriv, "-k", kPub, "-d", kDir])
    if 0 != retCode:
      raise cex.FilePath, "Could not create audit keys (returned %d)." % retCode

  try:    
    keyScript = comm.getConfKeyValue("distsearch", "tokenExchKeys", "genKeyScript" );
    keyCmdList = [os.path.expandvars(x.strip()) for x in keyScript.split(",") if len(x) > 0] # a,b,,d -> [a,b,d]
    pubFilename = comm.getConfKeyValue("distsearch", "tokenExchKeys", "publicKey" );
    privateFilename = comm.getConfKeyValue("distsearch", "tokenExchKeys", "privateKey" );
    certDir = comm.getConfKeyValue("distsearch", "tokenExchKeys", "certDir" )
    certDir = os.path.expandvars( certDir )
    privateFilename = os.path.join( certDir,privateFilename )
    pubFilename = os.path.join( certDir, pubFilename )
    if not ( os.path.exists( os.path.join( certDir,privateFilename ) ) or os.path.exists( os.path.join( certDir, pubFilename ) ) ):
      cmdList = keyCmdList + [ "-p", privateFilename, "-k", pubFilename,"-d", certDir ]
      success = comm.runAndLog( cmdList ) == 0
      if not success:
        logger.warn("Unable to generate distributed search keys."); #TK mgn 06/19/09
        raise cex.FilePath, "Unable to generate distributed search keys." #TK mgn 06/19/09
  except:
    logger.warn("Unable to generate distributed search keys."); #TK mgn 06/19/09
    raise 

  if isFirstInstall:
    ##### if user doesn't have a ui modules dir, put our default in its place. only run this in this block - otherwise,
    #     in an upgrade, we run the same code during migration and show an incorrect warning ("oh noes dir is missing").
    if not os.path.exists(migration.PATH_UI_MOD_ACTIVE):
      comm.moveItem(migration.PATH_UI_MOD_NEW, migration.PATH_UI_MOD_ACTIVE)
  ##### we're in an upgrade situation.
  else:
    ##### now do the actual migration (or fake it, if the user wants).
    #     upon faking, this function will throw an exception.
    if not ARG_LOGFILE in args:
      raise cex.ArgError, "Cannot migrate without the '%s' parameter." % ARG_LOGFILE
    migration.autoMigrate(args[ARG_LOGFILE], isDryRun)


  ##### FTR succeeded.  johnvey's never gonna have eggs. T_T

  # --- done w/ FTR, now i can has bucket?? ---
  return retDict