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
ada7efd6
Commit
ada7efd6
authored
Aug 24, 2014
by
Jonathan Michalon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move main script code into module and create installable executables
parent
215d513b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
14 deletions
+51
-14
README.md
README.md
+13
-0
bin/picomon
bin/picomon
+6
-0
bin/picomon-watchdog
bin/picomon-watchdog
+8
-3
picomon/__main__.py
picomon/__main__.py
+24
-11
No files found.
README.md
View file @
ada7efd6
...
@@ -77,6 +77,19 @@ They are sent on a regular basis (configured with option `emails.report.every`)
...
@@ -77,6 +77,19 @@ They are sent on a regular basis (configured with option `emails.report.every`)
only if there are some checks in an error state.
only if there are some checks in an error state.
Test it!
--------
You have several solutions :
*
Install with
`distutils`
, for example:
`setup.py install --user`
then run it from your local bin/ directory;
*
Run directly with something like
`python3 -m picomon`
*
Set python module path by hand:
`PYTHONPATH=. bin/picomon`
The default config file is
`config.py`
, so either copy/link the sample one, write
your own or use the
`-s`
command line argument.
License
License
-------
-------
...
...
bin/picomon
0 → 100755
View file @
ada7efd6
#!/usr/bin/env python3
import
picomon.__main__
picomon
.
__main__
.
run
()
picomon_watchdog.py
→
bin/picomon-watchdog
100644 → 100755
View file @
ada7efd6
#!/usr/bin/env python3
import
subprocess
import
subprocess
import
sys
import
sys
import
os
import
os
...
@@ -7,16 +8,20 @@ from picomon import mails
...
@@ -7,16 +8,20 @@ from picomon import mails
# launch picomon
# launch picomon
retcode
=
subprocess
.
call
([
"python3"
,
"picomon.py"
]
+
sys
.
argv
[
1
:])
filename
=
'picomon'
if
os
.
path
.
sep
in
sys
.
argv
[
0
]:
filename
=
os
.
path
.
join
(
os
.
path
.
dirname
(
sys
.
argv
[
0
]),
filename
)
retcode
=
subprocess
.
call
([
filename
]
+
sys
.
argv
[
1
:])
# load config file (unprotected, will trigger exceptions if problems but real
# load config file (unprotected, will trigger exceptions if problems but real
# picomon beforehand)
# picomon beforehand)
configfile
=
"config.py"
configfile
=
"config.py"
if
"-c"
in
sys
.
argv
:
if
"-c"
in
sys
.
argv
:
configfile
=
sys
.
argv
[
sys
.
argv
.
index
(
"-c"
)
+
1
]
configfile
=
sys
.
argv
[
sys
.
argv
.
index
(
"-c"
)
+
1
]
if
"--config"
in
sys
.
argv
:
if
"--config"
in
sys
.
argv
:
configfile
=
sys
.
argv
[
sys
.
argv
.
index
(
"--config"
)
+
1
]
configfile
=
sys
.
argv
[
sys
.
argv
.
index
(
"--config"
)
+
1
]
sys
.
path
.
append
(
os
.
path
.
dirname
(
configfile
))
sys
.
path
.
append
(
os
.
path
.
dirname
(
configfile
))
filename
=
os
.
path
.
basename
(
configfile
)
filename
=
os
.
path
.
basename
(
configfile
)
...
...
picomon.py
→
picomon
/__main__
.py
View file @
ada7efd6
"""
Picomon executable module.
This module can be executed from a command line with ``$python -m picomon`` or
from a python programme with ``picomon.__main__.run()``.
"""
import
concurrent.futures
import
concurrent.futures
import
signal
import
signal
import
argparse
import
argparse
...
@@ -6,12 +16,12 @@ import importlib
...
@@ -6,12 +16,12 @@ import importlib
import
sys
import
sys
import
os
import
os
from
time
import
sleep
from
time
import
sleep
from
picomon
import
config
from
picomon
import
mails
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
.
import
config
from
.
import
mails
def
create_report
(
only_old
=
False
):
def
__
create_report
(
only_old
=
False
):
has_error
=
False
has_error
=
False
report
=
''
report
=
''
report
+=
"
\n
Checks in error:
\n
"
report
+=
"
\n
Checks in error:
\n
"
...
@@ -33,22 +43,21 @@ def create_report(only_old=False):
...
@@ -33,22 +43,21 @@ def create_report(only_old=False):
return
(
report
,
has_error
)
return
(
report
,
has_error
)
def
usr1_handler
(
signum
,
frame
):
def
__
usr1_handler
(
signum
,
frame
):
(
report
,
err
)
=
create_report
()
(
report
,
err
)
=
__
create_report
()
print
(
"Signal SIGUSR1 caught, printing state of checks."
)
print
(
"Signal SIGUSR1 caught, printing state of checks."
)
print
(
report
)
print
(
report
)
def
alarm_handler
(
signum
,
frame
):
def
__
alarm_handler
(
signum
,
frame
):
(
report
,
err
)
=
create_report
(
only_old
=
True
)
(
report
,
err
)
=
__
create_report
(
only_old
=
True
)
if
err
:
if
err
:
report
=
"Following entries have failed for more than %ss:
\n
"
%
\
report
=
"Following entries have failed for more than %ss:
\n
"
%
\
config
.
emails
.
report
.
every
+
report
config
.
emails
.
report
.
every
+
report
mails
.
send_email_report
(
report
)
mails
.
send_email_report
(
report
)
if
__name__
==
'__main__'
:
def
run
():
# Parse command line
# Parse command line
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"-1"
,
"--one"
,
parser
.
add_argument
(
"-1"
,
"--one"
,
...
@@ -81,8 +90,8 @@ if __name__ == '__main__':
...
@@ -81,8 +90,8 @@ if __name__ == '__main__':
logging
.
getLogger
().
setLevel
(
'DEBUG'
)
logging
.
getLogger
().
setLevel
(
'DEBUG'
)
# register signal handling
# register signal handling
signal
.
signal
(
signal
.
SIGUSR1
,
usr1_handler
)
signal
.
signal
(
signal
.
SIGUSR1
,
__
usr1_handler
)
signal
.
signal
(
signal
.
SIGALRM
,
alarm_handler
)
signal
.
signal
(
signal
.
SIGALRM
,
__
alarm_handler
)
# register report signal interval
# register report signal interval
if
config
.
emails
.
report
.
every
>
0
:
if
config
.
emails
.
report
.
every
>
0
:
...
@@ -113,3 +122,7 @@ if __name__ == '__main__':
...
@@ -113,3 +122,7 @@ if __name__ == '__main__':
executor
.
submit
(
check
.
run
)
executor
.
submit
(
check
.
run
)
sleep
(
config
.
base_tick
)
sleep
(
config
.
base_tick
)
mails
.
quit
()
mails
.
quit
()
if
__name__
==
'__main__'
:
run
()
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