Monday, September 24, 2012

Lawson Health Check Automation

Lawson Health Check Automation

Disclaimer

While I use these scripts in my environment they are only tested in my environment. These examples are in no way endorsed by Lawson, Infor or any of their affiliates. There is no warranty, expressed or implied, to them  -- use at your own risk.

-- Common sense dictates that you at least read through thet script to understand what it does.

Base Script


:: This file gathers logs from the production Lawson system
::   and places them in a temporary local folder where it then
::   parses them for the current day's events and any errors.
:: 20120913 garymartin2007@gmail.com
:: REQUIREMENTS:
::   -- Microsoft .NET Framework v4 +
::   -- WinSCP with .NET COM interop
::      -- Create WinSCP script file
::   -- PowerShell
::   -- tidyit.cmd
:: COMMAND LINE ARGUMENTS - none
:: PROGRAM Flow
::   -- Set log file
::   -- Get date formats using PowerShell
::   --- Set date formats
::   -- Run WinSCP script to gather log files
::   -- Parse Lawson log files for errors and ouput to log file
:: CHANGELOG
::    -- 20120913 Beta version testing
::    -- 20120913 Modifed output for HTML file creation
::    -- 20120914 Added HTML Tidy to clean up any errors in output file

@echo off
setLocal EnableDelayedExpansion
set LOGFILE=C:\Lawson\reports\scrout.html
set LOCALLOGFOLDER=C:\Lawson\reports\logs\

:: get date and set vars for later use
::   Powershell is used because Win 7 does not provide
::     week day names
powershell -NonInteractive -Command "& {Get-Date -Format ddd.MMM.dd}" > date.txt
REM powershell -NonInteractive -Command "& {Get-Date -Format .MMM.dd', 'yyyy}" > date1.txt
powershell -NonInteractive -Command "& {Get-Date -Format .MMM.dd}" > date1.txt

:: Date format for latm, ladb, and lajs logs
for /f "tokens=* delims= " %%a in (date.txt) do (
set DATESTR1=%%a
)
:: Date format for ProcessFlow logs
for /f "tokens=* delims= " %%a in (date1.txt) do (
set DATESTR2=%%a
)

:: get the current logs using WinSCP script
C:\gmTools\WinSCP\WinSCP.exe /console /script=c:\Lawson\reports\WinSCPHC.txt

