📄 staflog.rxp
字号:
else if totalonly then logdata = selcount /* Only want total count */ else if last > '' then call ProcessLastRequest /* Only want last x */ else logdata = logdata || tmplogdata rc = MakeSTAFResult(STAFError.!Ok, logdata) /* Format output buffer */ end end else rc = MakeSTAFResult(STAFError.!FileOpenError, errorBuffer) if logcopied = 1 then call SysFileDelete copyfile end when type = "LOG" then do if trustlevel < 3 then RETURN MakeSTAFResult(STAFError.!AccessDenied, , STAFError.!AccessDenied.!text) if rmtmachine > '' then do /* Determine the actual remote machine name (short or long) */ STAFRC = STAFSubmit("LOCAL", "MISC", "MACHINE "rmtmachine) if STAFRC = 0 then rmtmachine = STAFResult origMachine = rmtmachine origHandle = OptionValue("RMTHANDLE") origName = OptionValue("RMTNAME") end call ValidateLogInput /* Validate required level input */ call SetDirStruct origMachine origHandle name = OptionValue("NAME") rc = CreatePath(logdir, filesep) /* Check|create directory(s) */ if rc = STAFError.!Ok then do status = FileStatus(infile, maxretry, "write") /* Make sure file READY */ if status \= 2 then do options "NOEXMODE NOETMODE" rc = charout(infile, d2c(latestlevel,1) || d2c(date('S'),4) || , d2c(time('S'),3) || d2c(x2d(b2x(level)),4) || d2c(totlen,4) || , origMachine || fsep || origHandle || fsep || origName || fsep || message) options "EXMODE ETMODE" if rc = STAFError.!Ok then call STAFExit MakeSTAFResult(STAFError.!Ok) else rc = MakeSTAFResult(STAFError.!FileWriteError, , STAFError.!FileWriteError.!text": "infile) call stream infile, "c", "close" end else rc = MakeSTAFResult(STAFError.!FileOpenError, errorBuffer) end else do errorBuffer = errorMakeDir.!text || logdir rc = MakeSTAFResult(STAFError.!FileOpenError, errorBuffer) end end when type = "LIST" then do if trustlevel < 2 then call STAFExit MakeSTAFResult(STAFError.!AccessDenied, , STAFError.!AccessDenied.!text) call SetDirStruct ResolveVariable(optionValue("MACHINE")) , ResolveVariable(optionValue("HANDLE")) if optionTimes("MACHINES") > 0 | optionTimes("HANDLES") > 0 then do listfileopts = "DT" listdir = logdir || filesep || "*" end else do listfileopts = "FST" listdir = logdir||filesep||"*"||ext end call SysFileTree listdir, stem, listfileopts if stem.0 = 0 then do if optionTimes("MACHINES") > 0 then text = "No machine logs found" else if optionTimes("HANDLES") > 0 then text = "No handle logs found" else if optionTimes("MACHINE") > 0 then text = "No global machine logs found" else text = "No global logs found" rc = MakeSTAFResult(STAFError.!FileOpenError, text": "listdir) end else do rc = MakeSTAFResult(STAFError.!Ok) do i = 1 to stem.0 parse var stem.i listdatetime listsize . listfile listfirst = lastpos(filesep,listfile) + 1 if optionTimes("MACHINES") > 0 | optionTimes("HANDLES") > 0 then do listlength = length(listfile) - listfirst + 1 listrest = linesep listfile = substr(listfile, listfirst, listlength) end else do listlength = lastpos('.',listfile) - listfirst listrest = MakeStandardDate(substr(listdatetime,4,2)|| , substr(listdatetime,7,2)substr(listdatetime,1,2))||"-"|| , substr(listdatetime,10,2)||":"||substr(listdatetime,13,2)|| , ":00 Size="||listsize||linesep listfile = substr(substr(listfile, listfirst, listlength),1,40,'.') end rc = rc||listfile||" "||listrest end end end when type = "DELETE" then do if trustlevel < 4 then RETURN MakeSTAFResult(STAFError.!AccessDenied, , STAFError.!AccessDenied.!text) call SetDirStruct ResolveVariable(optionValue("MACHINE")) , ResolveVariable(optionValue("HANDLE")) rc = SysFileDelete(infile) if rc = STAFError.!Ok then rc = MakeSTAFResult(STAFError.!Ok) else rc = MakeSTAFResult(STAFError.!FileDeleteError, , STAFError.!FileDeleteError.!text": "infile" (rc="rc")") end end call STAFUnRegister RETURN rc/******************************************************************************//* Function Definitions *//******************************************************************************//******************************************************************************//* CheckRange - Determine if a log record meets the date/time criteria. *//* Arguments: nothing *//* Returns : 0 if no data found *//* 1 if record meets date/time criteria *//* 2 if record is past BEFORE and TO criteria *//******************************************************************************/CheckRange: /* FROM date/time check */ if checkdate.1 > '' then if ldate < checkdate.1 then return 0 else if ldate = checkdate.1 then if checktime.1 > '' then if ltime < checktime.1 then return 0 else nop else nop else nop else if checktime.1 > '' then if ltime < checktime.1 then return 0 /* AFTER date/time check */ if checkdate.2 > '' then if ldate < checkdate.2 then return 0 else if ldate <= checkdate.2 then if checktime.2 > '' then if ltime <= checktime.2 then return 0 else nop else return 0 else nop else if checktime.2 > '' then if ltime <= checktime.2 then return 0 /* TO date/time check */ if checkdate.3 > '' then if ldate > checkdate.3 then return 2 else if ldate = checkdate.3 then if checktime.3 > '' then if ltime > checktime.3 then return 0 else nop else nop else nop else if checktime.3 > '' then if ltime > checktime.3 then return 2 /* BEFORE date/time check */ if checkdate.4 > '' then if ldate > checkdate.4 then return 2 else if ldate = checkdate.4 then if checktime.4 > '' then if ltime >= checktime.4 then return 0 else nop else return 0 else nop else if checktime.4 > '' then if ltime >= checktime.4 then return 2return 1/******************************************************************************//* InitializeLogParser - Initial the parser options for each request type. *//* Arguments: none *//* Returns : none if ok *//* exits if invalid options specified *//******************************************************************************/InitializeLogParser: /* Initial the parser options for each request type */ call InitParser call AddOptionGroup "HELP LOG QUERY LIST DELETE PURGE", 1, 1 call AddOption "RMTMACHINE", 1, "YES" select when type = "QUERY" | type = "PURGE" then do call AddOption "QUERY", 1, "NO" call AddOption "PURGE", 1, "NO" call AddOption "CONFIRM", 1, "NO" call AddOptionNeed "PURGE", "CONFIRM" call AddOption "GLOBAL", 1, "NO" call AddOption "MACHINE", 1, "YES" call AddOption "HANDLE", 1, "YES" call AddOptionGroup "GLOBAL MACHINE", 1, 1 call AddOptionNeed "HANDLE", "MACHINE" call AddOption "LOGNAME", 1, "YES" call AddOptionNeed "QUERY", "LOGNAME" call AddOptionNeed "PURGE", "LOGNAME" call AddOption "QMACHINE", 0, "YES" call AddOption "QHANDLE", 0, "YES" call AddOption "NAME", 0, "YES" call AddOption "FIRST", 1, "YES" call AddOption "LAST", 1, "YES" call AddOption "TOTAL", 1, "NO" call AddOption "STATS", 1, "NO" call AddOptionGroup "FIRST LAST TOTAL STATS", 0, 1 call AddOption "CONTAINS", 0, "YES" call AddOption "LEVELBITSTRING", 1, "NO" call AddOption "LEVELMASK", 1, "YES" call AddOption "FROM", 1, "YES" call AddOption "AFTER", 1, "YES" call AddOption "TO", 1, "YES" call AddOption "BEFORE", 1, "YES" call AddOptionGroup "FROM AFTER", 0, 1 call AddOptionGroup "TO BEFORE", 0, 1 call AddOption "FIELDSEP", 1, "YES" call AddOptionGroup "FIELDSEP PURGE", 0, 1 call AddOptionGroup "LAST PURGE", 0, 1 call AddOptionGroup "TOTAL PURGE", 0, 1 call AddOptionGroup "STATS PURGE", 0, 1 call AddOptionGroup "LEVELBITSTRING PURGE", 0, 1 end when type = "LOG" then do call InitializeLogOption call AddOption "RMTHANDLE", 1, "YES" call AddOption "RMTNAME", 1, "YES" call AddOptionNeed "RMTMACHINE", "RMTHANDLE" call AddOptionNeed "RMTMACHINE", "RMTNAME" end when type = "LIST" then do call AddOption "LIST", 1, "NO" call AddOption "GLOBAL", 1, "NO" call AddOption "MACHINE", 1, "YES" call AddOption "HANDLE", 1, "YES" call AddOption "MACHINES", 1, "NO" call AddOption "HANDLES", 1, "NO" call AddOptionGroup "GLOBAL MACHINES MACHINE", 1, 1 call AddOptionGroup "MACHINES HANDLES", 0, 1 call AddOptionGroup "MACHINE MACHINES", 0, 1 call AddOptionGroup "HANDLE HANDLES", 0, 1 call AddOptionNeed "HANDLE", "MACHINE" end when type = "DELETE" then do call AddOption "DELETE", 1, "NO" call AddOption "GLOBAL", 1, "NO" call AddOption "CONFIRM", 1, "NO" call AddOption "MACHINE", 1, "YES" call AddOption "HANDLE", 1, "YES" call AddOption "LOGNAME", 1, "YES" call AddOptionGroup "GLOBAL MACHINE HANDLE", 1, 2 call AddOptionNeed "DELETE", "LOGNAME" call AddOptionNeed "DELETE", "CONFIRM" call AddOptionNeed "HANDLE", "MACHINE" end when type = "HELP" then call ProcessHelp end rc = ParseString(origRequest, "errorBuffer") if rc \= 0 then call STAFExit MakeSTAFResult(STAFError.!InvalidRequestString, , STAFError.!InvalidRequestString.!text || linesep || errorBuffer)return/******************************************************************************//* ProcessHelp - Format help output buffer and exit. *//* Arguments: none *//* Returns : exits *//******************************************************************************/ProcessHelp: call STAFExit MakeSTAFResult(STAFError.!Ok, "STAF Log Help"||linesep||linesep|| , "LOG <GLOBAL | MACHINE | HANDLE> LOGNAME <Logname> LEVEL <Level>"||linesep|| , " MESSAGE <Message> [RESOLVEMESSAGE | NORESOLVEMESSAGE]"||linesep|| , "QUERY <GLOBAL | [[MACHINE <Machine>] [HANDLE <Handle>]] LOGNAME <Logname>"||linesep|| , " [LEVELMASK <Mask>] [QMACHINE <Machine> [QHANDLE <Handle>]]"||linesep|| , " [NAME <Name>] [FIRST <Num> | LAST <Num>] | TOTAL | STATS]"||linesep|| , " [CONTAINS <String>] [LEVELBITSTRING] [FIELDSEP <Char>]"||linesep|| , " [FROM <Timestamp> | AFTER <Timestamp>]"||linesep|| , " [BEFORE <Timestamp> | TO <Timestamp>]"||linesep|| , " Note: <Timestamp> format is date, @time, or date@time"||linesep|| , " (i.e. 19980214, @16:30:45, 19980214@16:30:45)"||linesep|| , "LIST <GLOBAL | MACHINES | [[MACHINE <Machine>] [HANDLE <Handle>] "|| , "[HANDLES]]>"||linesep|| , "DELETE <GLOBAL | [[MACHINE <Machine>] [HANDLE <Handle>]]>"||linesep , " LOGNAME <Logname> CONFIRM"||linesep|| , "PURGE <GLOBAL | [[MACHINE <Machine>] [HANDLE <Handle>]]> LOGNAME <Logname>"||linesep|| , " CONFIRM [plus same optional selection criteria as QUERY except"||linesep|| , " LAST, TOTAL, STATS, LEVELBITSTRING and FIELDSEP not allowed]"||linesep|| , "HELP")return/******************************************************************************//* ProcessLastRequest - If LAST specifiled the process the circular stem *//* holding the selected records and add them the the output buffer. *//* Arguments: none *//* Returns : none *//******************************************************************************/ProcessLastRequest: /* Position the saved pointer to the last record saved */ if lastpntr = 1 then PL_savepntr = lastdata.0 else PL_savepntr = lastpntr - 1 /* Make sure the total of LAST does not exceed the number selected */ if lastdata.0 > selcount then lastdata.0 = selcount /* Build output buffer with first record selected to end of stem */ do i = lastpntr to lastdata.0 logdata = logdata||lastdata.i end /* If did not start at top of stem, then build output buffer from the */ /* top of the stem to last record selected */ if lastpntr \= 1 then do i = 1 to PL_savepntr logdata = logdata||lastdata.i endreturn/******************************************************************************//* ProcessSelectedRecord - The record has matched the QUERY selection input, *//* if NOT TOTAL then concatenate the selected record to the output buffer. *//* Arguments: none *//* Returns : none *//******************************************************************************/ProcessSelectedRecord: selcount = selcount + 1 if stats then do PS_statsindex = pos('1',statslevel) statsarray.PS_statsindex = statsarray.PS_statsindex + 1 end else if totalonly = 0 then do tmpdata = ldate||"-"||convertSeconds(ltime)||fieldsep|| , machine||fieldsep||handle||fieldsep||name||fieldsep|| , level||fieldsep||message||linesep if last = '' then do tmplogdatacnt = tmplogdatacnt + 1 tmplogdata = tmplogdata||tmpdata if tmplogdatacnt >= tmplogdatamax then do logdata = logdata||tmplogdata tmplogdata = '' tmplogdatacnt = 0 end end else do lastdata.lastpntr = tmpdata if lastpntr = lastdata.0 then lastpntr = 1 else lastpntr = lastpntr + 1 end endreturn/******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -