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
5bcd8e30
Commit
5bcd8e30
authored
Sep 08, 2017
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(LogDB): реализовал вывод html-странички со списком
log-серверов доступных для подключения через websocket
parent
dbfe112f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
4 deletions
+71
-4
LogDB.cc
extensions/LogDB/LogDB.cc
+65
-0
LogDB.h
extensions/LogDB/LogDB.h
+2
-0
logdb-conv.cc
extensions/LogDB/logdb-conv.cc
+3
-3
websocket-test.html
extensions/LogDB/websocket-test.html
+1
-1
No files found.
extensions/LogDB/LogDB.cc
View file @
5bcd8e30
...
@@ -641,6 +641,7 @@ void LogDB::handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPSer
...
@@ -641,6 +641,7 @@ void LogDB::handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPSer
using
Poco
::
Net
::
HTTPResponse
;
using
Poco
::
Net
::
HTTPResponse
;
std
::
ostream
&
out
=
resp
.
send
();
std
::
ostream
&
out
=
resp
.
send
();
resp
.
setContentType
(
"text/json"
);
resp
.
setContentType
(
"text/json"
);
try
try
...
@@ -661,6 +662,15 @@ void LogDB::handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPSer
...
@@ -661,6 +662,15 @@ void LogDB::handleRequest( Poco::Net::HTTPServerRequest& req, Poco::Net::HTTPSer
std
::
vector
<
std
::
string
>
seg
;
std
::
vector
<
std
::
string
>
seg
;
uri
.
getPathSegments
(
seg
);
uri
.
getPathSegments
(
seg
);
// проверка подключения к страничке со списком websocket-ов
if
(
seg
.
size
()
>=
1
&&
seg
[
0
]
==
"ws"
)
{
httpWebSocketPage
(
out
,
req
,
resp
);
out
.
flush
();
return
;
}
// example: http://host:port/api/version/logdb/..
// example: http://host:port/api/version/logdb/..
if
(
seg
.
size
()
<
4
if
(
seg
.
size
()
<
4
||
seg
[
0
]
!=
"api"
||
seg
[
0
]
!=
"api"
...
@@ -1258,5 +1268,60 @@ void LogDB::LogWebSocket::waitCompletion()
...
@@ -1258,5 +1268,60 @@ void LogDB::LogWebSocket::waitCompletion()
finish
.
wait
(
lk
);
finish
.
wait
(
lk
);
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void
LogDB
::
httpWebSocketPage
(
std
::
ostream
&
ostr
,
Poco
::
Net
::
HTTPServerRequest
&
req
,
Poco
::
Net
::
HTTPServerResponse
&
resp
)
{
using
Poco
::
Net
::
HTTPResponse
;
resp
.
setChunkedTransferEncoding
(
true
);
resp
.
setContentType
(
"text/html"
);
// code base on example from
// https://github.com/pocoproject/poco/blob/developNet/samples/WebSocketServer/src/WebSocketServer.cpp
ostr
<<
"<html>"
<<
endl
;
ostr
<<
"<head>"
<<
endl
;
ostr
<<
"<title>"
<<
myname
<<
" log servers list</title>"
<<
endl
;
ostr
<<
"<script type=
\"
text/javascript
\"
>"
<<
endl
;
ostr
<<
"function WebSocketCreate(logname)"
<<
endl
;
ostr
<<
"{"
<<
endl
;
ostr
<<
" if (
\"
WebSocket
\"
in window)"
<<
endl
;
ostr
<<
" {"
<<
endl
;
ostr
<<
" var ws = new WebSocket(
\"
ws://"
<<
req
.
serverAddress
().
toString
()
<<
"/logdb/ws/
\"
+ logname);"
<<
endl
;
ostr
<<
" var l = document.getElementById('logname');"
<<
endl
;
ostr
<<
" l.innerHTML = logname"
<<
endl
;
ostr
<<
" ws.onmessage = function(evt)"
<<
endl
;
ostr
<<
" {"
<<
endl
;
ostr
<<
" var p = document.getElementById('logs');"
<<
endl
;
ostr
<<
" if( evt.data != '.' ) {"
<<
endl
;
ostr
<<
" p.innerHTML = p.innerHTML +
\"
</br>
\"
+evt.data"
<<
endl
;
ostr
<<
" }"
<<
endl
;
ostr
<<
" };"
<<
endl
;
ostr
<<
" ws.onclose = function()"
<<
endl
;
ostr
<<
" { "
<<
endl
;
ostr
<<
" alert(
\"
WebSocket closed.
\"
);"
<<
endl
;
ostr
<<
" };"
<<
endl
;
ostr
<<
" }"
<<
endl
;
ostr
<<
" else"
<<
endl
;
ostr
<<
" {"
<<
endl
;
ostr
<<
" alert(
\"
This browser does not support WebSockets.
\"
);"
<<
endl
;
ostr
<<
" }"
<<
endl
;
ostr
<<
"}"
<<
endl
;
ostr
<<
"</script>"
<<
endl
;
ostr
<<
"</head>"
<<
endl
;
ostr
<<
"<body>"
<<
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
<<
"<div id='logs'></div>"
<<
endl
;
ostr
<<
"</body>"
<<
endl
;
}
// -----------------------------------------------------------------------------
#endif
#endif
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
extensions/LogDB/LogDB.h
View file @
5bcd8e30
...
@@ -130,6 +130,7 @@ namespace uniset
...
@@ -130,6 +130,7 @@ namespace uniset
\todo WebSocket: сделать ограничение на максимальное количество соединений
\todo WebSocket: сделать ограничение на максимальное количество соединений
\todo utils: написать конвертор обычных uniset-логов в БД.
\todo utils: написать конвертор обычных uniset-логов в БД.
\todo db: возможно всё-таки стоит парсить логи на предмет loglevel, и тогда уж и дату с временем вынимать
\todo db: возможно всё-таки стоит парсить логи на предмет loglevel, и тогда уж и дату с временем вынимать
\todo web: генерировать html-страничку со списком подключения к логам с использованием готового шаблона
*/
*/
class
LogDB
:
class
LogDB
:
public
EventLoopServer
public
EventLoopServer
...
@@ -180,6 +181,7 @@ namespace uniset
...
@@ -180,6 +181,7 @@ namespace uniset
Poco
::
JSON
::
Object
::
Ptr
httpGetList
(
const
Poco
::
URI
::
QueryParameters
&
p
);
Poco
::
JSON
::
Object
::
Ptr
httpGetList
(
const
Poco
::
URI
::
QueryParameters
&
p
);
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
);
// формирование условия where для строки XX[m|h|d|M]
// формирование условия where для строки XX[m|h|d|M]
// XX m - минут, h-часов, d-дней, M - месяцев
// XX m - минут, h-часов, d-дней, M - месяцев
...
...
extensions/LogDB/logdb-conv.cc
View file @
5bcd8e30
...
@@ -105,12 +105,12 @@ LogInfo makeLogInfo( const std::string& name )
...
@@ -105,12 +105,12 @@ LogInfo makeLogInfo( const std::string& name )
void
parseLine
(
SQLiteInterface
*
db
,
const
LogInfo
&
loginfo
,
const
std
::
string
&
line
)
void
parseLine
(
SQLiteInterface
*
db
,
const
LogInfo
&
loginfo
,
const
std
::
string
&
line
)
{
{
// 28/07/2017 10:55:19( info):
QG3(AutomatTransientMode): ждем отключения автомата
// 28/07/2017 10:55:19( info):
text...text...more text
static
const
std
::
regex
re
(
"[::space::]{0,}"
static
const
std
::
regex
re
(
"[::space::]{0,}"
"(
\\
d{2})[/-]{1}(
\\
d{2})[/-]{1}(
\\
d{4})"
"(
\\
d{2})[/-]{1}(
\\
d{2})[/-]{1}(
\\
d{4})"
//date
" "
" "
"(
\\
d{2}:
\\
d{2}:
\\
d{2})"
"(
\\
d{2}:
\\
d{2}:
\\
d{2})"
// time
// "(.*)$"
// "(.*)$"
);
);
...
...
extensions/LogDB/websocket-test.html
View file @
5bcd8e30
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
// ws.send("Hello, world!");
// ws.send("Hello, world!");
// };
// };
ws
.
onmessage
=
ws
.
onmessage
=
function
(
evt
)
ws
.
onmessage
=
function
(
evt
)
{
{
var
p
=
document
.
getElementById
(
'logs'
);
var
p
=
document
.
getElementById
(
'logs'
);
if
(
evt
.
data
!=
'.'
)
{
if
(
evt
.
data
!=
'.'
)
{
...
...
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