dim LogEnabled
LogEnabled = false
dim ManagedEntityId
ManagedEntityId = ""
Dim oAPI, oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
dim DebugEventSource
dim LogEventSource
dim LogSeverity
LogSeverity = LOGSEVERITY_INFO
DebugEventSource = "$Config/DebugEventSource$"
if instr(DebugEventSource,"$") then
LogEventSource = "Amalga"
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in DebugEventSource - $ not translated - " & DebugEventSource
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
else
LogEventSource = trim(DebugEventSource & "")
if (LogEventSource = "") then
LogEventSource = "Amalga"
LogEnabled = true
LogSeverity = LOGSEVERITY_WARN
WriteLine "missing DebugEventSource, defaulting to 'Amalga'"
LogEnabled = false
LogSeverity = LOGSEVERITY_INFO
end if
end if
Dim oArgs
Set oArgs = WScript.Arguments
DumpArgs(oArgs)
if (oArgs.Count <> EXPECTED_PARAM_COUNT) then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "invalid arg count: " & oArgs.Count & " expected " & EXPECTED_PARAM_COUNT
oArgs = cdate("invalid arg count") ''' intentionally crash
end if
ManagedEntityId = GetArg(oArgs(0))
dim DebugEnabled
DebugEnabled = "$Config/DebugEnabled$"
if instr(DebugEnabled,"$") then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in DebugEnabled - $ not translated - " & DebugEnabled
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if
DebugEnabled = trim(ucase(DebugEnabled & " "))
LogEnabled = (DebugEnabled = "TRUE")
dim FolderPath, UseReg, ThresholdValue, SubFolder
FolderPath = "$Config/FilePath$"
if instr(FolderPath,"$") then
cdate("unexpected error - macro subsitution did not happen")
end if
WriteLine "FolderPath: " & FolderPath
FolderPath = lcase(FolderPath & "")
UseReg = "$Config/PathIsARegKey$"
if instr(UseReg,"$") then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in UseReg - $ not translated - " & UseReg
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if
WriteLine "UseReg: " & UseReg
UseReg = lcase(trim(UseReg & " "))
UseReg = (UseReg = "true")
WriteLine "UseReg: " & UseReg
ThresholdValue = "$Config/ThresholdValue$"
if instr(ThresholdValue,"$") then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in ThresholdValue - $ not translated - " & ThresholdValue
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if
WriteLine "ThresholdValue: " & ThresholdValue
ThresholdValue = cint(ThresholdValue & "")
SubFolder = "$Config/SubFolder$"
if instr(ThresholdValue,"$") then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in SubFolder - $ not translated - " & SubFolder
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if
WriteLine "SubFolder: " & SubFolder
SubFolder = lcase(trim(SubFolder & " "))
if (UseReg) then
dim temp, pos, strKeyPath, strValueName
temp = FolderPath
pos = len(temp)
do while (pos > 0)
if (mid(temp,pos,1) = "\") then exit do
pos = pos - 1
loop
if pos = 0 then pos = len(temp) +1
strKeyPath = left(temp,pos-1) ''' no trailing backslash here
strValueName = mid(temp,pos+1)
dim oReg, strComputer, arrSubKeys, i, keyfound, arrValueNames, strValue
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
If oReg.EnumKey (HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames) = 0 Then
WriteLine("The registry path exists " & strKeyPath)
keyfound = true
Else
WriteLine("The HKLM registry path does not exist for " & strKeyPath & " assuming this is a file folder and continuing..." )
keyfound = false
end if
If (keyfound) Then
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
FolderPath = strValue & ""
else
FolderPath = ""
end if
end if
WriteLine "FolderPath: " & FolderPath
if (SubFolder <> "" and FolderPath <> "") then
if (right(FolderPath,1) <> "\") then
FolderPath = FolderPath & "\" & SubFolder
else
FolderPath = FolderPath & SubFolder
end if
end if
WriteLine "FolderPath: " & FolderPath
dim fso, Files, Count
Count = 0
Set fso = CreateObject("Scripting.FileSystemObject")
on error resume next
Set Files = Fso.GetFolder(FolderPath).Files
if err.number <> 0 then Count = -1
Count = Files.Count
if err.number <> 0 then Count = -1
on error goto 0
wscript.echo "File count: " & Count
dim tempResult
if (Count = -1) then
tempResult = "$Config/StateWhenFolderMissing$"
if instr(tempResult,"$") then cdate("unexpected error - macro subsitution did not happen")
Call oBag.AddValue("result", tempResult)
Call oBag.AddValue("details","MISSING_FOLDER")
Writeline "MISSING_FOLDER - returning: " & tempResult
elseif (Count >= ThresholdValue) then
Call oBag.AddValue("result", "GE_THRESHOLD")
Writeline "GE_THRESHOLD"
else
Call oBag.AddValue("result", "LT_THRESHOLD")
Writeline "LT_THRESHOLD"
end if
Call oBag.AddValue("ThresholdValue", ThresholdValue)
Call oBag.AddValue("Count", Count)
Call oBag.AddValue("PathIsARegKey",UseReg)
if (UseReg) then
tempResult = "$Config/FilePath$"
if instr(tempResult,"$") then cdate("unexpected error - macro subsitution did not happen")
Call oBag.AddValue("RegLookup", tempResult)
end if
if (SubFolder <> "") then
Call oBag.AddValue("Appended SubFolder",SubFolder)
end if
Call oBag.AddValue("FolderPath",FolderPath)
sub DumpArgs(Args)
dim i, status
WriteLine("Dumping args as passed in.")
WriteLine("Note: If you see quotes, they are actually part of the argument literal.")
dim untranslated
untranslated = false
status = "Args: "
for i = 0 to Args.Count - 1
status = status & Args(i) & " "
WriteLine(i & ": " & Args(i))
if (instr(Args(i),"$") > 0) then
untranslated = true
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine("ERROR: untranslated $ encountered at arg " & i & ": " & Args(i))
end if
next
if (untranslated) then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine("ERROR: one or more untranslated $ args encountered, quitting.")
status = cdate("ERROR: one or more untranslated $ args encountered, quitting.") ''' intentionally crash here
end if
end sub
'////////////////////////////
function GetArg(quotedarg)
dim s
s = quotedarg
if s <> "" then
if mid(s,1,1) = """" then
s = mid(s,2, len(s)-1)
end if
if mid(s,len(s),1) = """" then
s = mid(s, 1, len(s)-1)
end if
end if
GetArg = s
end function
'////////////////////////////
sub WriteLine(in_line)
dim s
s = vbcrlf & "ID: " & ManagedEntityId & vbcrlf & WRITELINEHEADER & vbcrlf & vbcrlf & in_line
if (LogEnabled) then
wscript.echo in_line
call oAPI.LogScriptEvent(LogEventSource, 100, LogSeverity, s)
end if
end sub
'////////////////////////////
function NormalizeDate(x)
dim retval, i, L, c
L = len(x)
for i = 1 to L
c = ucase(mid(x,i,1))
if (instr("/:AMP ",c)=0) then
retval = retval & c
end if
next