Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- On error Resume Next
- Const ForReading = 1
- ' update this version each time you update elements of config items dictionary
- dim strVersionTag :: strVersionTag = "# log-local.cfg v1.5"
- ' determine path to SplunkHome to handle x32 universal forwarder on x64 platform
- dim strSplunkHome :: strSplunkHome = left(wscript.scriptfullname,instr(1,ucase(wscript.scriptfullname),"\ETC\")-1)
- dim strDefault :: strDefault = strSplunkHome & "\etc\" & "log.cfg"
- dim strLocal :: strLocal = strSplunkHome & "\etc\" & "log-local.cfg"
- dim strComputerName :: strComputername = ucase(GetEnvironmentValue("Process","COMPUTERNAME"))
- ' if default log.cfg file does not exist, quit
- if CheckFileExists(strDefault) = False then
- wscript.echo now() & "," & strComputerName & "," & "FATAL" & "," & strDefault & " does not exist!"
- wscript.quit
- end if
- ' if local log.cfg file does not exist, create it from default instance
- if CheckFileExists(strLocal) = False then
- wscript.echo now() & "," & strComputerName & "," & "INFO" & "," & "Copied default config file to " & strLocal & "."
- call copyFile(strDefault,strLocal)
- end if
- ' check to see if local log file has already been updated to expected version
- If IsTagPresent(strLocal,strVersionTag) = True then
- ' configuration file already has logging level preferences, quit
- wscript.echo now() & "," & strComputerName & "," & "INFO" & "," & "Local config file already configured."
- wscript.quit
- else
- wscript.echo now() & "," & strComputerName & "," & "INFO" & "," & "Local config needs updating."
- ' read in dictionary of desired configurations
- Dim objDictionary
- Set objDictionary = CreateObject("Scripting.Dictionary")
- call LoadDesiredConfigs()
- ' enumerate lines in local log file and replace configurations as needed
- call SetConfig(strLocal,objDictionary)
- ' tag local log file with version number to skip changes on next pass if already configured.
- call SetVersion(strLocal,strVersionTag)
- wscript.echo now() & "," & strComputerName & "," & "INFO" & "," & "Tagged " & strLocal & " with " & strVersionTag & "."
- end if
- Sub LoadDesiredConfigs()
- ' JIRA XXX - Reduce size of log files from 25m to 5m [done]
- objDictionary.Add "appender.A1.maxFileSize","5000000"
- objDictionary.Add "appender.license_usage.maxFileSize","5000000"
- objDictionary.Add "appender.A4.maxFileSize","5000000"
- objDictionary.Add "appender.metrics.maxFileSize","5000000"
- objDictionary.Add "appender.audittrail.maxFileSize","5000000"
- objDictionary.Add "appender.licenseaudit.maxFileSize","5000000"
- objDictionary.Add "appender.accesslog.maxFileSize","5000000"
- objDictionary.Add "appender.scheduler.maxFileSize","5000000"
- objDictionary.Add "appender.remotesearches.maxFileSize","5000000"
- ' JIRA XXX - Reduce count of log files to retain from 5 to 2 [done]
- objDictionary.Add "appender.A1.maxBackupIndex","2"
- objDictionary.Add "appender.license_usage.maxBackupIndex","2"
- objDictionary.Add "appender.A4.maxBackupIndex","2"
- objDictionary.Add "appender.metrics.maxBackupIndex","2"
- objDictionary.Add "appender.audittrail.maxBackupIndex","2"
- objDictionary.Add "appender.licenseaudit.maxBackupIndex","2"
- objDictionary.Add "appender.accesslog.maxBackupIndex","2"
- objDictionary.Add "appender.scheduler.maxBackupIndex","2"
- objDictionary.Add "appender.remotesearches.maxBackupIndex","2"
- ' JIRA XXX - Reduce verbosity of logging for sub-critical components [done]
- objDictionary.Add "category.loader","INFO" 'Should always be INFO!
- objDictionary.Add "category.DC:DeploymentClient","INFO" 'Tough to decide between INFO and WARN. Matches in community!
- objDictionary.Add "category.HttpPubSubConnection","INFO" 'Useful for profiling missing or busy splunk web.
- objDictionary.Add "category.DC:PhonehomeThread","WARN" 'Tough to decide between INFO and WARN.
- objDictionary.Add "category.DC:UpdateServerclassHandler","WARN"
- objDictionary.Add "category.DeployedServerclass","WARN"
- objDictionary.Add "category.BatchReader","WARN"
- objDictionary.Add "category.ThruputProcessor","WARN"
- objDictionary.Add "category.DC:HandshakeReplyHandler","WARN"
- objDictionary.Add "category.ExecProcessor","WARN"
- objDictionary.Add "category.TailingProcessor","WARN"
- objDictionary.Add "category.PipelineComponent","WARN"
- objDictionary.Add "category.TcpOutputProc","WARN"
- objDictionary.Add "category.ModularInputs","WARN"
- objDictionary.Add "category.TcpInputProc","WARN"
- objDictionary.Add "category.TcpInputConfig","WARN"
- objDictionary.Add "category.IndexProcessor","WARN"
- objDictionary.Add "category.DS_DC_Common","WARN"
- objDictionary.Add "category.DeployedApplication","WARN"
- objDictionary.Add "category.ClusteringMgr","WARN"
- objDictionary.Add "category.SpecFiles","WARN"
- objDictionary.Add "category.LicenseMgr","WARN"
- objDictionary.Add "category.LMTracker","WARN"
- objDictionary.Add "category.LMSlaveInfo","WARN"
- objDictionary.Add "category.LMStackMgr","WARN"
- objDictionary.Add "category.LMConfig","WARN"
- objDictionary.Add "category.BundlesSetup","WARN"
- objDictionary.Add "category.ServerConfig","WARN"
- End Sub
- Function IsTagPresent(strLocal,strTagLine)
- IsTagPresent = False
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Dim arrLogFile()
- i = 0
- Set objTextFile = objFSO.OpenTextFile(strLocal, ForReading)
- Do Until objTextFile.AtEndOfStream
- Redim Preserve arrLogFile(i)
- arrLogFile(i) = objTextFile.ReadLine
- i = i + 1
- Loop
- objTextFile.Close
- for i=0 to ubound(arrLogFile)
- strNextLine = arrLogFile(i)
- if instr(1,strNextLine,strTagLine)=1 then
- IsTagPresent = True
- end if
- strLastLine = strNextLine
- next
- End Function
- Function SetVersion(strLocal,strTagLine)
- arrTagLine = split(strTagLine," ")
- strTagPrefix = arrTagLine(0) & " " & arrTagLine(1)
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Dim arrLogFile()
- i = 0
- Set objTextFile = objFSO.OpenTextFile(strLocal, ForReading)
- Do Until objTextFile.AtEndOfStream
- Redim Preserve arrLogFile(i)
- arrLogFile(i) = objTextFile.ReadLine
- i = i + 1
- Loop
- objTextFile.close
- objFSO.DeleteFile(strLocal)
- Set objTextFile = objFSO.CreateTextFile(strLocal, True)
- for i=0 to ubound(arrLogFile)
- strNextLine = arrLogFile(i)
- if instr(1,strNextLine,strTagPrefix)=1 or instr(1,strNextLine,"# log.cfg")=1 then
- objTextFile.WriteLine strTagLine
- else
- objTextFile.WriteLine strNextLine
- end if
- next'
- objTextFile.close
- End Function
- Function SetConfig(strLocal,objDictionary)
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- Dim arrLogFile()
- i = 0
- Set objTextFile = objFSO.OpenTextFile(strLocal, ForReading)
- Do Until objTextFile.AtEndOfStream
- Redim Preserve arrLogFile(i)
- arrLogFile(i) = objTextFile.ReadLine
- i = i + 1
- Loop
- objTextFile.close
- objFSO.DeleteFile(strLocal)
- Set objTextFile = objFSO.CreateTextFile(strLocal, True)
- for i=0 to ubound(arrLogFile)
- strNextLine = arrLogFile(i)
- colKeys = objDictionary.Keys
- for each strKey in colKeys
- if instr(1,ucase(strNextLine),ucase(strKey) & "=")<>0 then
- strBefore = strNextLine
- strNextLine = left(strNextLine,instr(1,strNextLine,"=")) & objDictionary.Item(strKey)
- strAfter = strNextLine
- if strBefore <> strAfter then
- ' wscript.echo "strBefore: " & strBefore
- ' wscript.echo "strAfter: " & strAfter
- wscript.echo now() & "," & strComputerName & "," & "INFO" & "," & "Set " & strAfter
- end if
- end if
- next
- objTextFile.WriteLine strNextLine
- next'
- objTextFile.close
- End Function
- Function CheckFileExists(strFile)
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- CheckFileExists = objFSO.FileExists(strFile)
- End Function
- Function CopyFile(strSourceFile,strDestFile)
- Const OverwriteExisting = TRUE
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- objFSO.CopyFile strSourceFile , strDestFile, OverwriteExisting
- End Function
- Function GetEnvironmentValue(strValueType,strValueName)
- ' value types include: System, User, Volatile, or Process
- Set WshShell = WScript.CreateObject("WScript.Shell")
- Set WshSysEnv = WshShell.Environment(strValueType)
- GetEnvironmentValue = WshSysEnv(strValueName)
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement