Skip to content

10: How to...

Michael Ekdal edited this page Apr 9, 2024 · 64 revisions

How to check and warn if services are running or not in Windows (new)

java -cp C:\Jvakt\Jvakt.jar Jvakt.monWinServices -run -config c:\Jvakt -id MickePC -in PostgreSQL
MonWinServices

How to check and warn if services are running or not in Windows (old)

@rem *** Check and warn if the "IndexWorker" Service is running ***
sc query "IndexWorker" | findstr /i "RUNNING"
IF %ERRORLEVEL% EQU 0 (
RptToJv.exe -host jvakt.domain.com -id IndexWorker-service -ok -body "Service IndexWorker is RUNNING"
) else (
RptToJv.exe -host jvakt.domain.com -id IndexWorker-service -err -body "Service IndexWorker is NOT RUNNING"
)

How to check and warn about low disk space in Windows

@rem *** Check the C: D: and E: drives. Automatically found drives are checked using default values ***
java.exe -cp C:\JavaSrc Jvakt.CheckDiskSpace -id SAP_PROD_PCP_DiskSpace -jvakt -drv C: 10 10 -drv D: 5 85 -drv E: 10 35

@rem *** Check all drives using the default valuess 10 % and 10 GB ***
java.exe -cp C:\JavaSrc Jvakt.CheckDiskSpace -id SAP_PROD_PCP_DiskSpace -jvakt

-jvakt A switch to enable report to Jvakt. Default is no connection to Jvakt.
-id Used as identifier in the Jvakt monitoring system
-config The directory where to find the Jvakt.properties file. like "-config c:\Temp". Optional. Default is the current directory
-drv Three values is mandatory: drive min-percentage min-gigabyte. e.g -drv D: 10 150 -drv F: 12 120 (optional)
Automatically found drives are checked against the default values 10 % and 10 GB
Returncode is 0 when OK else 12.

CheckLogs

How to check and rename a completed logfile

@rem *** Checking a log file and renaming it afterwards ***
java.exe -cp C:\JavaSrc Jvakt.CheckLogs -jvakt -jvtype S -ren -dir C:\Logs\ -pos FtpSnd.log -suf .log -id SEND_FTP_CheckLogs
Beginning of CheckLogs.csv file ( read by the Jvakt-CheckLogs program )
E;Error
O;No Error(s)&completed M;Successful transfer
End of file

How to check a log file that constantly grows (old)

@rem *** Checking a read-only log file and saving the position in the -dir folder until next check ***
java.exe -cp C:\JavaSrc Jvakt.CheckLogs -jvakt -psav -suf .log -dir D:\glassfish\logs\ -pos server.log -id ChkLogs_glassfish
Beginning of CheckLogs.csv file ( read by the Jvakt-CheckLogs program )
E;Error
O;Error&324
End of file

How to check many log files that constantly grows, like syslog files (new)

This example checks the log files created by the nxlog Syslog collector.
NXLog Community Edition
@rem *** Checking many log files in a read-only -dir folder and saving the position in the -config folder until next check ***
java.exe -cp Jvakt.jar Jvakt.CheckLogs -csav -dir \win1\nxlog-Syslog_data -suf .log -jvakt -id nxlog-Syslog
Beginning of CheckLogs.csv file ( read by the Jvakt-CheckLogs program )
E;Error
E;<88>
O;Error&324
End of file

How to check Hyper-V and the event log in general.

How to check the event log, with some help from PowerShell.

CMD file
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File GetEvents.ps1
java -cp C:\JavaSrc Jvakt.CheckLogs -jvakt -jvtype I -ren -dir C:\MonEventLogs\Hyper-V\ -pos CheckLogs -suf .txt -id Chk_Hyper-V_events
Beginning of GetEvents.ps1 file

Get-WinEvent -FilterHashtable @{ LogName='Microsoft-Windows-Hyper-V-VMMS-Admin';
StartTime=((Get-Date).AddMinutes(-16))} -ComputerName Svr1 | Out-File .\CheckLogs-svr1.txt -Encoding utf8 -Width 240;

Get-WinEvent -FilterHashtable @{ LogName='Microsoft-Windows-Hyper-V-VMMS-Admin';
StartTime=((Get-Date).AddMinutes(-16))} -ComputerName svr2 | Out-File .\CheckLogs-svr2.txt -Encoding utf8 -Width 240

