Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
c87861f3
Commit
c87861f3
authored
Sep 08, 2017
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(LogDB): разделил вывод странички со списком и собственно подключение к web-сокету.
parent
5bcd8e30
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
61 deletions
+53
-61
logserver.cc
Utilities/ULog/logserver.cc
+2
-1
test.xml
conf/test.xml
+2
-2
LogDB.cc
extensions/LogDB/LogDB.cc
+43
-12
LogDB.h
extensions/LogDB/LogDB.h
+6
-1
websocket-test.html
extensions/LogDB/websocket-test.html
+0
-45
No files found.
Utilities/ULog/logserver.cc
View file @
c87861f3
...
@@ -234,7 +234,7 @@ int main( int argc, char** argv )
...
@@ -234,7 +234,7 @@ int main( int argc, char** argv )
{
{
if
(
!
silent
)
if
(
!
silent
)
{
{
dlog
->
any
()
<<
"["
<<
++
i
<<
"] Test message for log"
<<
endl
;
dlog
->
any
()
<<
"["
<<
++
i
<<
"] Test message for log
(русский текст)
"
<<
endl
;
dlog
->
info
()
<<
": dlog : INFO message"
<<
endl
;
dlog
->
info
()
<<
": dlog : INFO message"
<<
endl
;
dlog
->
warn
()
<<
": dlog : WARN message"
<<
endl
;
dlog
->
warn
()
<<
": dlog : WARN message"
<<
endl
;
dlog
->
crit
()
<<
": dlog : CRIT message"
<<
endl
;
dlog
->
crit
()
<<
": dlog : CRIT message"
<<
endl
;
...
@@ -250,6 +250,7 @@ int main( int argc, char** argv )
...
@@ -250,6 +250,7 @@ int main( int argc, char** argv )
dlog4
->
info
()
<<
": dlog4: INFO message"
<<
endl
;
dlog4
->
info
()
<<
": dlog4: INFO message"
<<
endl
;
dlog4
->
warn
()
<<
": dlog4: WARN message"
<<
endl
;
dlog4
->
warn
()
<<
": dlog4: WARN message"
<<
endl
;
dlog4
->
crit
()
<<
": dlog4: CRIT message"
<<
endl
;
dlog4
->
crit
()
<<
": dlog4: CRIT message"
<<
endl
;
}
}
msleep
(
delay
);
msleep
(
delay
);
...
...
conf/test.xml
View file @
c87861f3
...
@@ -40,8 +40,8 @@
...
@@ -40,8 +40,8 @@
<LogServer
name=
"smplus"
port=
"3333"
host=
"localhost"
/>
<LogServer
name=
"smplus"
port=
"3333"
host=
"localhost"
/>
<LogDB
name=
"LogDB"
>
<LogDB
name=
"LogDB"
>
<logserver
name=
"logserver1"
ip=
"localhost"
port=
"3333"
cmd=
"-s level1"
description=
"
SES log
"
/>
<logserver
name=
"logserver1"
ip=
"localhost"
port=
"3333"
cmd=
"-s level1"
description=
"
Лог сервер процесса управления N1
"
/>
<logserver
name=
"logserver2"
ip=
"localhost"
port=
"3333"
cmd=
""
description=
"
GEU log
"
/>
<logserver
name=
"logserver2"
ip=
"localhost"
port=
"3333"
cmd=
""
description=
"
Лог сервер процесса управления N2
"
/>
</LogDB>
</LogDB>
<settings>
<settings>
...
...
extensions/LogDB/LogDB.cc
View file @
c87861f3
...
@@ -663,8 +663,16 @@ void LogDB::handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPSer
...
@@ -663,8 +663,16 @@ void LogDB::handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPSer
uri
.
getPathSegments
(
seg
);
uri
.
getPathSegments
(
seg
);
// проверка подключения к страничке со списком websocket-ов
// проверка подключения к страничке со списком websocket-ов
if
(
seg
.
size
()
>
=
1
&&
seg
[
0
]
==
"ws"
)
if
(
seg
.
size
()
>
1
&&
seg
[
0
]
==
"logdb"
&&
seg
[
1
]
==
"ws"
)
{
{
// подключение..
if
(
seg
.
size
()
>
2
)
{
httpWebSocketConnectPage
(
out
,
req
,
resp
,
seg
[
2
]);
return
;
}
// default page
httpWebSocketPage
(
out
,
req
,
resp
);
httpWebSocketPage
(
out
,
req
,
resp
);
out
.
flush
();
out
.
flush
();
return
;
return
;
...
@@ -1275,12 +1283,44 @@ void LogDB::httpWebSocketPage( std::ostream& ostr, Poco::Net::HTTPServerRequest&
...
@@ -1275,12 +1283,44 @@ void LogDB::httpWebSocketPage( std::ostream& ostr, Poco::Net::HTTPServerRequest&
resp
.
setChunkedTransferEncoding
(
true
);
resp
.
setChunkedTransferEncoding
(
true
);
resp
.
setContentType
(
"text/html"
);
resp
.
setContentType
(
"text/html"
);
ostr
<<
"<html>"
<<
endl
;
ostr
<<
"<head>"
<<
endl
;
ostr
<<
"<title>"
<<
myname
<<
": log servers list</title>"
<<
endl
;
ostr
<<
"<meta http-equiv=
\"
Content-Type
\"
content=
\"
text/html; charset=UTF-8
\"
>"
<<
endl
;
ostr
<<
"</head>"
<<
endl
;
ostr
<<
"<body>"
<<
endl
;
ostr
<<
"<h1>servers:</h1>"
<<
endl
;
ostr
<<
"<ul>"
<<
endl
;
for
(
const
auto
&
l
:
logservers
)
{
ostr
<<
" <li><a target='_blank' href=
\"
http://"
<<
req
.
serverAddress
().
toString
()
<<
"/logdb/ws/"
<<
l
->
name
<<
"
\"
>"
<<
l
->
name
<<
"</a> – "
<<
"<i>"
<<
l
->
description
<<
"</i></li>"
<<
endl
;
}
ostr
<<
"</ul>"
<<
endl
;
ostr
<<
"</body>"
<<
endl
;
}
// -----------------------------------------------------------------------------
void
LogDB
::
httpWebSocketConnectPage
(
ostream
&
ostr
,
Poco
::
Net
::
HTTPServerRequest
&
req
,
Poco
::
Net
::
HTTPServerResponse
&
resp
,
const
std
::
string
&
logname
)
{
resp
.
setChunkedTransferEncoding
(
true
);
resp
.
setContentType
(
"text/html"
);
// code base on example from
// code base on example from
// https://github.com/pocoproject/poco/blob/developNet/samples/WebSocketServer/src/WebSocketServer.cpp
// https://github.com/pocoproject/poco/blob/developNet/samples/WebSocketServer/src/WebSocketServer.cpp
ostr
<<
"<html>"
<<
endl
;
ostr
<<
"<html>"
<<
endl
;
ostr
<<
"<head>"
<<
endl
;
ostr
<<
"<head>"
<<
endl
;
ostr
<<
"<title>"
<<
myname
<<
" log servers list</title>"
<<
endl
;
ostr
<<
"<title>"
<<
myname
<<
" log '"
<<
logname
<<
"'</title>"
<<
endl
;
ostr
<<
"<meta http-equiv=
\"
Content-Type
\"
content=
\"
text/html; charset=UTF-8
\"
>"
<<
endl
;
ostr
<<
"<script type=
\"
text/javascript
\"
>"
<<
endl
;
ostr
<<
"<script type=
\"
text/javascript
\"
>"
<<
endl
;
ostr
<<
"function WebSocketCreate(logname)"
<<
endl
;
ostr
<<
"function WebSocketCreate(logname)"
<<
endl
;
ostr
<<
"{"
<<
endl
;
ostr
<<
"{"
<<
endl
;
...
@@ -1308,16 +1348,7 @@ void LogDB::httpWebSocketPage( std::ostream& ostr, Poco::Net::HTTPServerRequest&
...
@@ -1308,16 +1348,7 @@ void LogDB::httpWebSocketPage( std::ostream& ostr, Poco::Net::HTTPServerRequest&
ostr
<<
"}"
<<
endl
;
ostr
<<
"}"
<<
endl
;
ostr
<<
"</script>"
<<
endl
;
ostr
<<
"</script>"
<<
endl
;
ostr
<<
"</head>"
<<
endl
;
ostr
<<
"</head>"
<<
endl
;
ostr
<<
"<body>"
<<
endl
;
ostr
<<
"<body onload=
\"
javascript:WebSocketCreate('"
<<
logname
<<
"')
\"
>"
<<
endl
;
ostr
<<
" <h1>"
<<
myname
<<
" WebSocket Server:</h1>"
<<
endl
;
ostr
<<
"<ul>"
<<
endl
;
for
(
const
auto
&
l
:
logservers
)
ostr
<<
" <li><a href=
\"
javascript:WebSocketCreate('"
<<
l
->
name
<<
"')
\"
>"
<<
l
->
name
<<
"</a></li>"
<<
endl
;
ostr
<<
"</ul>"
<<
endl
;
ostr
<<
"<h4><div id='logname'></div></h4>"
<<
endl
;
ostr
<<
"<h4><div id='logname'></div></h4>"
<<
endl
;
ostr
<<
"<div id='logs'></div>"
<<
endl
;
ostr
<<
"<div id='logs'></div>"
<<
endl
;
ostr
<<
"</body>"
<<
endl
;
ostr
<<
"</body>"
<<
endl
;
...
...
extensions/LogDB/LogDB.h
View file @
c87861f3
...
@@ -106,7 +106,11 @@ namespace uniset
...
@@ -106,7 +106,11 @@ namespace uniset
\section sec_LogDB_WEBSOCK LogDB Поддержка web socket
\section sec_LogDB_WEBSOCK LogDB Поддержка web socket
В LogDB встроена возможность realtime чтения логов, через websocket.
В LogDB встроена возможность realtime чтения логов, через websocket.
Подключение (создание) сокета происходит по адресу
Список доступных для подключения лог-серверов доступен по адресу:
\code
ws://host:port/logdb/ws/
\endcode
Прямое подключение к websocket-у доступно по адресу:
\code
\code
ws://host:port/logdb/ws/logname
ws://host:port/logdb/ws/logname
\endcode
\endcode
...
@@ -182,6 +186,7 @@ namespace uniset
...
@@ -182,6 +186,7 @@ namespace uniset
Poco
::
JSON
::
Object
::
Ptr
httpGetLogs
(
const
Poco
::
URI
::
QueryParameters
&
p
);
Poco
::
JSON
::
Object
::
Ptr
httpGetLogs
(
const
Poco
::
URI
::
QueryParameters
&
p
);
Poco
::
JSON
::
Object
::
Ptr
httpGetCount
(
const
Poco
::
URI
::
QueryParameters
&
p
);
Poco
::
JSON
::
Object
::
Ptr
httpGetCount
(
const
Poco
::
URI
::
QueryParameters
&
p
);
void
httpWebSocketPage
(
std
::
ostream
&
out
,
Poco
::
Net
::
HTTPServerRequest
&
req
,
Poco
::
Net
::
HTTPServerResponse
&
resp
);
void
httpWebSocketPage
(
std
::
ostream
&
out
,
Poco
::
Net
::
HTTPServerRequest
&
req
,
Poco
::
Net
::
HTTPServerResponse
&
resp
);
void
httpWebSocketConnectPage
(
std
::
ostream
&
out
,
Poco
::
Net
::
HTTPServerRequest
&
req
,
Poco
::
Net
::
HTTPServerResponse
&
resp
,
const
std
::
string
&
logname
);
// формирование условия where для строки XX[m|h|d|M]
// формирование условия where для строки XX[m|h|d|M]
// XX m - минут, h-часов, d-дней, M - месяцев
// XX m - минут, h-часов, d-дней, M - месяцев
...
...
extensions/LogDB/websocket-test.html
deleted
100644 → 0
View file @
5bcd8e30
<html>
<!--
Base on example from
https://github.com/pocoproject/poco/blob/develop/Net/samples/WebSocketServer/src/WebSocketServer.cpp
-->
<head>
<title>
WebSocketServer
</title>
<script
type=
"text/javascript"
>
function
WebSocketTest
()
{
if
(
"WebSocket"
in
window
)
{
var
ws
=
new
WebSocket
(
"ws://localhost:8888/logdb/ws/logserver1"
);
// ws.onopen = function()
// {
// ws.send("Hello, world!");
// };
ws
.
onmessage
=
function
(
evt
)
{
var
p
=
document
.
getElementById
(
'logs'
);
if
(
evt
.
data
!=
'.'
)
{
p
.
innerHTML
=
p
.
innerHTML
+
"<p>"
+
evt
.
data
+
"</p>"
;
}
};
ws
.
onclose
=
function
()
{
alert
(
"WebSocket closed."
);
};
}
else
{
alert
(
"This browser does not support WebSockets."
);
}
}
</script>
</head>
<body>
<h1>
Test uniset logdb websocket
</h1>
<p><a
href=
"javascript:WebSocketTest()"
>
Connect to 'logserver1'
</a></p>
<div
id=
"logs"
></div>
</body>
</html>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment