Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ipgallery
/
devops
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Registry
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a21490d3
authored
Dec 10, 2017
by
Amir Aharon
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
adjust to docker
parent
030d176e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
12 deletions
tools/wsEventEmulator/app.js
tools/wsEventEmulator/app.js
View file @
a21490d3
...
...
@@ -9,7 +9,23 @@ const request = require('request');
var
myArgs
=
require
(
'optimist'
).
argv
,
help
=
'node app.js -p port -f file-path [-d delay-between-samples --postUrl http url to post instead of websocket]'
;
var
config
=
{};
//const twoDaysAgoMs = 1000 * 3600 * 47;
/**
* getting configuration either from command args or from env
*/
var
getConfiguration
=
function
(){
myArgs
.
f
?
config
.
file
=
myArgs
.
f
:
config
.
file
=
process
.
env
.
file
;
myArgs
.
p
?
config
.
port
=
myArgs
.
p
:
config
.
port
=
8053
;
// default port
myArgs
.
d
?
config
.
delay
=
myArgs
.
d
:
config
.
delay
=
process
.
env
.
delay
;
myArgs
.
postUrl
?
config
.
postUrl
=
myArgs
.
postUrl
:
config
.
postUrl
=
process
.
env
.
postUrl
;
console
.
log
(
"Configuration is: "
+
JSON
.
stringify
(
config
));
};
/**
* some validation
...
...
@@ -18,18 +34,19 @@ if ((myArgs.h)||(myArgs.help)) {
console
.
log
(
help
);
process
.
exit
(
0
);
}
if
(
myArgs
.
f
==
null
){
getConfiguration
();
if
(
config
.
file
==
null
){
console
.
log
(
'please insert file path'
);
process
.
exit
(
0
);
}
if
(
myArgs
.
d
>
0
){
if
(
config
.
delay
&&
config
.
delay
>
0
){
rule
=
new
schedule
.
RecurrenceRule
();
rule
.
second
=
myArgs
.
d
;
rule
.
second
=
config
.
delay
;
rule
.
minute
=
0
;
}
console
.
log
(
'myArgs: '
,
myArgs
);
const
app
=
express
();
app
.
use
(
function
(
req
,
res
)
{
...
...
@@ -104,13 +121,13 @@ var sendJson = function(){
var
newEventObj
=
JSON
.
parse
(
JSON
.
stringify
(
eventObj
))
normalyzeEvent
(
newEventObj
);
console
.
log
(
"sending: "
+
JSON
.
stringify
(
newEventObj
));
if
(
myArgs
.
postUrl
==
null
){
if
(
config
.
postUrl
==
null
){
if
(
client
.
readyState
===
WebSocket
.
OPEN
)
{
client
.
send
(
JSON
.
stringify
(
newEventObj
));
}
}
else
{
request
.
post
({
url
:
myArgs
.
postUrl
,
url
:
config
.
postUrl
,
headers
:
{
"Content-Type"
:
"application/json"
},
...
...
@@ -126,10 +143,10 @@ var sendJson = function(){
index
=
++
index
%
jsonFile
.
length
;
}
fs
.
readFile
(
myArgs
.
f
,
(
err
,
data
)
=>
{
fs
.
readFile
(
config
.
file
,
(
err
,
data
)
=>
{
if
(
err
)
throw
err
;
jsonFile
=
JSON
.
parse
(
data
);
console
.
log
(
'finished reading: '
+
myArgs
.
f
);
console
.
log
(
'finished reading: '
+
config
.
file
);
});
wss
.
on
(
'connection'
,
function
connection
(
ws
,
req
)
{
...
...
@@ -139,8 +156,8 @@ wss.on('connection', function connection(ws, req) {
ws
.
on
(
'message'
,
function
incoming
(
message
)
{
console
.
log
(
'received: %s'
,
message
);
if
(
myArgs
.
d
>
0
){
var
j
=
schedule
.
scheduleJob
(
'*/'
+
myArgs
.
d
+
' * * * * * *'
,
sendJson
);
if
(
config
.
delay
>
0
){
var
j
=
schedule
.
scheduleJob
(
'*/'
+
config
.
delay
+
' * * * * * *'
,
sendJson
);
}
else
{
client
.
send
(
JSON
.
stringify
(
jsonFile
));
}
...
...
@@ -149,7 +166,7 @@ wss.on('connection', function connection(ws, req) {
});
server
.
listen
(
myArgs
.
p
,
function
listening
()
{
server
.
listen
(
config
.
port
,
function
listening
()
{
console
.
log
(
'Listening on %d'
,
server
.
address
().
port
);
});
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