-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconsole2html.java
More file actions
228 lines (202 loc) · 8.14 KB
/
console2html.java
File metadata and controls
228 lines (202 loc) · 8.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package Jvakt;
/*
* 2025-06-09 V.75 Michael Ekdal Changed the order of the createStatement to accomodate changes in postgresql-42.7.6.jar
* 2022-07-02 V.54 Michael Ekdal Added getVersion() to get at consistent version throughout all classes.
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.sql.*;
import java.util.*;
import java.util.Date;
public class console2html {
// static Vector map = new Vector(100,10);
static Date now;
static String DBUrl = "jdbc:postgresql://localhost:5433/Jvakt";
// static ResultSet rs;
static Connection conn = null;
static boolean swDelete;
static boolean swTiming;
static boolean swShDay; // set when the scheduled day is active
static java.sql.Date zDate;
static java.sql.Timestamp zD;
static java.sql.Timestamp zTs;
static java.sql.Time zT;
static Long lhou, lmin, Lsec, Lrptdat, Lchktim;
static int errors = 0;
static int warnings = 0;
static int infos = 0;
static String version = "CheckStatus ";
static String database = "Jvakt";
static String dbuser = "console";
static String dbpassword = "";
static String dbhost = "localhost";
static String dbport = "5433";
static String jvhost = "localhost";
static String jvport = "1956";
static int port ;
static String agent = null;
static String config = null;
static File configF;
public static void main (String[] args) throws IOException, UnknownHostException
{
version += getVersion()+".55";
now = new Date();
for (int i=0; i<args.length; i++) {
if (args[i].equalsIgnoreCase("-config")) config = args[++i];
}
if (config == null ) configF = new File("console.properties");
else configF = new File(config,"console.properties");
// System.out.println("----- Jvakt: "+now+" version: "+version);
// System.out.println("-config file: "+configF);
getProps();
DBUrl = "jdbc:postgresql://"+dbhost+":"+dbport+"/"+database;
String head = "<html><head> <TITLE>jVakt - CONSOLE - System Status</TITLE> <meta http-equiv=\"refresh\" content=\"60\"> </head> <body bgcolor=\"silver\">";
String foot = "</body></html>";
// String tblStr = "<TABLE COLS=7 BORDER=8 cellpadding=\"5\" width=\"100%\" >";
String tblStr = "<TABLE COLS=6 BORDER=8 cellpadding=\"5\" width=\"100%\" >";
String tblEnd = "</TABLE>";
// String tblHdr = "<TH>Count</TH> <TH>Id</TH> <TH>Prio</TH> <TH>Type</TH> <TH>Condat</TH> <TH>Status</TH> <TH>Body - "+ now +" </TH> <TH>Agent</TH>";
String tblHdr = "<TH>Id</TH> <TH>Prio</TH> <TH>Type</TH> <TH>Credat</TH> <TH>Status</TH> <TH>Body - "+ now +" </TH> <TH>Agent</TH>";
String hdrStrG = "<TH BGCOLOR=\"#00FF00\"><FONT SIZE=5>"; // Green
String hdrStrY = "<TH BGCOLOR=\"#FFFF00\"><FONT SIZE=5>"; // Yellow
String hdrStrR = "<TH BGCOLOR=\"#FF6600\"><FONT SIZE=5>"; // Red
String hdrStrM = "<TH BGCOLOR=\"#FF00FF\"><FONT SIZE=5>"; // Magenta
String hdrStrB = "<TH BGCOLOR=\"#CCEEFF\"><FONT SIZE=5>"; // Light blue
String hdrEnd = "</TH>";
String rowStr = "<TR>";
String rowEnd = "</TR>";
String boxStrG = "<TD BGCOLOR=\"#3CB371\"><FONT SIZE=5>"; // MediumSeaGreen
// String boxStrG = "<TD BGCOLOR=\"#00FF00\"><FONT SIZE=5>"; // Green
String boxStrY = "<TD BGCOLOR=\"#FAFAD2\"><FONT SIZE=5>"; // LightGoldenRodYellow
// String boxStrY = "<TD BGCOLOR=\"#FFFF00\"><FONT SIZE=5>"; // Yellow
String boxStrR = "<TD BGCOLOR=\"#CD5C5C\"><FONT SIZE=5>"; // IndianRed
// String boxStrR = "<TD BGCOLOR=\"#FF6600\"><FONT SIZE=5>"; // Red
String boxStrM = "<TD BGCOLOR=\"#FF00FF\"><FONT SIZE=5>"; // Magenta
String boxStrB = "<TD BGCOLOR=\"#CCEEFF\"><FONT SIZE=5>"; // Light blue
String boxStrO = "<TD BGCOLOR=\"#FF8C00\"><FONT SIZE=5>"; // DarkOrange
String boxStr = "<TD><FONT SIZE=5>";
String boxEnd = "</FONT></TD>";
System.out.println (head);
System.out.println (tblStr);
System.out.println (tblHdr);
boolean swFound = false;
String query;
Statement stmt = null;
try {
Class.forName("org.postgresql.Driver").newInstance();
DBUrl = "jdbc:postgresql://"+dbhost+":"+dbport+"/"+database;
conn = DriverManager.getConnection(DBUrl,dbuser,dbpassword);
conn.setAutoCommit(true);
query = new String("select * from console order by credat desc;");
// stmt = conn.createStatement(ResultSet.CONCUR_UPDATABLE,ResultSet.TYPE_SCROLL_INSENSITIVE);
stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE,ResultSet.CLOSE_CURSORS_AT_COMMIT );
stmt.setFetchSize(1000);
ResultSet rs = stmt.executeQuery(query);
String value = "";
while (rs.next ()) {
swFound = true;
System.out.println (rowStr);
for (int i = 1; i <= 9; i++) {
if (i==1) continue; // not interested in showing count
if (i==5) continue; // not interested in showing condat
// if (i==6) continue; // not interested in showing credat
value = rs.getString (i);
if (rs.getInt("prio") < 30 && rs.getString("status").contentEquals("ERR")) System.out.println (boxStrM);
else if (rs.getInt("prio") >= 30 && rs.getString("status").contentEquals("ERR")) System.out.println (boxStrR);
else if (rs.getString("status").contentEquals("INFO")) System.out.println (boxStrY);
else if (rs.getString("status").startsWith("TOut")) System.out.println (boxStrO);
else if (rs.getString("status").contentEquals("OK")) System.out.println (boxStrG);
else System.out.println (boxStrB);
System.out.print (value);
System.out.println (boxEnd);
}
System.out.println (rowEnd);
}
// if (!swFound) {
// System.out.println (rowStr);
// System.out.println (boxStrG);
// System.out.println (" ");
// System.out.println (boxEnd);
// System.out.println (boxStrG);
// System.out.println (" ");
// System.out.println (boxEnd);
// System.out.println (boxStrG);
// System.out.println (" ");
// System.out.println (boxEnd);
// System.out.println (boxStrG);
// System.out.println (" ");
// System.out.println (boxEnd);
// System.out.println (boxStrG);
// System.out.println (" ");
// System.out.println (boxEnd);
// System.out.println (boxStrG);
// System.out.println (" ");
// System.out.println (boxEnd);
// System.out.println (boxStrG);
// System.out.println (" ");
// System.out.println (boxEnd);
// System.out.println (boxStrG);
// System.out.println (" ");
// System.out.println (boxEnd);
// System.out.println (rowEnd);
// }
}
catch (Exception e) {
System.out.println ();
System.out.println ("ERROR: " + e.getMessage());
}
finally {
// Clean up.
try {
if (conn != null)
conn.close ();
}
catch (SQLException e) {
// Ignore.
}
System.out.println (tblEnd);
System.out.println (foot);
}
System.exit (0);
}
static void getProps() {
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream(configF);
prop.load(input);
// get the property value and print it out
database = prop.getProperty("database");
dbuser = prop.getProperty("dbuser");
dbpassword = prop.getProperty("dbpassword");
if (dbpassword.startsWith("==y")) {
byte[] decodedBytes = Base64.getDecoder().decode(dbpassword.substring(3));
String decodedString = new String(decodedBytes);
dbpassword=decodedString;
}
dbhost = prop.getProperty("dbhost");
dbport = prop.getProperty("dbport");
jvport = prop.getProperty("jvport");
jvhost = prop.getProperty("jvhost");
input.close();
} catch (IOException ex) {
// ex.printStackTrace();
}
}
static private String getVersion() {
String version = "0";
try {
Class<?> c1 = Class.forName("Jvakt.Version",false,ClassLoader.getSystemClassLoader());
Version ver = new Version();
version = ver.getVersion();
}
catch (java.lang.ClassNotFoundException ex) {
version = "?";
}
return version;
}
}