Exemplo n.º 1
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
Exemplo n.º 2
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
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