Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Turris
ucollect
Commits
24085ad0
Verified
Commit
24085ad0
authored
Dec 15, 2016
by
Michal 'vorner' Vaner
Browse files
Merge branch 'master' of git.nic.cz:turris/ucollect
parents
9ed48088
5912ff0a
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/master/bandwidth_plugin.py
View file @
24085ad0
...
...
@@ -169,35 +169,17 @@ def store_bandwidth(data, now):
if
not
cldata
.
buckets
:
continue
## Choose data structures according to protocol version
BUCKET_MAP
=
None
BUCKETS_CNT
=
None
if
cldata
.
version
<=
2
:
BUCKET_MAP
=
BUCKET_MAP_PROTO2
BUCKETS_CNT
=
BUCKETS_CNT_PROTO2
elif
cldata
.
version
>=
3
:
BUCKET_MAP
=
BUCKET_MAP_PROTO3
BUCKETS_CNT
=
BUCKETS_CNT_PROTO3
in_time
=
[
0
]
*
BUCKETS_CNT
in_bytes
=
[
0
]
*
BUCKETS_CNT
out_time
=
[
0
]
*
BUCKETS_CNT
out_bytes
=
[
0
]
*
BUCKETS_CNT
for
bucket
in
cldata
.
buckets
.
itervalues
():
pos
=
BUCKET_MAP
[
bucket
.
bucket
]
in_time
[
pos
]
=
bucket
.
in_time
in_bytes
[
pos
]
=
bucket
.
in_bytes
out_time
[
pos
]
=
bucket
.
out_time
out_bytes
[
pos
]
=
bucket
.
out_bytes
t
.
execute
(
"""SELECT client, timestamp, in_time, in_bytes, out_time, out_bytes
FROM bandwidth_stats
JOIN clients ON bandwidth_stats.client = clients.id
WHERE name = %s AND timestamp = date_trunc('hour', %s)
"""
,
(
client
,
now
))
result
=
t
.
fetchone
()
if
result
==
None
:
try
:
## Choose data structures according to protocol version
BUCKET_MAP
=
None
BUCKETS_CNT
=
None
if
cldata
.
version
<=
2
:
BUCKET_MAP
=
BUCKET_MAP_PROTO2
BUCKETS_CNT
=
BUCKETS_CNT_PROTO2
elif
cldata
.
version
>=
3
:
BUCKET_MAP
=
BUCKET_MAP_PROTO3
BUCKETS_CNT
=
BUCKETS_CNT_PROTO3
in_time
=
[
0
]
*
BUCKETS_CNT
in_bytes
=
[
0
]
*
BUCKETS_CNT
out_time
=
[
0
]
*
BUCKETS_CNT
...
...
@@ -210,30 +192,54 @@ def store_bandwidth(data, now):
out_time
[
pos
]
=
bucket
.
out_time
out_bytes
[
pos
]
=
bucket
.
out_bytes
t
.
execute
(
"""INSERT INTO bandwidth_stats (client, timestamp, in_time, in_bytes, out_time, out_bytes)
SELECT clients.id AS client, date_trunc('hour', %s) as timestamp, %s, %s, %s, %s
FROM clients
WHERE name = %s
"""
,
(
now
,
in_time
,
in_bytes
,
out_time
,
out_bytes
,
client
))
else
:
client_id
=
result
[
0
]
timestamp
=
result
[
1
]
in_time
=
result
[
2
]
in_bytes
=
result
[
3
]
out_time
=
result
[
4
]
out_bytes
=
result
[
5
]
t
.
execute
(
"""SELECT client, timestamp, in_time, in_bytes, out_time, out_bytes
FROM bandwidth_stats
JOIN clients ON bandwidth_stats.client = clients.id
WHERE name = %s AND timestamp = date_trunc('hour', %s)
"""
,
(
client
,
now
))
result
=
t
.
fetchone
()
if
result
==
None
:
in_time
=
[
0
]
*
BUCKETS_CNT
in_bytes
=
[
0
]
*
BUCKETS_CNT
out_time
=
[
0
]
*
BUCKETS_CNT
out_bytes
=
[
0
]
*
BUCKETS_CNT
for
bucket
in
cldata
.
buckets
.
itervalues
():
pos
=
BUCKET_MAP
[
bucket
.
bucket
]
in_time
[
pos
]
=
bucket
.
in_time
in_bytes
[
pos
]
=
bucket
.
in_bytes
out_time
[
pos
]
=
bucket
.
out_time
out_bytes
[
pos
]
=
bucket
.
out_bytes
t
.
execute
(
"""INSERT INTO bandwidth_stats (client, timestamp, in_time, in_bytes, out_time, out_bytes)
SELECT clients.id AS client, date_trunc('hour', %s) as timestamp, %s, %s, %s, %s
FROM clients
WHERE name = %s
"""
,
(
now
,
in_time
,
in_bytes
,
out_time
,
out_bytes
,
client
))
else
:
client_id
=
result
[
0
]
timestamp
=
result
[
1
]
in_time
=
result
[
2
]
in_bytes
=
result
[
3
]
out_time
=
result
[
4
]
out_bytes
=
result
[
5
]
for
bucket
in
cldata
.
buckets
.
itervalues
():
pos
=
BUCKET_MAP
[
bucket
.
bucket
]
in_time
[
pos
]
+=
bucket
.
in_time
in_bytes
[
pos
]
+=
bucket
.
in_bytes
out_time
[
pos
]
+=
bucket
.
out_time
out_bytes
[
pos
]
+=
bucket
.
out_bytes
t
.
execute
(
"""UPDATE bandwidth_stats
SET in_time = %s, in_bytes = %s, out_time = %s, out_bytes = %s
WHERE client = %s AND timestamp = %s
"""
,
(
in_time
,
in_bytes
,
out_time
,
out_bytes
,
client_id
,
timestamp
))
except
KeyError
:
# Some clients send invalid data (bucket with index 0). While we need to solve that, we at least don't want to kill data for all the clients in such a case.
logger
.
exception
(
"Broken data from client %s"
,
client
)
for
bucket
in
cldata
.
buckets
.
itervalues
():
pos
=
BUCKET_MAP
[
bucket
.
bucket
]
in_time
[
pos
]
+=
bucket
.
in_time
in_bytes
[
pos
]
+=
bucket
.
in_bytes
out_time
[
pos
]
+=
bucket
.
out_time
out_bytes
[
pos
]
+=
bucket
.
out_bytes
t
.
execute
(
"""UPDATE bandwidth_stats
SET in_time = %s, in_bytes = %s, out_time = %s, out_bytes = %s
WHERE client = %s AND timestamp = %s
"""
,
(
in_time
,
in_bytes
,
out_time
,
out_bytes
,
client_id
,
timestamp
))
class
BandwidthPlugin
(
plugin
.
Plugin
):
"""
...
...
src/plugins/sniff/sniff-cert
View file @
24085ad0
...
...
@@ -30,7 +30,7 @@ while [ "$1" ] ; do
fi
mkdir -p "$DIR"
cd "$DIR"
echo | openssl s_client -servername "$HOST" -connect "$HOST":"$PORT" $PARAMS -showcerts
-status
>out 2>/dev/null
echo
-n ''
| openssl s_client -servername "$HOST" -connect "$HOST":"$PORT" $PARAMS -showcerts >out 2>/dev/null
awk -v c=-1 '/-----BEGIN CERTIFICATE-----/{inc=1;c++} inc {print > (c ".pem")}' <out
grep '^SSL-Session:' -A 20 <out >session
echo '-----BEGIN HOST-----'
...
...
Write
Preview
Supports
Markdown
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