Get-WinEvent -FilterHashtable @{ LogName='Microsoft-Windows-Hyper-V-VMMS-Admin';
StartTime=((Get-Date).AddMinutes(-16))} -ComputerName svr3 | Out-File .\CheckLogs-svr3.txt -Encoding utf8 -Width 240

End of GetEvents.ps1 file
Beginning of CheckLogs.csv file ( read by the Jvakt-CheckLogs program )
E;Warning
E;Error
E; W a r n i n g
E; E r r o r
O;10103 Warning
O;19060 Error
O;18012 Error
O;18016 Error
O;32315 Warning
End of file

How to check for Hyper-V replication status with help from PowerShell.

CMD file
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File GetEvents.ps1
java -cp C:\JavaSrc Jvakt.CheckLogs -jvakt -jvtype R -ren -dir C:\MonHyperVstatus\ -pos CheckLogs-tgtsvr -suf .txt -id Hyper-V_tgtsvr_Status
java -cp C:\JavaSrc Jvakt.CheckLogs -jvakt -jvtype R -ren -dir C:\MonHyperVstatus\ -pos CheckLogs-srcsvr -suf .txt -id Hyper-V_srcsvr_Status
java -cp C:\JavaSrc Jvakt.ManFiles -run -del -hou 72 -nolist -sdir C:\MonHyperVstatus -suf .sav
GetEvents.ps1 file
Get-VMReplication -ComputerName tgtsvr | Out-File .\CheckLogs-tgtsvr.txt -Encoding utf8
Get-VMReplication -ComputerName srcsvr | Out-File .\CheckLogs-srcsvr.txt -Encoding utf8
Beginning of CheckLogs.csv file ( read by the Jvakt-CheckLogs program )
E;Error
E;Critical
End of file

ManFiles examples

How to check a folder for old files queuing up.

@rem *** Checking files are imported into APP and not remaining on disk ***
java -cp C:\JavaSrc Jvakt.ManFiles -nosub -pre SAP_ -suf .xml -sdir E:\Files\APP\In -min 30 -nolist > c:\temp\Check_Folders.txt
IF %ERRORLEVEL% EQU 0 (
C:\Java\jdk\bin\java -cp c:\JavaSrc Jvakt.RptToJv -host jvakt.domain.com -id Files_from_APP -ok -body "No files from APP in queue"
) else (
C:\Java\jdk\bin\java -cp c:\JavaSrc Jvakt.RptToJv -host jvakt.domain.com -id Files_from_APP -err -body "Files from APP in queue"
)

Move files from -sdir to -tdir. The text ptp050 must occur inside the file. The files must end with -xml

java -cp C:\JavaSrc Jvakt.ManFiles -sdir c:\temp -suf .xml -move -list -tdir C:\tmp -run -scan ptp050 -nosub

Move files from -sdir to -tdir. File file change date is in the 2015 intervall. The program is looping.

java -cp C:\JavaSrc Jvakt.ManFiles -sdir \share\in -list -nosub -fdat 20150101000000 -tdat 20151231999999 -tdir N:\out\2015 -move -run -loop

Executing the rows inside the parameter file Copy2fs.par and reporting the status to the Jvakt server.

java -cp c:\JavaSrc\ Jvakt.ManFiles -parfile Copy2fs.par -jvakt -id PROD-Copy2fs

Executing the ManFiles commands from inside the parameter file To-From.par in a never ending loop.

C:\Java\jdk\bin\java -cp C:\JavaSrc Jvakt.ManFiles -parfile To-From -loop
Beginning of To-From.par file
# Comments
-run -move -suf .txt -pos EX2_ -list -nosub -sdir E:\ToY -tdir \fs\FromX -adir E:\Copies
-run -move -suf .txt -pos EX2_ -list -nosub -sdir \fs\ToX -tdir E:\FromY
End of To-From.par file

Moving files depending on the content in the files.

java -cp c:\JavaSrc\ Jvakt.ManFiles -run -move -nosub -sdir \fs\IN -Pos Totalin -suf .txt -tdir \fs\IN\T2 -scan FileContent -nosub

