42 |
public String lat; |
public String lat; |
43 |
public String lng; |
public String lng; |
44 |
} |
} |
45 |
|
|
46 |
|
class PositionContainer { |
47 |
|
List<RequestPosition> green = new ArrayList<RequestPosition>(); |
48 |
|
List<RequestPosition> yellow = new ArrayList<RequestPosition>(); |
49 |
|
List<RequestPosition> red = new ArrayList<RequestPosition>(); |
50 |
|
} |
51 |
|
|
52 |
|
|
53 |
boolean isGz(String fileStr) { |
boolean isGz(String fileStr) { |
54 |
return fileStr.substring(fileStr.length() - 3).equals(".gz"); |
return fileStr.substring(fileStr.length() - 3).equals(".gz"); |
55 |
} |
} |
56 |
|
|
57 |
protected List<RequestPosition> getRequestsFromFileWorker(boolean multiple) throws IOException{ |
protected PositionContainer getRequestsFromFileWorker(boolean multiple) throws IOException{ |
58 |
List<RequestPosition> positions = new ArrayList<RequestPosition>(); |
PositionContainer positions = new PositionContainer(); |
59 |
|
|
60 |
try { |
try { |
61 |
String files_single[] = {"/var/log/apache2/app_access.log"}; |
String files_single[] = {"/var/log/apache2/app_access.log"}; |
70 |
} |
} |
71 |
|
|
72 |
SimpleDateFormat df = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss"); |
SimpleDateFormat df = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss"); |
73 |
|
|
74 |
|
Date now = new Date(); |
75 |
for (String fileStr : files ) { |
for (String fileStr : files ) { |
76 |
File f = new File(fileStr); |
File f = new File(fileStr); |
77 |
if ( !f.exists() ) { |
if ( !f.exists() ) { |
117 |
|
|
118 |
pos.lat = args[0].split("=")[1]; |
pos.lat = args[0].split("=")[1]; |
119 |
pos.lng = args[1].split("=")[1]; |
pos.lng = args[1].split("=")[1]; |
120 |
|
|
121 |
|
|
122 |
|
long timediff = now.getTime() - pos.time.getTime(); |
123 |
|
if ( timediff < (3*60*60*1000) ) { |
124 |
|
positions.red.add(pos); //RED |
125 |
|
} else if ( timediff < (24*60*60*1000)) { |
126 |
|
positions.yellow.add(pos); //YELLOW |
127 |
|
} else { |
128 |
|
positions.green.add(pos); //GREEN |
129 |
|
} |
130 |
|
|
|
positions.add(pos); |
|
131 |
} |
} |
132 |
in.close(); |
in.close(); |
133 |
input.close(); |
input.close(); |
143 |
|
|
144 |
return positions; |
return positions; |
145 |
} |
} |
146 |
|
|
147 |
|
protected void formatPositions(StringBuilder sb, String color, List<RequestPosition> list) { |
148 |
|
sb.append( "<Folder>\n"); |
149 |
|
sb.append( " <name>" ).append(color).append("</name>\n"); |
150 |
|
sb.append( " <open>0</open>\n" ); |
151 |
|
sb.append( " <description>Count=").append(list.size()).append("</description>\n"); |
152 |
|
|
153 |
|
for(RequestPosition current : list) { |
154 |
|
sb.append( " <Placemark>\n" ); |
155 |
|
sb.append( " <styleUrl>#" + color + "</styleUrl>\n" ); |
156 |
|
sb.append( " <description>IP=" + current.ip + " Time=" + current.time + "</description>\n" ); |
157 |
|
sb.append( " <Point><coordinates>" + current.lng + "," + current.lat + ",0</coordinates></Point>\n" ); |
158 |
|
sb.append( " </Placemark>\n" ); |
159 |
|
} |
160 |
|
|
161 |
|
sb.append("</Folder>\n"); |
162 |
|
} |
163 |
|
|
164 |
protected String formatXml(List<RequestPosition> list) { |
protected String formatXml(PositionContainer positions) { |
165 |
StringBuilder sb = new StringBuilder(); |
StringBuilder sb = new StringBuilder(); |
166 |
|
|
167 |
sb.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
sb.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); |
200 |
*/ |
*/ |
201 |
|
|
202 |
|
|
203 |
final String STYLE_GREEN = "green"; |
formatPositions(sb, "green", positions.green); |
204 |
final String STYLE_YELLOW = "yellow"; |
formatPositions(sb, "yello", positions.yellow); |
205 |
final String STYLE_RED = "red"; |
formatPositions(sb, "red", positions.red); |
206 |
|
|
207 |
String oldstyle = null; |
|
|
Date now = new Date(); |
|
|
for(RequestPosition current : list) { |
|
|
|
|
|
String style; |
|
|
long timediff = now.getTime() - current.time.getTime(); |
|
|
|
|
|
if ( timediff < (3*60*60*1000) ) { |
|
|
style = STYLE_RED; |
|
|
} else if ( timediff < (24*60*60*1000)) { |
|
|
style = STYLE_YELLOW; |
|
|
} else { |
|
|
style = STYLE_GREEN; |
|
|
} |
|
|
|
|
|
if ( !style.equals(oldstyle) ) { |
|
|
if (oldstyle != null) |
|
|
sb.append( "</Folder>\n"); |
|
|
sb.append( "<Folder>\n"); |
|
|
sb.append( " <name>" ).append(style).append("</name>\n"); |
|
|
sb.append( " <open>0</open>\n" ); |
|
|
|
|
|
oldstyle = style; |
|
|
} |
|
|
|
|
|
sb.append( " <Placemark>\n" ); |
|
|
sb.append( " <styleUrl>#" + style + "</styleUrl>\n" ); |
|
|
sb.append( " <description>IP=" + current.ip + " Time=" + current.time + "</description>\n" ); |
|
|
sb.append( " <Point><coordinates>" + current.lng + "," + current.lat + ",0</coordinates></Point>\n" ); |
|
|
sb.append( " </Placemark>\n" ); |
|
|
} |
|
|
sb.append( "</Folder>\n" ); |
|
208 |
sb.append( "</Document>\n" ); |
sb.append( "</Document>\n" ); |
209 |
sb.append( "</kml>\n" ); |
sb.append( "</kml>\n" ); |
210 |
|
|