Skip to content

04: The agent programs

Michael Ekdal edited this page Nov 25, 2023 · 64 revisions

RptToJv.java

RptToJv is the main program to be used by agent reporting.
It can be executed from the command line and called by scripts or other system where a command can be called.
It has also a C# variant to be used from windows without any need of java.

The -id parameter

The -id is important.
It is the key of the report and is used in the DB to keep track of things.

The -type parameter

R is the preferred type to use whenever possible. It requires the agent to report the status of the object at regular intervals. If the agent fails to report the status the server side will notice lateness and issue a warning.

S is used when an event monitored happens every day or a specific weekday. e.g. use RptToJv in backup scripts to monitor the backups. A warning will be issued when the report is late.

T is used when an event monitored has no known time when to report . No time out warning will be issued.

I is used at any time to send a warning or information to the console. No lateness tests are possible.

If no previous row exists in the status table it will be created.
In might be necessary to update new row if the default rules is not sufficient.
Once the record is created, you need to use the console program to change values like type and prio.

Command line example

When executed without any switch the help text is shown
java -cp C:\JavaSrc Jvakt.RptToJv -id Script1 -ok -type R -body "All is fine"
or
java -cp Jvakt.jar Jvakt.RptToJv -id Script2 -err -body "A problem occured!"
or
RptToJv.exe -id Server1 -ok -type t -body "All is fine"

-host - The host of the Jvakt server. The default is 127.0.0.1
-port - The Jvakt server port. The default is 1956
-id - The Jvakt id key of the monitoring set
-ok -> short for -sts OK
-err -> short for -sts ERR
-info -> short for -sts INFO
-sts - default is OK (or rather use -ok, -err or -info)
-body - Any descriptive text
-prio - default is 30
-type - R=repetetive S=scheduled T=regular(no timeout) I=immediate D=delete

CheckLogs is used to check text file based logs of different types.

It can be executed from the command line.

It expects at least one .csv file to be present in the -config folder or the current folder, like CheckLogs01.csv.
If the -jakt switch is used one Jvakt.properties file must be present to identify the host and port of the Jvakt server.

(Deprecated)
It expects three text files to be present, CheckLogs.srch, CheckLogs.okay and CheckLogs.must.
CheckLogs.srch must contain error strings to search for. e.g. ORA-
CheckLogs.okay Can be empty. Strings considered okay even when triggered by the CheckLogs.srch file. e.g. ORA-01013
CheckLogs.must Can be empty. Can contain strings that must be present. e.g. Successfull transfer
(Deprecated)

--- start csv file example ---
# rows starting E; are strings to search for. At least one is necessary to raise an error.
# rows starting O; are strings that can turn off the error found in a row. Optional.
# rows starting M; are strings must be found in the log-file, else an error is raised. Optional.
# the search string can be divided by a ampersand (&) to contain several search strings. # E.g. O;Error not found&ftpuserxx E;Error
E;warning
E;critical
E;ORA-
O;ORA-00054
E;Disconnected&Unable to authenticate
E;Connection failed.
E;Server unexpectedly closed network connection
E;Server refused public-key signature despite accepting key
E; 550
E;The system cannot find the file specified
E;Password authentication failed
E;Access denied
E;Failed to connect to
E;FTP port did not open
E;Script&Failed
E;The network path was not found
M;Upload successful
--- end file example ---

It might need the jVakt.properties file containing jvhost, jvport and the database parameters.
The environmental variable Error-level is set to the number of errors found, else 0.

The parameters and their meaning are:
-dir = The name of the directory to scan for log files, like -dir c:\Temp
-suf = The suffix of the log files you want to include in the scan, like -suf .log. (optional)
-pos = Text that must be contained in the log file names, like -pos glassfish (optional)
-id = Used as identifier in the Jvakt monitoring system. (optional).
-csav = Saves the position of the scanned file in the -config directory. Optional.
-psav = Saves the position of the scanned file in the log-files directory. Optional.
-ren = A switch that makes the scanned file be renamed instead of saving position.
-logs = A switch to enable importing the checked log file into the Jvakt DB. Default is no import. Optional.
-jvakt = A switch to enable report to Jvakt. Default is no connection to Jvakt. Optional.
-jvtype = The type of the Jvakt report. Optional. The default is R. Optional.
-config = The directory where to find the setup files. Like -config c:\Temp. Default is current directory. Optional.
-charset = Default is UTF8. It could be UTF-16, UTF-32, ASCII, ISO8859_1...
The program will usually detect UTF-16 and UTF8 so don't use the -charset parameter unnecessarily.

Example 1. Used with no end log files (newer solution)

Used with ever growing logs, i.e. DB logs, app server logs and so on.
This example checks log file without changing them in any way, you need only read/only access.
It creates “position” files in the -config directory in order to know where the log file ended.
It expect to find the .csv files ant the Jvakt.properties file in the -config directory.
The next time CheckLogs continues from where it ended the last time.

