Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
picomon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Heintz
picomon
Commits
83c73056
Commit
83c73056
authored
Sep 01, 2016
by
Colomban Wendling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for dynamic DNS resolution in host addresses
parent
659462e1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
1 deletion
+84
-1
config-sample.py
config-sample.py
+17
-0
picomon/checks.py
picomon/checks.py
+1
-1
picomon/dyndns.py
picomon/dyndns.py
+66
-0
No files found.
config-sample.py
View file @
83c73056
...
...
@@ -60,6 +60,23 @@ unnamed = Host(ipv4='127.0.0.1', ipv6='::1')
v6only
=
Host
(
ipv6
=
'2001:0DB8::beef'
)
# Dynamic DNS resolution for the hosts (discouraged but for truly dynamic DNS)
from
picomon.dyndns
import
DynDNS4
,
DynDNS6
dynamic
=
Host
(
ipv4
=
DynDNS4
(
'example.com'
),
ipv6
=
DynDNS6
(
'example.com'
),
name
=
'example.com'
)
# Shorthands for dynamic hosts
from
picomon.dyndns
import
DynHost
,
DynHost4
,
DynHost6
dynamic2
=
DynHost
(
dns
=
'example.com'
)
dynamic3
=
DynHost
(
'example.com'
)
dynv4only
=
DynHost4
(
dns
=
'example.com'
)
dynv6only
=
DynHost6
(
dns
=
'example.com'
)
partdyn
=
DynHost
(
dns
=
'example.com'
,
ipv6
=
'::1'
)
# Checks
########
...
...
picomon/checks.py
View file @
83c73056
...
...
@@ -110,7 +110,7 @@ class Check(object):
lambda
s
:
"'"
+
s
.
replace
(
"'"
,
"'
\"
'
\"
'"
)
+
"'"
,
command
))
try
:
p
=
Popen
(
command
,
stdout
=
PIPE
,
stderr
=
PIPE
)
p
=
Popen
(
map
(
str
,
command
)
,
stdout
=
PIPE
,
stderr
=
PIPE
)
except
OSError
as
e
:
self
.
errmsg
=
'Check not available: '
+
e
.
strerror
return
False
...
...
picomon/dyndns.py
0 → 100644
View file @
83c73056
import
socket
from
.checks
import
Host
class
DynDNS
(
object
):
"""
mimicks a str() but resolves a host to an IP
>>> x=DynDNS('localhost')
>>> print(x)
127.0.0.1
>>> print(x.replace('.', ' '))
127 0 0 1
>>> x == 'localhost'
True
>>> x == '127.0.0.1'
True
"""
def
__init__
(
self
,
host
,
family
=
0
):
self
.
_host
=
host
self
.
_family
=
family
def
__str__
(
self
):
""" pick up the first matching address """
return
socket
.
getaddrinfo
(
self
.
_host
,
None
,
self
.
_family
)[
0
][
4
][
0
]
def
__repr__
(
self
):
return
str
(
self
)
def
__eq__
(
self
,
other
):
""" consider equality if host or string representation match """
if
isinstance
(
other
,
type
(
self
))
and
self
.
_host
==
other
.
_host
:
return
True
other_str
=
str
(
other
)
return
self
.
_host
==
other_str
or
str
(
self
)
==
other_str
def
__getattr__
(
self
,
attr
):
return
getattr
(
str
(
self
),
attr
)
class
DynDNS4
(
DynDNS
):
def
__init__
(
self
,
host
):
DynDNS
.
__init__
(
self
,
host
,
socket
.
AF_INET
)
class
DynDNS6
(
DynDNS
):
def
__init__
(
self
,
host
):
DynDNS
.
__init__
(
self
,
host
,
socket
.
AF_INET6
)
class
DynHost
(
Host
):
def
__init__
(
self
,
dns
,
ipv4
=
None
,
ipv6
=
None
,
name
=
None
):
Host
.
__init__
(
self
,
ipv4
=
ipv4
or
DynDNS4
(
dns
),
ipv6
=
ipv6
or
DynDNS6
(
dns
),
name
=
name
or
dns
)
class
DynHost4
(
Host
):
def
__init__
(
self
,
dns
,
name
=
None
):
Host
.
__init__
(
self
,
ipv4
=
DynDNS4
(
dns
),
name
=
name
or
dns
)
class
DynHost6
(
Host
):
def
__init__
(
self
,
dns
):
Host
.
__init__
(
self
,
ipv6
=
DynDNS6
(
dns
),
name
=
name
or
dns
)
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