Checking for files older than 30 minutes exists and report the status to Jvakt.

java.exe -cp C:\JavaSrc Jvakt.ManFiles -nosub -pre SAP_ -suf .txt -sdir E:\Integrations\Out -min 30 -nolist > c:\tmp\Check_Folders.txt
IF %ERRORLEVEL% EQU 0 (
java.exe -cp c:\JavaSrc Jvakt.RptToJv -host jvhost -id PROD_Files_from_APP -ok -body "No files from APP in queue"
) else (
java.exe -cp c:\JavaSrc Jvakt.RptToJv -host jvhost -id PROD_Files_from_APP -err -body "Files from APP in queue"
)

Executing the ManFiles commands from inside the parameter file Copyfiles01.par.

Copies files ending with xml or json and add the new suffix of "copied" to the source files. C:\Java\jdk\bin\java -cp C:\JavaSrc Jvakt.ManFiles -parfile Copyfiles -pardir c:\ManFiles\Task01
Beginning of Copyfiles01.par file
# Comments
-run -copy -sdir \temp -tdir \temp\bu -suf xml;json -asuf copied -nosub -list
End of Copyfiles01.par file

Deleting files older than 30 days (30*24 hours) with the suffix "copied".

java.exe -cp C:\Jvakt\Jvakt.jar Jvakt.ManFiles -run -del -nosub -suf .copied -sdir \temp -hou 720 -nolist

Renaming ".log" files by adding the new suffix -sav to the found files.

java.exe -cp C:\Jvakt\Jvakt.jar Jvakt.ManFiles -run -sdir \temp -suf .log -asuf saved

Removing the suffix sav on the found files.

java.exe -cp C:\Jvakt\Jvakt.jar Jvakt.ManFiles -run -sdir \temp -suf .saved -rsuf saved

How to create the CpyAS400TblToSQLsvr command file from AS400 commands

Note that this is an example and it's possible to do it in more ways according to your preferences.

Use the DSPFD command in the AS400 to create a file containing all physical files in a particular library.

DSPFD FILE(AS400LIB/*ALL) TYPE(*BASATR) OUTPUT(*OUTFILE) FILEATR(*PF) OUTFILE(WORKLIB/FILENAME)

Use an AS400 query to analyze the file and create a new file containing the names of the physical files in the library.

Use previously file as input.
Define two new result fields as T1 'xxxxx ' and T2 as ' zzzzz'
Select fields T1, ATFILE and T2 in that order.
Select records as ATDTAT EQ 'D'
Select output type as a 'Database file', 'Detail' and new file name as FILENAME2.

Use the CPYTOIMPF command in the AS400 to create a PC-file in the IFS file system of the AS400.

CPYTOIMPF FROMFILE(WRKLIB/FILENAME2) TOSTMF(AS400LIB.txt) MBROPT(*REPLACE) STMFCODPAG(*PCASCII) RCDDLM(*CRLF) DTAFMT(*FIXED) STRDLM(*NONE) FLDDLM(' ')

Use the FileZilla FTP client to retrieve the PC-file from the AS400 to the PC.

Use SFTP or FTP, user/password according to your preference.
Depending of settings in the AS400 you might not access the IFS file system by default.
If you add the name of the IFS folder where your file resides you should be fine.
Tab Advanced/Default remote directory: /home/username

Use the Notepad++ editor to replace the xxxxx and yyyyyy strings to the suitable java command string.

N.B. Some versions of the regular Notepad cannot replace long strings, thus Notepad++.

Use Search/Replace to change all xxxxx lines to something like this:
java.exe -Djava.library.path=C:\Jvakt -cp C:\Jvakt\jt400.jar;c:\Jvakt\mssql-jdbc.jar;c:\Jvakt\Jvakt.jar Jvakt.CpyAS400TblToSQLsvr -run -as400host AShost -as400user ASuser -as400pw ASpwpw -as400lib ASlib -as400tbl

Use Search/Replace to change all zzzzz lines to something like this:
-SQLhost SQLserverhost -SQLdbase AS400_history -numlog 10000 -sqlisec y >> CpyAS400TblToSQLsvr.log 2>> CpyAS400TblToSQLsvrE.log

Rename the file suffix to .CMD and excute.

Clone this wiki locally