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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
arn
picomon
Commits
852ab9cc
Commit
852ab9cc
authored
Aug 23, 2014
by
Jonathan Michalon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prefix messages with a timestamp and support multiple verbosity levels
parent
04b27b1a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
1 deletion
+19
-1
README.md
README.md
+2
-0
lib/__init__.py
lib/__init__.py
+3
-0
lib/checks.py
lib/checks.py
+2
-0
lib/mails.py
lib/mails.py
+2
-1
picomon.py
picomon.py
+10
-0
No files found.
README.md
View file @
852ab9cc
...
@@ -50,6 +50,8 @@ In addition some checks have specific options, see lib/checks.py for examples.
...
@@ -50,6 +50,8 @@ In addition some checks have specific options, see lib/checks.py for examples.
In case you want to check lesser important services and configure very long check intervals, you may
In case you want to check lesser important services and configure very long check intervals, you may
want to have another interval, global to all checks, for error retries. This can be set with the
`error_every`
option.
want to have another interval, global to all checks, for error retries. This can be set with the
`error_every`
option.
For a full list of all available options, see the lib/__init__.py file.
Current state output
Current state output
--------------------
--------------------
...
...
lib/__init__.py
View file @
852ab9cc
...
@@ -15,6 +15,9 @@ config.install_attr('base_tick', 60)
...
@@ -15,6 +15,9 @@ config.install_attr('base_tick', 60)
# How often we retry checks that are in error (-1 disables feature)
# How often we retry checks that are in error (-1 disables feature)
config
.
install_attr
(
'error_every'
,
-
1
)
config
.
install_attr
(
'error_every'
,
-
1
)
# Verbosity level (one of CRITICAL, ERROR, WARNING, INFO, DEBUG)
config
.
install_attr
(
'verb_level'
,
'INFO'
)
# Email addresses to send to when an alert is triggered
# Email addresses to send to when an alert is triggered
config
.
install_attr
(
'emails.to'
,
[])
config
.
install_attr
(
'emails.to'
,
[])
# The From: address
# The From: address
...
...
lib/checks.py
View file @
852ab9cc
from
.subprocess_compat
import
TimeoutExpired
,
Popen
,
PIPE
from
.subprocess_compat
import
TimeoutExpired
,
Popen
,
PIPE
import
re
import
re
import
logging
from
.
import
mails
from
.
import
mails
from
collections
import
Iterable
from
collections
import
Iterable
from
datetime
import
datetime
from
datetime
import
datetime
...
@@ -61,6 +62,7 @@ class Check(object):
...
@@ -61,6 +62,7 @@ class Check(object):
config
.
error_every
<
0
config
.
error_every
<
0
else
config
.
error_every
)
else
config
.
error_every
)
if
self
.
every_count
==
0
or
immediate
:
if
self
.
every_count
==
0
or
immediate
:
logging
.
debug
(
'Running '
+
str
(
self
))
self
.
setup
()
self
.
setup
()
if
not
self
.
check
():
if
not
self
.
check
():
self
.
retry_count
=
min
(
self
.
retry_count
+
1
,
self
.
retry
)
self
.
retry_count
=
min
(
self
.
retry_count
+
1
,
self
.
retry
)
...
...
lib/mails.py
View file @
852ab9cc
import
smtplib
import
smtplib
import
logging
from
email.mime.text
import
MIMEText
from
email.mime.text
import
MIMEText
from
email.utils
import
make_msgid
from
email.utils
import
make_msgid
from
collections
import
defaultdict
from
collections
import
defaultdict
...
@@ -55,7 +56,7 @@ class ThreadedSMTP(object):
...
@@ -55,7 +56,7 @@ class ThreadedSMTP(object):
server
=
smtplib
.
SMTP
(
host
)
server
=
smtplib
.
SMTP
(
host
)
server
.
sendmail
(
*
args
,
**
kwargs
)
server
.
sendmail
(
*
args
,
**
kwargs
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"Couldn't send email: %s"
%
str
(
e
),
file
=
stderr
)
logging
.
warning
(
"Couldn't send email: %s"
%
str
(
e
)
)
finally
:
finally
:
if
server
:
# server is None on exception queue.Empty
if
server
:
# server is None on exception queue.Empty
self
.
_queue
.
task_done
()
self
.
_queue
.
task_done
()
...
...
picomon.py
View file @
852ab9cc
import
concurrent.futures
import
concurrent.futures
import
signal
import
signal
import
argparse
import
argparse
import
logging
from
time
import
sleep
from
time
import
sleep
import
config
as
user_config
import
config
as
user_config
from
lib
import
config
from
lib
import
config
...
@@ -60,8 +61,17 @@ if __name__ == '__main__':
...
@@ -60,8 +61,17 @@ if __name__ == '__main__':
help
=
"single run with immediate output of "
+
help
=
"single run with immediate output of "
+
"check results (test/debug)"
,
"check results (test/debug)"
,
action
=
"store_true"
)
action
=
"store_true"
)
parser
.
add_argument
(
"-D"
,
"--debug"
,
help
=
"Set verbosity to DEBUG"
,
action
=
"store_true"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
# Configure logging
logging
.
basicConfig
(
format
=
'%(asctime)s %(levelname)s: %(message)s'
,
level
=
config
.
verb_level
)
if
args
.
debug
:
logging
.
getLogger
().
setLevel
(
'DEBUG'
)
# do the actual polling
# do the actual polling
with
concurrent
.
futures
.
ThreadPoolExecutor
(
max_workers
=
5
)
as
executor
:
with
concurrent
.
futures
.
ThreadPoolExecutor
(
max_workers
=
5
)
as
executor
:
def
runner
(
check
):
def
runner
(
check
):
...
...
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