The rules for the search is entered in the .csv file.
The .csv file could look like this:
E;ERROR
E;<88>
E;WARNING
O;WARNING&stopping nxlog service

java -cp Jvakt.jar Jvakt.CheckLogs -csav -config C:\Jvakt\CheckLogs\nxLogs -dir \\win1\nxlog-Syslog_data -suf .log -id nxlogSyslogSvr

Example 2. Used with no end log files (older solution)

Used with ever growing logs, i.e. Syslog server logs, DB logs, app server logs and so on. This example checks log file without changing them in any way.
It creates “position” files in the -dir directory in order to know where the log file ended.
The next time CheckLogs continues from where it ended the last time.

The rules for the search is entered in the .must and .srch files. (This deprecated, it can be replaced by the .csv file.)
The “srch” file contains ORA- (or E;ORA- in the csv file) to react to all strings starting with ORA-.
The “okay” file contains ORA-01013 (or O;ORA-01013 in the csv file) and some more to make these specific strings acceptable.

java -cp Jvakt.jar Jvakt.CheckLogs -psav -dir c:\logs\ -suf .log -id OraSystemA

Example 3 Used with "logical end" log-files (e.g. FTP transfer, backup jobs...)

This example scans files ending with AftgSndFtp.log created by FTP. The status is sent to the Jvakt server. It also checks the ERRORLEVEL variable and sends an email depending of the result.
When the log file is scanned it will be renamed (-ren) in order for it not to read it the next time.
The “srch” file contains a number of strings (or E;error in the csv file) known to appear if the FTP transfer fails.
The “must” file contains “Upload successful” (or M;Upload successful in the csv file). If missing in the log file an error is sent to Jvakt and ERRORLEVEL is increased by 1.

java -cp C:\JavaSrc Jvakt.CheckLogs -jvakt -jvtype S -ren -dir C:\Logs\ -pos AftgSndFtp.log -suf .log -id SEND_FTP_CheckLogs
set RC=%ERRORLEVEL%
if %RC% EQU 0 ( "send OK mail" )
if %RC% GEQ 1 ( "send FAIL mail" )

Example 4 To scan a FTP server logs.

This example scans a FTP server logs. The status is sent to the Jvakt server. The “srch” file contains “key check failure” to be aware of if the host key of the remote host was changed.

java -cp Jvakt.jar Jvakt.CheckLogs -jvakt -jvtype R -psav -dir C:\CoreFTPServer\Log\ -suf .log -id CoreFTPServer_CheckLogs

CheckDiskSpace

CheckDiskSpace is used to the remaining space in the disk drives.
It can be executed from the command line.
The Jvakt.properties file must be present if the -jvakt switch is used.

-id = Used as identifier in the Jvakt monitoring system. Optional.
-jvakt = A switch to enable report to Jvakt. Default is no connection to Jvakt. Optional.
-config = The directory where to find the Jvakt.properties file. like **-config c:\Jvakt**. The default is the current directory. Optional.
-drv = List of drives to be checked. -drv D: 10 150 -drv F: 12 120 -drv C: 12 120
On every -drv there has to be three values.
First the drive letter (C:), second the minimum percentage allowed (%) and last the minimum allowed disk space (GB).

Automatically found drives are checked against the default values 10 % and 10 GB
Returncode is 0 when OK else 12.

java -cp C:\Jvakt\Jvakt.jar Jvakt.CheckDiskSpace -jvakt -id MickesPC -config C:\Jvakt -drv C: 20 20

monWinServices

monWinServices is used to monitor the Services of a Windows server.
It can be executed from the command line.
The Jvakt.properties file must be present if the -jvakt switch is used.

-id = Used as identifier in the Jvakt monitoring system. Optional.
-run = A switch to enable report to Jvakt. Default is no connection to Jvakt. Optional.
-config = The directory where to find the Jvakt.properties file. like **-config c:\Jvakt**. The default is the current directory. Optional.
-in = Include a "Service Name" to be monitored (not "Display Name"!). A part of the name is accepted.
Up to 99 -in is accepted. e.g. -in postgresql -in gp and so on...
-ex = Exclude a "Service Name" from being monitored (not "Display Name"!). A part of the name is accepted.
Up to 99 -ex is accepted. e.g. -in postgresql12 -in gpupdate and so on...

The default is monitoring the Running status of all Windows services with startup type "Automatic" but not service with "Delayed Start" or "Trigger Start".
Using a -in parameter like "-in SAP" will check that all services where the string SAP is found has the status "Running".
No matter if it is "Delayed Start" or "Trigger Start".
The Windows tool SC.exe is used to find the status.

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

Clone this wiki locally