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
17288503
Commit
17288503
authored
Aug 25, 2014
by
Jonathan Michalon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Put args parsing and config loading in methods and reuse them in the watchdog
parent
df8f10bd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
18 deletions
+18
-18
bin/picomon-watchdog
bin/picomon-watchdog
+4
-13
picomon/__main__.py
picomon/__main__.py
+14
-5
No files found.
bin/picomon-watchdog
View file @
17288503
...
...
@@ -5,6 +5,7 @@ import os
import
importlib
from
picomon
import
config
from
picomon
import
mails
from
picomon.__main__
import
parse_args
,
import_config
# launch picomon
...
...
@@ -14,19 +15,9 @@ if os.path.sep in sys.argv[0]:
retcode
=
subprocess
.
call
([
filename
]
+
sys
.
argv
[
1
:])
# load config file (unprotected, will trigger exceptions if problems but real
# picomon beforehand)
configfile
=
"config.py"
if
"-c"
in
sys
.
argv
:
configfile
=
sys
.
argv
[
sys
.
argv
.
index
(
"-c"
)
+
1
]
if
"--config"
in
sys
.
argv
:
configfile
=
sys
.
argv
[
sys
.
argv
.
index
(
"--config"
)
+
1
]
sys
.
path
.
append
(
os
.
path
.
dirname
(
configfile
))
filename
=
os
.
path
.
basename
(
configfile
)
base
,
ext
=
os
.
path
.
splitext
(
filename
)
importlib
.
import_module
(
base
)
# load config
args
=
parse_args
()
import_config
(
args
.
config
)
# send warning
mails
.
send_email
(
config
.
emails
.
watchdog_subject
,
...
...
picomon/__main__.py
View file @
17288503
...
...
@@ -57,8 +57,7 @@ def __alarm_handler(signum, frame):
mails
.
send_email_report
(
report
)
def
run
():
# Parse command line
def
parse_args
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"-1"
,
"--one"
,
help
=
"single run with immediate output of "
+
...
...
@@ -70,12 +69,14 @@ def run():
parser
.
add_argument
(
"-c"
,
"--config"
,
help
=
"Set config file (defauts to config.py)"
,
default
=
'config.py'
)
args
=
parser
.
parse_args
()
return
parser
.
parse_args
()
def
import_config
(
configfile
):
# import config file module
try
:
sys
.
path
.
append
(
os
.
path
.
dirname
(
args
.
config
))
filename
=
os
.
path
.
basename
(
args
.
config
)
sys
.
path
.
append
(
os
.
path
.
dirname
(
configfile
))
filename
=
os
.
path
.
basename
(
configfile
)
base
,
ext
=
os
.
path
.
splitext
(
filename
)
importlib
.
import_module
(
base
)
except
ImportError
as
e
:
...
...
@@ -83,6 +84,14 @@ def run():
args
.
config
,
str
(
e
)))
sys
.
exit
(
1
)
def
run
():
# Parse command line
args
=
parse_args
()
# import config file module
import_config
(
args
.
config
)
# Configure logging
logging
.
basicConfig
(
format
=
'%(asctime)s %(levelname)s: %(message)s'
,
level
=
config
.
verb_level
)
...
...
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