Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
url-checker
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
url-checker
Commits
30810042
Commit
30810042
authored
Dec 04, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add network reporting method
parent
00fe334b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
10 deletions
+60
-10
urlchecker_network.py
urlchecker_network.py
+60
-10
No files found.
urlchecker_network.py
View file @
30810042
import
socket
import
socket
import
errno
import
errno
from
peewee
import
fn
TIMEOUT
=
2
TIMEOUT
=
2
def
reportNetwork
(
db
,
ip
=
None
,
transport
=
None
,
port
=
None
):
# http://charlesleifer.com/blog/techniques-for-querying-lists-of-objects-and-determining-the-top-related-item/
NetworkChangeAlias
=
db
.
NetworkChange
.
alias
()
subquery
=
(
NetworkChangeAlias
.
select
(
NetworkChangeAlias
.
ip
,
NetworkChangeAlias
.
transport
,
NetworkChangeAlias
.
port
,
fn
.
MAX
(
NetworkChangeAlias
.
status_id
).
alias
(
"max_status_id"
),
)
.
group_by
(
NetworkChangeAlias
.
ip
,
NetworkChangeAlias
.
transport
,
NetworkChangeAlias
.
port
,
)
.
alias
(
"network_change_max_subquery"
)
)
StatusAlias
=
db
.
Status
.
alias
()
query
=
(
db
.
NetworkChange
.
select
(
db
.
NetworkChange
,
StatusAlias
)
.
join
(
StatusAlias
)
.
switch
(
db
.
NetworkChange
)
.
join
(
subquery
,
on
=
(
(
db
.
NetworkChange
.
status_id
==
subquery
.
c
.
max_status_id
)
&
(
db
.
NetworkChange
.
ip
==
subquery
.
c
.
ip
)
&
(
db
.
NetworkChange
.
transport
==
subquery
.
c
.
transport
)
&
(
db
.
NetworkChange
.
port
==
subquery
.
c
.
port
)
),
)
.
order_by
(
db
.
NetworkChange
.
ip
.
asc
(),
db
.
NetworkChange
.
port
.
asc
(),
db
.
NetworkChange
.
transport
.
asc
(),
)
)
if
transport
is
not
None
:
if
type
(
transport
)
==
list
:
query
=
query
.
where
(
db
.
NetworkChange
.
transport
<<
transport
)
else
:
query
=
query
.
where
(
db
.
NetworkChange
.
transport
==
transport
)
if
port
is
not
None
:
query
=
query
.
where
(
db
.
NetworkChange
.
port
==
port
)
if
ip
is
not
None
:
if
type
(
ip
)
==
list
:
query
=
query
.
where
(
db
.
NetworkChange
.
ip
<<
ip
)
else
:
query
=
query
.
where
(
db
.
NetworkChange
.
ip
==
ip
)
return
query
def
logNetwork
(
db
,
ip
,
transport
,
port
,
state
,
status_id
):
def
logNetwork
(
db
,
ip
,
transport
,
port
,
state
,
status_id
):
with
db
.
_db
.
atomic
():
with
db
.
_db
.
atomic
():
try
:
try
:
# Check previous parameter value
# Check previous parameter value
previous_entry
=
(
previous_entry
=
reportNetwork
(
db
.
NetworkChange
.
select
()
db
,
ip
=
ip
,
transport
=
transport
,
port
=
port
.
where
(
).
get
()
db
.
NetworkChange
.
ip
==
ip
,
db
.
NetworkChange
.
transport
==
transport
,
db
.
NetworkChange
.
port
==
port
,
)
.
order_by
(
db
.
NetworkChange
.
status
.
desc
())
.
get
()
)
except
db
.
NetworkChange
.
DoesNotExist
:
except
db
.
NetworkChange
.
DoesNotExist
:
previous_entry
=
None
previous_entry
=
None
...
...
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