-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.html
190 lines (184 loc) · 6.54 KB
/
log.html
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
<!DOCTYPE html>
<meta charset="utf-8" />
<title>日志查看-测试版</title>
<style type="text/css">
a:link { text-decoration: none;color: blue}
a:active { text-decoration:blink}
a:hover { text-decoration:underline;color: red}
a:visited { text-decoration: none;color: green}
</style>
<script language="javascript"type="text/javascript">
var wsUri = "ws://"+window.location.host+"/readlog/wsapi"
var output;
var websocket = new WebSocket(wsUri);
function scroll_message(){
if (document.getElementById("scroll").value=="停止滚动"){
document.getElementById("scroll").value="开始滚动";
}else{
document.getElementById("scroll").value="停止滚动";
}
}
function load_list(){
var httpRequest = new XMLHttpRequest();
httpRequest.open('GET', '/readlog/list', true);
httpRequest.send();
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
var json = httpRequest.responseText;
service_list.innerHTML=json;
}
};
}
function log_connect(data){
var type = data.type;
//testWebSocket();
var req = {};
req["service_type"]=data.type;
req["service_name"]=data.text;
output.innerHTML="";
websocket.send(JSON.stringify(req));
}
function log_docker(){
var req = {};
req["log_type"]="realtime";
document.getElementById("select_systemd").value="";
req["service_type"]="docker";
req["service_name"]=document.getElementById("select_docker").value;
req["since"]=document.getElementById("input_since").value.replace("T"," ");
req["until"]=document.getElementById("input_until").value.replace("T"," ");
req["grep"]=document.getElementById("input_grep").value;
req["lines"]=parseInt(document.getElementById("input_lines").value);
if (req["service_name"] == ""){
return
}
output.innerHTML="";
websocket.send(JSON.stringify(req));
}
function log_systemd(){
var req = {};
req["log_type"]="realtime";
document.getElementById("select_docker").value="";
req["service_type"]="systemd";
req["service_name"]=document.getElementById("select_systemd").value;
req["since"]=document.getElementById("input_since").value.replace("T"," ");
req["until"]=document.getElementById("input_until").value.replace("T"," ");
req["grep"]=document.getElementById("input_grep").value;
req["lines"]=parseInt(document.getElementById("input_lines").value);
if (req["service_name"] == ""){
return
}
output.innerHTML="";
websocket.send(JSON.stringify(req));
}
function history(){
var req = {};
req["log_type"]="history";
if (document.getElementById("select_docker").value != ""){
req["service_type"]="docker";
req["service_name"]=document.getElementById("select_docker").value;
}else if (document.getElementById("select_systemd").value != ""){
req["service_type"]="systemd";
req["service_name"]=document.getElementById("select_systemd").value;
}else{
alert("请选择服务");
}
req["since"]=document.getElementById("input_since").value;
req["until"]=document.getElementById("input_until").value;
req["grep"]=document.getElementById("input_grep").value;
req["lines"]=parseInt(document.getElementById("input_lines").value);
output.innerHTML="";
websocket.send(JSON.stringify(req));
}
function init() {
output = document.getElementById("output");
load_list();
testWebSocket();
}
function testWebSocket() {
websocket.binaryType = 'arraybuffer'
websocket.onopen = function(evt) {
websocket.send("0")
onOpen(evt)
};
websocket.onclose = function(evt) {
onClose(evt)
};
websocket.onmessage = function(evt) {
onMessage(evt)
};
websocket.onerror = function(evt) {
onError(evt)
};
}
function onOpen(evt) {
writeToScreen("CONNECTED");
//doSend("WebSocket rocks");
}
function onClose(evt) {
writeToScreen('<span style="color: red;">DISCONNECTED</span> ');
}
function onMessage(evt) {
//writeToScreen('<span style="color: blue;">'+ evt.data+'</span>');
writeToScreen(evt.data+"<br>");
//console.log(console.log(evt.data))
//writeToScreen('<span style="color: blue;">RESPONSE: '+ binaryData(evt)+'</span>');
//websocket.close();
}
function onError(evt) {
writeToScreen('<span style="color: red;">ERROR:</span> '+ evt.data);
}
function doSend(message) {
writeToScreen("SENT: " + message);
websocket.send(message);
}
function writeToScreen(message) {
//var pre = document.createElement("p");
//pre.style.wordWrap = "break-word";
var pre = document.createElement("span");
pre.style.color = "#C0C0C0";
pre.innerHTML = message;
output.appendChild(pre);
var children = output.childNodes;
//output1.innerHTML=children.length;
if(children.length>1000){
output.removeChild(output.firstChild);
}
if (document.getElementById("scroll").value=="停止滚动"){
output.scrollTop = output.scrollHeight;
}
}
function commandsend(){
message_data=document.getElementById("input1").value
//doSend(message_data)
doSend('{"type":"command", "data":"'+message_data+'"}')
}
function messagesend(){
message_data=document.getElementById("input2").value
doSend(message_data+'\r\n')
}
function insert_img(){
var bigImg = document.createElement("img");
bigImg.src = "QR.png";
output.appendChild(bigImg)
}
function closews(){
websocket.close();
}
window.addEventListener("load", init, false);
</script>
<h2>日志查看,仅限公司网络内使用,外部无法使用</h2>
<div id="output1">
<button type="button" onclick=closews()>断开ws</button>
<button type="button" onclick=openws() disabled=true>连接ws</button>
<br>
<!--
<input id='input2' type="text" size="30" name="input2" />
<button type="button" onclick=messagesend()>信息发送</button>
-->
<div>服务器列表:服务器1,服务器2,服务器3
<input id="scroll" type="button" value="停止滚动" onclick="scroll_message();"/>
</div>
<div id="service_list">
</div>
<div id="output" style="background:black;height:600px;width:1024px;resize:both;overflow:scroll;"></div><div id="output2"></div>
</html>