Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
verktoy
kindnavsync
Commits
7c64cf0f
Commit
7c64cf0f
authored
Jun 26, 2018
by
Morten Brekkevold
Browse files
format IP addresses in Slack output
also ditch IPy in favor of ipaddress, which is built-in in Python 3
parent
a9b505b2
Changes
2
Hide whitespace changes
Inline
Side-by-side
bin/kindnavsync
View file @
7c64cf0f
...
...
@@ -11,12 +11,12 @@ import os
import
socket
from
collections
import
defaultdict
import
logging
from
ipaddress
import
ip_address
from
operator
import
attrgetter
,
itemgetter
import
requests
import
argparse
from
IPy
import
IP
from
slack_log_handler
import
SlackLogHandler
from
kindnavsync.navapi
import
NAVAPI
,
ObjectNotFound
...
...
@@ -133,12 +133,25 @@ class SlackFormatter(logging.Formatter):
if
isinstance
(
arg
,
(
KindDevice
,
NAVBox
)):
return
"<{url}|{text}>"
.
format
(
url
=
arg
.
get_absolute_url
(),
text
=
str
(
arg
))
elif
(
isinstance
(
arg
,
list
)
and
any
(
isinstance
(
i
,
(
KindDevice
,
NAVBox
))
for
i
in
arg
)):
newarg
=
[
cls
.
_format_arg
(
i
)
for
i
in
arg
]
return
'
\n
'
.
join
(
" • {}"
.
format
(
s
)
for
s
in
newarg
)
else
:
return
arg
elif
isinstance
(
arg
,
str
)
and
_is_valid_ip
(
arg
):
return
"`{}`"
.
format
(
arg
)
elif
isinstance
(
arg
,
list
):
if
any
(
isinstance
(
i
,
(
KindDevice
,
NAVBox
))
for
i
in
arg
):
newarg
=
[
cls
.
_format_arg
(
i
)
for
i
in
arg
]
return
'
\n
'
.
join
(
" • {}"
.
format
(
s
)
for
s
in
newarg
)
elif
any
(
_is_valid_ip
(
i
)
for
i
in
arg
):
newarg
=
[
cls
.
_format_arg
(
i
)
for
i
in
arg
]
return
', '
.
join
(
newarg
)
return
arg
def
_is_valid_ip
(
addr
):
try
:
ip_address
(
addr
)
return
True
except
ValueError
:
return
False
def
get_kind_data
():
...
...
@@ -228,7 +241,8 @@ def lookup_dns(names):
except
socket
.
gaierror
:
pass
else
:
result
[
name
]
=
[
a
for
a
in
addresslist
if
IP
(
a
).
version
()
==
4
]
result
[
name
]
=
[
a
for
a
in
addresslist
if
ip_address
(
a
).
version
==
4
]
return
dict
(
result
)
...
...
setup.py
View file @
7c64cf0f
...
...
@@ -13,7 +13,6 @@ setup(
scripts
=
[
'bin/kindnavsync'
,
'bin/kindnavsyncdiff'
],
packages
=
[
'kindnavsync'
],
install_requires
=
[
'IPy>=0.81'
,
'requests'
,
'slack_log_handler'
,
],
...
...
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