:: Search and log errors to file
:: Start Head section
@ECHO ^<html lang="en"^>^<head^>^<title^>Lawson ERP AHC Implementation^</title^> > %LOGFILE% 2>&1
:: to enable HTML5 in IE
@ECHO ^<script^>document.createElement('header'); document.createElement('nav'); document.createElement('article'); document.createElement('footer'); document.createElement('aside');^</script^> >> %LOGFILE% 2>&1
@ECHO ^<link rel="stylesheet" href="scrout.css" /^> >> %LOGFILE% 2>&1
@ECHO ^</head^>^<body^> >> %LOGFILE% 2>&1
@ECHO ^<h1^>Production^</h1^>^<p^> >> %LOGFILE% 2>&1
@ECHO DATESTR1 = %DATESTR1% ^<br /^> DATESTR2 = %DATESTR2% ^<br /^>for findstr regex format. Last run >> %LOGFILE% 2>&1
time /t >> %LOGFILE% 2>&1
@ECHO . ^</p^> >> %LOGFILE% 2>&1
:: End Head section
:: lawsec section
@ECHO ^<h2^>LAWSEC Results^</h2^> >> %LOGFILE% 2>&1
@ECHO ^<pre^> >> %LOGFILE% 2>&1
findstr /i /b "Lawson" %LOCALLOGFOLDER%heilawwi004\lawsec.txt >> %LOGFILE% 2>&1
@ECHO ^</pre^> >> %LOGFILE% 2>&1
:: jqstatus section
@ECHO ^<h2^>JQSTATUS Results^</h2^> >> %LOGFILE% 2>&1
@ECHO ^<pre^> >> %LOGFILE% 2>&1
findstr /i /n /b "^[0-9]" %LOCALLOGFOLDER%heilawwi004\jqstat.txt >> %LOGFILE% 2>&1
@ECHO ^</pre^> >> %LOGFILE% 2>&1
:: jobinteg section
@ECHO ^<h2^>JOBINTEG Results^</h2^> >> %LOGFILE% 2>&1
@ECHO ^<pre^> >> %LOGFILE% 2>&1
findstr /i /n /b "ORPHANED " %LOCALLOGFOLDER%heilawwi004\orphans.txt >> %LOGFILE% 2>&1
@ECHO ^</pre^> >> %LOGFILE% 2>&1
:: secinteg section
@ECHO ^<h2^>SECINTEG Results^</h2^> >> %LOGFILE% 2>&1
@ECHO ^<pre^> >> %LOGFILE% 2>&1
findstr /i /n /b "corrupt" %LOCALLOGFOLDER%heilawwi004\secinteg.txt >> %LOGFILE% 2>&1
@ECHO ^</pre^> >> %LOGFILE% 2>&1
:: latm log
@ECHO ^<h2^>LATM.LOG Errors only^</h2^> >> %LOGFILE% 2>&1
@ECHO ^<pre^> >> %LOGFILE% 2>&1
findstr /i /n /b %DATESTR1% %LOCALLOGFOLDER%heilawwi004\latm.log | find "PrcTPCrash" >> %LOGFILE% 2>&1
@ECHO ^</pre^> >> %LOGFILE% 2>&1
@ECHO ^<hr /^> >> %LOGFILE% 2>&1
@ECHO ^<pre^> >> %LOGFILE% 2>&1
findstr /i /n /b %DATESTR1% %LOCALLOGFOLDER%heilawwi004\latm.log | find /i "ERROR" >> %LOGFILE% 2>&1
@ECHO ^</pre^> >> %LOGFILE% 2>&1
:: ladb log
@ECHO ^<h2^>LADB.LOG ^</h2^> >> %LOGFILE% 2>&1
@ECHO ^<p^>Filtered out (LoadLic) lines.^</p^> >> %LOGFILE% 2>&1
@ECHO ^<pre^> >> %LOGFILE% 2>&1
findstr /i /n /b %DATESTR1% %LOCALLOGFOLDER%heilawwi004\ladb.log | find /v "(LoadLic)" >> %LOGFILE% 2>&1
@ECHO ^</pre^> >> %LOGFILE% 2>&1
:: lajs log
@ECHO ^<h2^>LAJS.LOG All events^</h2^> >> %LOGFILE% 2>&1
@ECHO ^<pre^> >> %LOGFILE% 2>&1
findstr /i /n /b %DATESTR1% %LOCALLOGFOLDER%heilawwi004\lajs.log >> %LOGFILE% 2>&1
@ECHO ^</pre^> >> %LOGFILE% 2>&1
:: pflow.out log
@ECHO ^<h2^>PFLOW.OUT^</h2^> >> %LOGFILE% 2>&1
@ECHO ^<p^>Java com.lawson errors only^</p^> >> %LOGFILE% 2>&1
@ECHO ^<pre^> >> %LOGFILE% 2>&1
findstr /i /n /b %DATESTR2% %LOCALLOGFOLDER%heilawwi004\pflow.out | find "at com.lawson" >> %LOGFILE% 2>&1
@ECHO ^</pre^> >> %LOGFILE% 2>&1
:: pfsch.out log
@ECHO ^<h2^>PFSCH.OUT Database Exception errors only ^</h2^> >> %LOGFILE% 2>&1
@ECHO ^<pre^> >> %LOGFILE% 2>&1
findstr /i /n /b %DATESTR2%",.[0-9]*.[0-9]*:[0-9]*:[0-9].*.M\].*Lawson.Database.Exception" %LOCALLOGFOLDER%heilawwi004\pfsch.out >> %LOGFILE% 2>&1
@ECHO ^</pre^> >> %LOGFILE% 2>&1
@ECHO ^<p^>There are:^</p^> >> %LOGFILE% 2>&1
@ECHO ^<pre^> >> %LOGFILE% 2>&1
REM findstr /i /n /b %DATESTR2%",.[0-9]*.[0-9]*:[0-9]*:[0-9].*.M\].*Scheduler shutdown waiting for jobs to complete" %LOCALLOGFOLDER%heilawwi004\pfsch.out | find /c "Scheduler shutdown waiting for jobs to complete" >> %LOGFILE% 2>&1
findstr /i /n /b %DATESTR2%",.2012.[0-9]*:[0-9]*:[0-9]*.[A|P]M\].Scheduler shutdown waiting for jobs to complete" %LOCALLOGFOLDER%heilawwi004\pfsch.out | find /c "Scheduler shutdown waiting for jobs to complete" >> %LOGFILE% 2>&1
@ECHO ^</pre^> >> %LOGFILE% 2>&1
@ECHO ^<p^>jobs waiting for scheduler to shut down. If there are more than a few: to correct this: ^<br /^> ^<br /^> Follow AR_1095827 instructions.^<br /^> ps -ef ^&#124; grep WfSche ^&#124; less ^<br /^> to kill the hung processes.^</p^> >> %LOGFILE% 2>&1
:: Start footer
@ECHO ^<br /^>^<p^>Completed  >> %LOGFILE% 2>&1
time /t >> %LOGFILE% 2>&1
@ECHO ^</p^> >> %LOGFILE% 2>&1
:: Close HTML tags
@ECHO ^</body^>^</html^> >> %LOGFILE% 2>&1
call tidyit.cmd %LOGFILE%
endlocal

@start "" /b C:\PROGRA~2\INTERN~1\iexplore.exe C:\Lawson\reports\scrout.html

Requires

Set the following to run as a cron job:
jqstatus –rwh > /law/app/jqstat.txt
jobinteg –vd > /law/app/orphans.txt
lawsec > /law/app/lawsec.txt
secinteg –fv > /law/app/secinteg.txt

No comments:

Post a Comment

Reflecting on Service

I was US Army Airborne Field Artillery - Target Acquisition. I never was in combat, so I don't think of myself as a veteran, but I do th...