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}"
mail
=
Host
(
ipv4
=
'127.0.0.1'
,
ipv6
=
'::1'
,
name
=
'LXC mail'
)
web
=
Host
(
ipv4
=
'127.0.0.0'
,
ipv6
=
'::42'
,
name
=
'Bad IPs'
)
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
(
CheckPing4
,
[
mail
,
web
],
retry
=
2
)
...
...
lib/__init__.py
View file @
993cb1ff
...
...
@@ -24,5 +24,7 @@ config.install_attr('emails.smtp_host', 'localhost:25')
# available substitutions:
# - state ("Problem" or "OK")
# - check (check's name, like "CheckDNSRec6")
# - dest (the target of the check ie. an IP or a Host's 'name' parameter)
config
.
install_attr
(
'emails.subject_tpl'
,
'[DOMAIN] {state}: {check} on {dest}'
)
# - dest (the target of the check ie. an IP or a Host's 'name'
# 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):
def
__repr__
(
self
):
return
'{:<15s} N={}/{}, R={}/{}, {}'
.
format
(
self
.
__class__
.
__name__
,
self
.
every_count
,
self
.
every
,
self
.
retry_count
,
self
.
retry
,
self
.
_options
)
self
.
every_count
,
self
.
every
,
self
.
retry_count
,
self
.
retry
,
self
.
_options
)
def
setup
(
self
):
pass
...
...
@@ -121,13 +124,13 @@ class Check6(CheckIP):
class
CheckPing4
(
Check4
):
def
check
(
self
):
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
):
def
check
(
self
):
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
):
...
...
@@ -182,13 +185,13 @@ class CheckHTTP(Check):
def
check
(
self
):
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
):
def
check
(
self
):
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
):
...
...
@@ -222,7 +225,7 @@ class CheckSMTP(Check):
def
check
(
self
):
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
):
...
...
@@ -243,7 +246,7 @@ class CheckOpenVPN(Check):
'-s'
,
"
\x38\x01\x01\x01\x01\x01\x01\x01\x42
"
,
'-e'
,
"@"
,
'-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
):
...
...
lib/mails.py
View file @
993cb1ff
...
...
@@ -8,14 +8,15 @@ import email.charset
# 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'
)
def
send_email_for_check
(
check
):
from
.
import
config
# ensure we do not traceback with unknown substitutions
subject
=
config
.
emails
.
subject_tpl
.
format_map
(
defaultdict
(
lambda
:
"<no substitution>"
,
state
=
'OK'
if
check
.
ok
else
'Problem'
,
check
=
check
.
__class__
.
__name__
,
dest
=
check
.
target_name
))
defaultdict
(
lambda
:
"<no substitution>"
,
state
=
'OK'
if
check
.
ok
else
'Problem'
,
check
=
check
.
__class__
.
__name__
,
dest
=
check
.
target_name
))
msg_text
=
''
if
not
check
.
ok
:
...
...
@@ -32,7 +33,8 @@ def send_email_for_check(check):
try
:
server
=
smtplib
.
SMTP
(
config
.
emails
.
smtp_host
)
# 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
()
except
Exception
as
e
:
print
(
"Couldn't send email: %s"
%
str
(
e
),
file
=
stderr
)
picomon.py
View file @
993cb1ff
...
...
@@ -14,7 +14,7 @@ def usr1_handler(signum, frame):
if
not
check
.
ok
:
print
(
'-+'
*
40
)
print
(
"Check %s is in error state:
\n\t
%s"
%
(
check
,
check
.
errmsg
.
strip
()))
check
.
errmsg
.
strip
()))
print
(
'-+'
*
40
,
"""
Other checks (usually OK but may be in retry mode):"""
)
...
...
@@ -31,8 +31,9 @@ if __name__ == '__main__':
# Parse command line
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"-1"
,
"--one"
,
help
=
"single run with immediate output of check results (test/debug)"
,
action
=
"store_true"
)
help
=
"single run with immediate output of "
+
"check results (test/debug)"
,
action
=
"store_true"
)
args
=
parser
.
parse_args
()
# 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