Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Amonit
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TeDomum
Amonit
Commits
a69e019f
Commit
a69e019f
authored
Mar 29, 2019
by
kaiyou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove the wrapping decorator, will now rely on hooks
parent
0a3be672
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
6 additions
and
33 deletions
+6
-33
amonit/check/http.py
amonit/check/http.py
+0
-4
amonit/check/mail.py
amonit/check/mail.py
+0
-3
amonit/check/matrix.py
amonit/check/matrix.py
+0
-1
amonit/check/tls.py
amonit/check/tls.py
+0
-3
amonit/scheduler.py
amonit/scheduler.py
+4
-1
amonit/util.py
amonit/util.py
+2
-21
No files found.
amonit/check/http.py
View file @
a69e019f
from
amonit
import
util
import
requests
import
requests_html
@
util
.
wrap
def
get
(
context
,
url
,
expected_code
=
200
,
expected_string
=
None
):
""" Run a GET http request and test the HTTP response code
"""
...
...
@@ -26,7 +23,6 @@ def get(context, url, expected_code=200, expected_string=None):
}
@
util
.
wrap
def
get_xpath
(
context
,
url
,
query
,
result_type
=
"str"
,
destination
=
"message"
):
""" Run a GET http requests and use xpath to extract a result
"""
...
...
amonit/check/mail.py
View file @
a69e019f
...
...
@@ -3,7 +3,6 @@ import smtplib
import
os
from
email.mime
import
text
,
multipart
from
amonit
import
util
def
get_imap_client
(
host
,
port
,
encrypt
):
...
...
@@ -28,7 +27,6 @@ def get_smtp_client(host, port, encrypt):
return
client
@
util
.
wrap
def
imap_login
(
context
,
host
,
username
,
password
,
port
=
143
,
encrypt
=
None
):
""" Check that IMAP login works properly and accesses the INBOX
"""
...
...
@@ -37,7 +35,6 @@ def imap_login(context, host, username, password, port=143, encrypt=None):
client
.
logout
()
@
util
.
wrap
def
send_then_receive
(
context
,
account_from
,
account_to
):
""" Send a mail using SMTP, then check that it is received using IMAP
This is useful either on a single server or across servers to ensure
...
...
amonit/check/matrix.py
View file @
a69e019f
import
os
import
json
from
amonit
import
util
from
matrix_client
import
client
as
matrix_client
from
matrix_client
import
room
as
matrix_room
...
...
amonit/check/tls.py
View file @
a69e019f
import
ssl
import
OpenSSL
from
amonit
import
util
@
util
.
wrap
def
check_certificate
(
context
,
host
,
port
):
""" Retrieve and check a TLS certificate
"""
...
...
amonit/scheduler.py
View file @
a69e019f
...
...
@@ -57,7 +57,10 @@ def check_run(checkid, function, context, args):
context
,
args
=
scheduler
.
hook
(
"precheck"
,
context
,
args
)
context
=
dict
(
scheduler
.
state
[
checkid
],
**
context
)
context
.
update
(
checkid
=
checkid
,
function
=
function
)
result
=
util
.
resolve
(
function
)(
context
,
**
args
)
try
:
result
=
util
.
resolve
(
function
)(
context
,
**
args
)
except
Exception
as
error
:
result
=
error
context
,
result
=
scheduler
.
hook
(
"postcheck"
,
context
,
result
)
scheduler
.
state
[
checkid
]
=
context
scheduler
.
notify
(
checkid
,
context
)
...
...
amonit/util.py
View file @
a69e019f
...
...
@@ -52,25 +52,6 @@ def merge(*objects):
elif
mode
is
list
:
return
sum
(
objects
)
else
:
raise
ValueError
(
"Cannot merge objects of type {}"
.
format
(
mode
))
raise
ValueError
(
"Cannot merge objects of type {}: {}"
.
format
(
mode
,
objects
))
def
wrap
(
function
):
""" Wrap a check function to handle simple results and exceptions
"""
def
replacement
(
*
args
,
**
kwargs
):
try
:
result
=
function
(
*
args
,
**
kwargs
)
if
type
(
result
)
is
not
dict
or
"up"
not
in
result
:
result
=
{
"up"
:
True
,
"message"
:
str
(
result
)
}
except
Exception
as
error
:
result
=
{
"up"
:
False
,
"error"
:
type
(
error
).
__name__
,
"message"
:
str
(
error
)
}
return
result
return
replacement
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