-
Notifications
You must be signed in to change notification settings - Fork 1
02: The core java programs
The class Server is the core listener. It waits for new connections and starts new threads when needed.
It's dependent on the PostgreSQL database and the file Jvakt.properties.
It starts a single thread/instance of the class DBupdate and listen for connections on an IP-port (default is 1956).
When a new connection is made it is transferred to a new thread/thread of the class ServerThread, which from now on handles the current connection. In the meantime the server instance is waiting for new connections.
THe Jvakt.Server starts in dormant mode which means it won't send any mail or SMS, just show any issues in the console.
Sample startup scripts (win):
StartServer.cmd (should be started by the Task Scheduler when the server starts.)
@rem - The Activate_dly.cmd activates Jvakt.Server 15 minutes after start.
start "Activate" activate_dly.cmd
@rem - Jvakt.server receives all reports from all agents amd monitors and updates the database.
C:\Java\jdk64\bin\java.exe -Xmx4096m -Xms1024m -cp C:\JavaSrc;C:\JavaSrc\postgresql.jar Jvakt.Server -log -config C:\JavaSrc > Server.log 2> ServerE.log
Sample startup scripts (Linux):
StartServer.sh (should be started by the cron scheduler when the server starts.)
#!/usr/bin/bash
# @reboot /home/jvakt/Jvakt/StartServer.sh (cron)
# Send the activate_dly.sh script to the background. It will activate Jvakt.Server which starts in dormant mode by default.
/home/jvakt/Jvakt/activate_dly.sh &
# Start Jvakt.Server which receive reports from agents and monitors and update the database.
java -cp /home/jvakt/Jvakt/Jvakt.jar Jvakt.Server -log -config /home/jvakt/Jvakt >> /home/jvakt/Jvakt/Logs/Server.log 2> /home/jvakt/Jvakt/Logs/ServerE.log
Activate_dly.cmd:
@rem This script is started from StartServer.cmd.
@rem Aktivates the Jvakt.Server after 15 minutes
timeout 900
C:\Java\jdk\bin\java.exe -cp C:\JavaSrc Jvakt.RptToJv -host 127.0.0.1 -port 1956 -type Active -id Jvakt -config D:\Jvakt-console\config >> activate.log
exit
Activate_dly.sh:
#!/usr/bin/bash
# (Base function) Sends an activate message to the Jvakt server after a timeout of 1200 seconds.
# The time out gives the agents and monitors a chance to report in.
# This cmd file is triggered from the StartServer.cmd.
# The Jvakt.Server always starts in dormant mode and need to be activated after a while.
sleep 20m
java -cp /home/jvakt/Jvakt/Jvakt.jar Jvakt.RptToJv -host 127.0.0.1 -port 1956 -type Active -id Jvakt -config /home/jvakt/Jvakt/
DBupdate class
The DBupdate class is used by Server and is used as a single instance tasked to handle the database update logic.
It is synchronized which means the update of the database will be made one update after another.
ServerThread class
ServerThread class is used by Server and parses the message from the client. Then it disconnects from the client and sends the message as an object to the DBupdate instance and waits until it has finished.
A number of ServerThread might be active at the same time waiting for the DBupdate to finish.
CheckStatus reads the status table and keeps the status codes and the console table up to date.
it checks for timeouts. i.e. where the agents has failed to report the status in time.
It checks for reported errors where the accepted number of errors has been exceeded.
If an OK has been received any corresponding errors in the console is removed.
It triggers a plugin for the agent if such is registered.
It's dependent on the PostgreSQL database and the file Jvakt.properties.
Sample startup scripts (win):
CheckStatus.cmd:
@rem - The CheckStatus.cmd should be started by the Task Scheduler every minute.
java -cp C:\JavaSrc;C:\JavaSrc\postgresql.jar Jvakt.CheckStatus
SendMail sends mail whenever the status has changed either way. The prio must be below 30. It is used for more important issues to mail interested parties. SendMail sends mail decided by the CheckStatus program. The Status table is read and updated regarding mail issues. The property toEmail in file jVakt.properties is read to decide the interested parties.
Sample startup scripts (win):
SendMail.cmd:
@rem - The SendMail.cmd should be started by the Task Scheduler every minute.
**java -cp C:\JavaSrc;C:\JavaSrc\postgresql-42.2.5.jar;jakarta.activation-api-2.0.0.jar;C:\JavaSrc\jakarta.mail-2.0.0.jar Jvakt.SendMail
Use a "Cinterion MC55i Terminal GPRS modem with serial conn" and a "W&T COM Port Redirector" to be able to send SMS. Google it and you will easily find such a modem.
SendSMS sends a SMS text message whenever the status has changed either way, positive or negative.
The prio must be below 30. It is used for more important issues to SMS text interested parties.
SendSMS sends SMS text decided by the CheckStatus program. The Status table is read and updated regarding SMS issues.
The property toSMS in file jVakt.properties is read to decide the interested parties.
The properties SMShost and SMSport is also read from the Jvakt.Properties file in order to find the Cinterion box on the network.
Sample startup scripts (win):
SendSMS.cmd:
@rem - The SendSMS.cmd should be started by the Task Scheduler every minute.
java -cp C:\JavaSrc;C:\JavaSrc\postgresql.jar Jvakt.SendSMS -config D:\Jvakt-console\config >> SendSMS.log 2> SendSMSE.log
Use a "Telonika RUT241 router/modem" to be able to send SMS using HTTP. Google it and you will easily find such a modem.
SendSMShttp sends a SMS text message whenever the status has changed either way, positive or negative.
The prio must be below 30. It is used for more important issues to SMS text interested parties.
SendSMShttp sends SMS text decided by the CheckStatus program. The Status table is read and updated regarding SMS issues.
The property toSMS in file jVakt.properties is read to decide the interested parties.
The properties SMSuser, SMSpwd, SMShost and SMSport is also read from the Jvakt.Properties file in order to find the Telonika box on the network.
Sample startup scripts (win):
SendSMS.cmd:
@rem - The SendSMS.cmd should be started by the Task Scheduler every minute.
java -cp C:\JavaSrc;C:\JavaSrc\postgresql.jar Jvakt.SendSMShttp -config D:\Jvakt-console\config >> SendSMShttp.log 2> SendSMSEhttp.log
SendMail30 sends mail whenever a status row has changed either way. The prio is by default 30 and above, but it's possible to monitor for rows down to prio 0. It is used for lesser important issues to be able to mail interested parties. SendMail30 sends mail decided by the CheckStatus program. The Status table is read and updated regarding mail issues. The file SendMail30-01.csv is read to decide the interested parties.
Sample startup scripts (win):
SendMail30.cmd:
@rem - The SendMail30.cmd should be started by the Task Scheduler every minute.
java -cp C:\JavaSrc;C:\JavaSrc\postgresql.jar;jakarta.activation-api-2.0.0.jar;C:\JavaSrc\jakarta.mail-2.0.0.jar Jvakt.SendMail30 -config D:\Jvakt-console\config >> SendMail30.log 2> SendMail30E.log
SendMailSTS is meant to be executed at regular intervals. e.g. every third hour. It sends the current status. Usually it will show a healthy status. It's up to the on-call-duty person to react if an expected status mail doesn't appear.
Sample startup scripts (win):
SendMailSTS.cmd:
@rem - The SendMailSTS.cmd should be started by the Task Scheduler at suitable times when a status mail is wanted.
java -cp C:\JavaSrc;C:\JavaSrc\postgresql-42.2.5.jar;jakarta.activation-api-2.0.0.jar;C:\JavaSrc\jakarta.mail-2.0.0.jar Jvakt.SendMailSTS -config D:\Jvakt-console\config >> SendMailSTS.log 2> SendMailSTSE.log
Magenta - is a serious error. The difference from red is the value in the importance column is below 30.
Red - is a warning.The difference from magenta is the value in the importance column is 30 or higher.
Yellow - is a warning no matter the importance. It's could be the agent or monitor has stopped to report in the status. This means the real status of the object may be okay, but investigation is necessary.
Orange - is a warning. A row of type S or R has not reported in within the time limits.
TheSendMsg class is used by other classes to send messages to the server instance.
console is a GUI program used to keep an eye of the status while present at site.
The file console.properties is read and the following parameters need to be present:
database = Jvakt
dbuser = console
dbpassword = pw
dbhost = localhost
dbport = 5433
jvhost = 127.0.0.1
jvport = 1956
The command to start the other apps, which runs in a completely separate process.
cmdHst = javaw -cp Jvakt.jar Jvakt.consoleHst
cmdSts = javaw -cp Jvakt.jar Jvakt.consoleSts
cmdStat = javaw -cp Jvakt.jar Jvakt.StatisticsChartLauncher
cmdStats = javaw -cp Jvakt.jar Jvakt.StatisticsChart
statsDir = //jvakthost/Stat
NOTE that you must use forward slashes / not back slashes \ !
console.java uses also the three clases consoleCR.java, consoleDM.java and consoleROW.java.
javaw -cp "C:\jVakt\bin;C:\workspace\postgresql-9.4.1211.jar" Jvakt.console
console2html creates a html file with the status.
The file console.properties is read and the following parameters need to be present:
database = Jvakt
dbuser = console
dbpassword = pw
dbhost = localhost
dbport = 5433
jvhost = 127.0.0.1
jvport = 1956
java -cp "C:\jVakt\bin;C:\workspace\postgresql-9.4.1211.jar" Jvakt.console2html
Used to let mail information into Jvakt and make it appear in the console and/or trigger a SMS text message.
java -cp C:\Jvakt;C:\Jvakt\jakarta.activation-api-2.0.0.jar;C:\Jvakt\jakarta.mail-2.0.0.jar Jvakt.GetMail2Jvakt -config C:\Mail2Jvakt
The parameters and their meaning are:
-config The dir of the input files. Like: "-dir c:\Temp"
-norun To turn of the status update to Jvakt server. Mainly for test.
-nomailcheck Do not read an analyze the mails. Only log-on the mail server to verify it is possible.
-id Creates an ID in the Jvakt server showing the status of the mail server. OK when able to log-on, ERR when not.
-show Show a verbose log.
It's usually started from the basejobs.cmd.
Use it by sending a mail to the mail account as seen in the Jvakt.properties file in the smtpuser parameter.
What you write in the Subject field will appear as one line in the console.
If you enter the string SMS: in the subject field the mail will be regarded as a high prio message.
The messages will be SMS'ed to the phones in the "toSMS" parameter list found in the jVakt.properties file.
Note the senders property in the Jvakt.properties file!
senders contain comma separated strings that must be found in the senders address to be accepted by GetMail2Jvakt.
senders=* allows all senders, Default is no sender is accepted.
Example: senders=@domain.com,@domain.se,user1.name,user2.name
If none of the strings in the list is found in the from field, Jvakt will disregard the mail.
Note the exsubjects property in the Jvakt.properties file!
exsubjects contain comma separated strings that must NOT found in the subject it body of the mail.
Example: exsubjects=Automatic reply,vacation
If any of the strings in the list is found in the subject field, Jvakt will disregard the mail.
This to mitigate the risk of spam in Jvakt.
The normal and high prio mail creates two entries in the status table. MAIL_2_Jvakt and MAIL_2_Jvakt_Prio.
To disable or change the prio or type start the consoleSts program by press F6 in the console.
From here you can change the state to I to inactivate the function or maybe change the prio to 5 to force the SMS even during the night.
I recomend to change type to T on both and the prio on MAIL_2_Jvakt_Prio to be 29 or lesser.
If the type remains I the entry will be removed by the housekeeping routine.
GetMail2Jvakt can also be used to monitor the availability to an email server. It try to log in the the server using the imap protocoll and then logs out again without opening any mail.
To use GetMail2Jvakt in this way add the -id parameter and the -nomailcheck parameter to the command line.
Used to check a mailbox for expected and unexpected mails, good or bad.
java -cp C:\Jvakt;C:\Jvakt\jakarta.activation-api-2.0.0.jar;C:\Jvakt\jakarta.mail-2.0.0.jar Jvakt.SearchMail -config C:\Mail2Jvakt
The parameters and their meaning are:
-config The dir of the input files. Like: "-dir c:\Jvakt\SearchMail"
The files SearchMail-01.csv and the Jvakt.properties file will be read from the config folder.
The SearchMail-01.csv file contains a number of parameters separated by a semicolon.
ID;M or O;D or S;G or B;Sender;Subject;Body;
ID field: Used in to identify the checkpoint.
M or O field: Use M in situations where you require for a mail to be present, for instance as a reply from a mail echo server.
When you use M and the mail is missing an error is reported to the Jvakt server. When found an OK is reported.
Use O in situations where a missing mail is good.
D or S field: Use D if you want the found mail to be deleted from the mailbox.
Use S to mark it as seen.
G or B field: Use G if the mail searched for is considered good and B if it is a bad mail.
This for the program to know when to issue a good or bad report to the Jvakt server.
Sender field: Used to identify the mail. Enter a string to search for of the sender of the mail.
Subject field: Used to identify the mail. Enter a string to search for in the subject of the mail.
Body field: Used to identify the mail. Enter a string to search for in the body and attached text files of the mail.
Sender, subject and body hits must be made to consider the mail found and a report to be made.
If sender, subject and body is empty they are considered a hit by default.
I.e. The ..;UPS-BY892;;; creates a search for a mail with UPS-BY892 somewhere in the name of the sender with any text in the subject and body.
Begining of example SearchMail-01.csv
MAIL_From_Diesel_Generator;O;S;G;UPS_Notification;Motos is stopped;;
MAIL_From_Diesel_Generator;O;S;G;UPS_Notification;Auto mode Ready;;
MAIL_From_Diesel_Generator;O;S;B;UPS_Notification;;;
MAIL_From_Diesel_Generator;O;S;B;UPS_Notification;;Error;
MAIL_SUNET.SE_Echo;M;D;G;@sunet.se;Echo from;;
End of example SearchMail-01.csv
It need the jVakt.properties file.
The values read from the Jvakt.properties file are:
jvport
jvhost
jvport
smtpuser
smtppwd
imaphost
imapport
imapssl
imaprw
imapFolder