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
993cb1ff
Commit
993cb1ff
authored
May 24, 2014
by
Colomban Wendling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PEP8 fixes
Fix all PEP8 errors but E221 (multiple spaces before operator).
parent
1493903b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
19 deletions
+28
-19
config.py
config.py
+2
-1
lib/__init__.py
lib/__init__.py
+4
-2
lib/checks.py
lib/checks.py
+11
-8
lib/mails.py
lib/mails.py
+7
-5
picomon.py
picomon.py
+4
-3
No files found.
config.py
View file @
993cb1ff
...
@@ -24,7 +24,8 @@ config.emails.subject_tpl = "[ARN] {state}: {check} on {dest}"
...
@@ -24,7 +24,8 @@ config.emails.subject_tpl = "[ARN] {state}: {check} on {dest}"
mail
=
Host
(
ipv4
=
'127.0.0.1'
,
ipv6
=
'::1'
,
name
=
'LXC mail'
)
mail
=
Host
(
ipv4
=
'127.0.0.1'
,
ipv6
=
'::1'
,
name
=
'LXC mail'
)
web
=
Host
(
ipv4
=
'127.0.0.0'
,
ipv6
=
'::42'
,
name
=
'Bad IPs'
)
web
=
Host
(
ipv4
=
'127.0.0.0'
,
ipv6
=
'::42'
,
name
=
'Bad IPs'
)
alsace
=
Host
(
ipv4
=
'127.0.0.1'
,
ipv6
=
'::1'
)
alsace
=
Host
(
ipv4
=
'127.0.0.1'
,
ipv6
=
'::1'
)
recursif
=
Host
(
ipv4
=
'89.234.141.66'
,
ipv6
=
'2a00:5881:8100:1000::31'
,
name
=
'DNS récursif'
)
recursif
=
Host
(
ipv4
=
'89.234.141.66'
,
ipv6
=
'2a00:5881:8100:1000::31'
,
name
=
'DNS récursif'
)
config
.
checks
.
add
(
CheckDNSZone
,
[
"arn-fai.net"
,
"netlib.re"
],
ip_version
=
4
)
config
.
checks
.
add
(
CheckDNSZone
,
[
"arn-fai.net"
,
"netlib.re"
],
ip_version
=
4
)
config
.
checks
.
add
(
CheckPing4
,
[
mail
,
web
],
retry
=
2
)
config
.
checks
.
add
(
CheckPing4
,
[
mail
,
web
],
retry
=
2
)
...
...
lib/__init__.py
View file @
993cb1ff
...
@@ -24,5 +24,7 @@ config.install_attr('emails.smtp_host', 'localhost:25')
...
@@ -24,5 +24,7 @@ config.install_attr('emails.smtp_host', 'localhost:25')
# available substitutions:
# available substitutions:
# - state ("Problem" or "OK")
# - state ("Problem" or "OK")
# - check (check's name, like "CheckDNSRec6")
# - check (check's name, like "CheckDNSRec6")
# - dest (the target of the check ie. an IP or a Host's 'name' parameter)
# - dest (the target of the check ie. an IP or a Host's 'name'
config
.
install_attr
(
'emails.subject_tpl'
,
'[DOMAIN] {state}: {check} on {dest}'
)
# parameter)
config
.
install_attr
(
'emails.subject_tpl'
,
'[DOMAIN] {state}: {check} on {dest}'
)
lib/checks.py
View file @
993cb1ff
...
@@ -38,8 +38,11 @@ class Check(object):
...
@@ -38,8 +38,11 @@ class Check(object):
def
__repr__
(
self
):
def
__repr__
(
self
):
return
'{:<15s} N={}/{}, R={}/{}, {}'
.
format
(
self
.
__class__
.
__name__
,
return
'{:<15s} N={}/{}, R={}/{}, {}'
.
format
(
self
.
__class__
.
__name__
,
self
.
every_count
,
self
.
every
,
self
.
retry_count
,
self
.
retry
,
self
.
every_count
,
self
.
_options
)
self
.
every
,
self
.
retry_count
,
self
.
retry
,
self
.
_options
)
def
setup
(
self
):
def
setup
(
self
):
pass
pass
...
@@ -121,13 +124,13 @@ class Check6(CheckIP):
...
@@ -121,13 +124,13 @@ class Check6(CheckIP):
class
CheckPing4
(
Check4
):
class
CheckPing4
(
Check4
):
def
check
(
self
):
def
check
(
self
):
command
=
[
'/bin/ping'
,
'-c'
,
'1'
,
'-W'
,
str
(
self
.
timeout
),
self
.
addr
]
command
=
[
'/bin/ping'
,
'-c'
,
'1'
,
'-W'
,
str
(
self
.
timeout
),
self
.
addr
]
return
self
.
exec_with_timeout
(
command
,
timeout
=
self
.
timeout
+
1
)
return
self
.
exec_with_timeout
(
command
,
timeout
=
self
.
timeout
+
1
)
class
CheckPing6
(
Check6
):
class
CheckPing6
(
Check6
):
def
check
(
self
):
def
check
(
self
):
command
=
[
'/bin/ping6'
,
'-c'
,
'1'
,
'-W'
,
str
(
self
.
timeout
),
self
.
addr
]
command
=
[
'/bin/ping6'
,
'-c'
,
'1'
,
'-W'
,
str
(
self
.
timeout
),
self
.
addr
]
return
self
.
exec_with_timeout
(
command
,
timeout
=
self
.
timeout
+
1
)
return
self
.
exec_with_timeout
(
command
,
timeout
=
self
.
timeout
+
1
)
class
CheckDNSZone
(
Check
):
class
CheckDNSZone
(
Check
):
...
@@ -182,13 +185,13 @@ class CheckHTTP(Check):
...
@@ -182,13 +185,13 @@ class CheckHTTP(Check):
def
check
(
self
):
def
check
(
self
):
command
=
self
.
build_command
()
command
=
self
.
build_command
()
return
self
.
exec_with_timeout
(
command
,
timeout
=
self
.
timeout
+
1
)
return
self
.
exec_with_timeout
(
command
,
timeout
=
self
.
timeout
+
1
)
class
CheckHTTPS
(
CheckHTTP
):
class
CheckHTTPS
(
CheckHTTP
):
def
check
(
self
):
def
check
(
self
):
command
=
self
.
build_command
()
+
[
'--ssl'
]
command
=
self
.
build_command
()
+
[
'--ssl'
]
return
self
.
exec_with_timeout
(
command
,
timeout
=
self
.
timeout
+
1
)
return
self
.
exec_with_timeout
(
command
,
timeout
=
self
.
timeout
+
1
)
class
CheckHTTP4
(
CheckHTTP
,
Check4
):
class
CheckHTTP4
(
CheckHTTP
,
Check4
):
...
@@ -222,7 +225,7 @@ class CheckSMTP(Check):
...
@@ -222,7 +225,7 @@ class CheckSMTP(Check):
def
check
(
self
):
def
check
(
self
):
command
=
self
.
build_command
()
command
=
self
.
build_command
()
return
self
.
exec_with_timeout
(
command
,
timeout
=
self
.
timeout
+
1
)
return
self
.
exec_with_timeout
(
command
,
timeout
=
self
.
timeout
+
1
)
class
CheckSMTP4
(
CheckSMTP
,
Check4
):
class
CheckSMTP4
(
CheckSMTP
,
Check4
):
...
@@ -243,7 +246,7 @@ class CheckOpenVPN(Check):
...
@@ -243,7 +246,7 @@ class CheckOpenVPN(Check):
'-s'
,
"
\x38\x01\x01\x01\x01\x01\x01\x01\x42
"
,
'-s'
,
"
\x38\x01\x01\x01\x01\x01\x01\x01\x42
"
,
'-e'
,
"@"
,
'-e'
,
"@"
,
'-t'
,
str
(
self
.
timeout
)]
'-t'
,
str
(
self
.
timeout
)]
return
self
.
exec_with_timeout
(
command
,
timeout
=
self
.
timeout
+
1
)
return
self
.
exec_with_timeout
(
command
,
timeout
=
self
.
timeout
+
1
)
class
CheckOpenVPN4
(
CheckOpenVPN
,
Check4
):
class
CheckOpenVPN4
(
CheckOpenVPN
,
Check4
):
...
...
lib/mails.py
View file @
993cb1ff
...
@@ -8,14 +8,15 @@ import email.charset
...
@@ -8,14 +8,15 @@ import email.charset
# unreadable for non-ASCII chars if we have to look at raw email
# unreadable for non-ASCII chars if we have to look at raw email
email
.
charset
.
add_charset
(
'utf-8'
,
email
.
charset
.
QP
,
email
.
charset
.
QP
,
'utf-8'
)
email
.
charset
.
add_charset
(
'utf-8'
,
email
.
charset
.
QP
,
email
.
charset
.
QP
,
'utf-8'
)
def
send_email_for_check
(
check
):
def
send_email_for_check
(
check
):
from
.
import
config
from
.
import
config
# ensure we do not traceback with unknown substitutions
# ensure we do not traceback with unknown substitutions
subject
=
config
.
emails
.
subject_tpl
.
format_map
(
subject
=
config
.
emails
.
subject_tpl
.
format_map
(
defaultdict
(
lambda
:
"<no substitution>"
,
defaultdict
(
lambda
:
"<no substitution>"
,
state
=
'OK'
if
check
.
ok
else
'Problem'
,
state
=
'OK'
if
check
.
ok
else
'Problem'
,
check
=
check
.
__class__
.
__name__
,
check
=
check
.
__class__
.
__name__
,
dest
=
check
.
target_name
))
dest
=
check
.
target_name
))
msg_text
=
''
msg_text
=
''
if
not
check
.
ok
:
if
not
check
.
ok
:
...
@@ -32,7 +33,8 @@ def send_email_for_check(check):
...
@@ -32,7 +33,8 @@ def send_email_for_check(check):
try
:
try
:
server
=
smtplib
.
SMTP
(
config
.
emails
.
smtp_host
)
server
=
smtplib
.
SMTP
(
config
.
emails
.
smtp_host
)
# server.set_debuglevel(1)
# server.set_debuglevel(1)
server
.
sendmail
(
config
.
emails
.
addr_from
,
config
.
emails
.
to
,
msg
.
as_string
())
server
.
sendmail
(
config
.
emails
.
addr_from
,
config
.
emails
.
to
,
msg
.
as_string
())
server
.
quit
()
server
.
quit
()
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"Couldn't send email: %s"
%
str
(
e
),
file
=
stderr
)
print
(
"Couldn't send email: %s"
%
str
(
e
),
file
=
stderr
)
picomon.py
View file @
993cb1ff
...
@@ -14,7 +14,7 @@ def usr1_handler(signum, frame):
...
@@ -14,7 +14,7 @@ def usr1_handler(signum, frame):
if
not
check
.
ok
:
if
not
check
.
ok
:
print
(
'-+'
*
40
)
print
(
'-+'
*
40
)
print
(
"Check %s is in error state:
\n\t
%s"
%
(
check
,
print
(
"Check %s is in error state:
\n\t
%s"
%
(
check
,
check
.
errmsg
.
strip
()))
check
.
errmsg
.
strip
()))
print
(
'-+'
*
40
,
"""
print
(
'-+'
*
40
,
"""
Other checks (usually OK but may be in retry mode):"""
)
Other checks (usually OK but may be in retry mode):"""
)
...
@@ -31,8 +31,9 @@ if __name__ == '__main__':
...
@@ -31,8 +31,9 @@ if __name__ == '__main__':
# Parse command line
# Parse command line
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"-1"
,
"--one"
,
parser
.
add_argument
(
"-1"
,
"--one"
,
help
=
"single run with immediate output of check results (test/debug)"
,
help
=
"single run with immediate output of "
+
action
=
"store_true"
)
"check results (test/debug)"
,
action
=
"store_true"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
# do the actual polling
# do the actual polling
...
...
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