Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vernemq
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
stack
vernemq
Commits
a328920c
Commit
a328920c
authored
Nov 19, 2018
by
zCaesar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add broker count and fixed onoff
parent
daabfd9d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
3 deletions
+34
-3
authhook/auth_on_register.js
+2
-2
authhook/on_offline.js
+1
-1
authhook/redis/on_message.js
+13
-0
authhook/redis/on_offline.js
+9
-0
authhook/redis/on_register.js
+9
-0
No files found.
authhook/auth_on_register.js
View file @
a328920c
...
@@ -106,7 +106,7 @@ module.exports = function (options = {}) {
...
@@ -106,7 +106,7 @@ module.exports = function (options = {}) {
cache
.
set
(
cachekey
,
result
);
cache
.
set
(
cachekey
,
result
);
console
.
log
(
client_id
)
console
.
log
(
client_id
)
console
.
log
(
client_id
.
indexOf
(
'-'
))
console
.
log
(
client_id
.
indexOf
(
'-'
))
if
(
client_id
.
indexOf
(
'mqttjs
_
'
)
!==
-
1
)
{
if
(
client_id
.
indexOf
(
'mqttjs'
)
!==
-
1
)
{
res
.
send
({
res
.
send
({
"result"
:
result
?
"ok"
:
"no"
"result"
:
result
?
"ok"
:
"no"
});
});
...
@@ -124,7 +124,7 @@ module.exports = function (options = {}) {
...
@@ -124,7 +124,7 @@ module.exports = function (options = {}) {
});
});
}
}
else
{
else
{
if
(
client_id
.
indexOf
(
'mqttjs
_
'
)
!==
-
1
)
{
if
(
client_id
.
indexOf
(
'mqttjs'
)
!==
-
1
)
{
res
.
send
({
res
.
send
({
"result"
:
authstatus
?
"ok"
:
"no"
"result"
:
authstatus
?
"ok"
:
"no"
});
});
...
...
authhook/on_offline.js
View file @
a328920c
...
@@ -7,7 +7,7 @@ module.exports = function(options = {}) {
...
@@ -7,7 +7,7 @@ module.exports = function(options = {}) {
}
}
function
doRedis
(
client_id
)
{
function
doRedis
(
client_id
)
{
if
(
client_id
.
indexOf
(
'mqttjs_'
)
!
==
-
1
)
{
if
(
client_id
.
indexOf
(
'mqttjs_'
)
=
==
-
1
)
{
require
(
'./redis/on_offline'
).
on_offline_redis
(
client_id
).
then
(
status
=>
{
require
(
'./redis/on_offline'
).
on_offline_redis
(
client_id
).
then
(
status
=>
{
console
.
log
(
'redis:status: '
+
status
)
console
.
log
(
'redis:status: '
+
status
)
})
})
...
...
authhook/redis/on_message.js
View file @
a328920c
...
@@ -7,6 +7,11 @@ function on_message_redis(deviceid, payload) { // first time to access on authho
...
@@ -7,6 +7,11 @@ function on_message_redis(deviceid, payload) { // first time to access on authho
redis
.
hincrby
(
information
.
keys
,
'actual_message_count'
,
1
)
redis
.
hincrby
(
information
.
keys
,
'actual_message_count'
,
1
)
redis
.
hincrby
(
information
.
keys
,
'charged_message_count'
,
information
.
charged_message_count
)
redis
.
hincrby
(
information
.
keys
,
'charged_message_count'
,
information
.
charged_message_count
)
redis
.
hincrby
(
information
.
keys
,
'total_message_size'
,
information
.
total_message_size
)
redis
.
hincrby
(
information
.
keys
,
'total_message_size'
,
information
.
total_message_size
)
redis
.
hincrby
(
setBrokerValue
().
keys
,
'actual_message_count'
,
1
)
redis
.
hincrby
(
setBrokerValue
().
keys
,
'charged_message_count'
,
information
.
charged_message_count
)
redis
.
hincrby
(
setBrokerValue
().
keys
,
'total_message_size'
,
information
.
total_message_size
)
redis
.
hset
(
information
.
keys
,
'last_publish'
,
information
.
last_publish
,
function
(
err
,
res
)
{
redis
.
hset
(
information
.
keys
,
'last_publish'
,
information
.
last_publish
,
function
(
err
,
res
)
{
resolve
(
!
res
)
// 0 is ok, 1 is no => if ok is 0 then not 0 = 1
resolve
(
!
res
)
// 0 is ok, 1 is no => if ok is 0 then not 0 = 1
})
})
...
@@ -31,4 +36,11 @@ function setValue(deviceid, payload) {
...
@@ -31,4 +36,11 @@ function setValue(deviceid, payload) {
charged_message_count
:
charged_message_count
,
charged_message_count
:
charged_message_count
,
total_message_size
:
total_message_size
total_message_size
:
total_message_size
}
}
}
function
setBrokerValue
()
{
var
keys
=
'_broker:1'
return
{
keys
:
keys
}
}
}
\ No newline at end of file
authhook/redis/on_offline.js
View file @
a328920c
...
@@ -4,6 +4,7 @@ var redis = new Redis()
...
@@ -4,6 +4,7 @@ var redis = new Redis()
function
on_offline_redis
(
deviceid
)
{
// first time to access on authhook auth_on_register
function
on_offline_redis
(
deviceid
)
{
// first time to access on authhook auth_on_register
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
information
=
setValue
(
deviceid
)
var
information
=
setValue
(
deviceid
)
redis
.
hincrby
(
setBrokerValue
().
keys
,
'device_usage_count'
,
-
1
)
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'offline_on'
,
information
.
offline_on
,
function
(
err
,
res
)
{
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'offline_on'
,
information
.
offline_on
,
function
(
err
,
res
)
{
resolve
(
!
res
)
// 0 is ok, 1 is no => if ok is 0 then not 0 = 1
resolve
(
!
res
)
// 0 is ok, 1 is no => if ok is 0 then not 0 = 1
})
})
...
@@ -21,4 +22,11 @@ function setValue(deviceid) {
...
@@ -21,4 +22,11 @@ function setValue(deviceid) {
status
:
status
,
status
:
status
,
offline_on
:
offline_on
offline_on
:
offline_on
}
}
}
function
setBrokerValue
()
{
var
keys
=
'_broker:1'
return
{
keys
:
keys
}
}
}
\ No newline at end of file
authhook/redis/on_register.js
View file @
a328920c
...
@@ -5,6 +5,7 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_
...
@@ -5,6 +5,7 @@ function on_register_redis(deviceid) { // first time to access on authhook auth_
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
var
information
=
setValue
(
deviceid
)
var
information
=
setValue
(
deviceid
)
redis
.
hdel
(
information
.
keys
,
'offline_on'
)
redis
.
hdel
(
information
.
keys
,
'offline_on'
)
redis
.
hincrby
(
setBrokerValue
().
keys
,
'device_usage_count'
,
1
)
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'register_on'
,
information
.
register_on
,
'last_check'
,
information
.
last_check
,
function
(
err
,
res
)
{
redis
.
hset
(
information
.
keys
,
'status'
,
information
.
status
,
'register_on'
,
information
.
register_on
,
'last_check'
,
information
.
last_check
,
function
(
err
,
res
)
{
resolve
(
!
res
)
// 0 is ok, 1 is no => if ok is 0 then not 0 = 1
resolve
(
!
res
)
// 0 is ok, 1 is no => if ok is 0 then not 0 = 1
})
})
...
@@ -24,4 +25,11 @@ function setValue(deviceid) {
...
@@ -24,4 +25,11 @@ function setValue(deviceid) {
register_on
:
register_on
,
register_on
:
register_on
,
last_check
:
last_check
last_check
:
last_check
}
}
}
function
setBrokerValue
()
{
var
keys
=
'_broker:1'
return
{
keys
:
keys
}
}
}
\ 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