Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
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
Léo-Paul Géneau
slapos
Commits
cd1c0816
Commit
cd1c0816
authored
Dec 11, 2014
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
monitor: more code simplification
parent
14001ab2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
21 deletions
+11
-21
stack/monitor/buildout.cfg
stack/monitor/buildout.cfg
+1
-1
stack/monitor/monitor.py.in
stack/monitor/monitor.py.in
+10
-20
No files found.
stack/monitor/buildout.cfg
View file @
cd1c0816
...
...
@@ -48,7 +48,7 @@ mode = 0644
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/${:filename}
download-only = true
md5sum =
49587347fd82d93cca27715f787f8bec
md5sum =
5b12e864f1762d7984f7d4863d0b795d
destination = ${buildout:parts-directory}/monitor-template-monitor-bin
filename = monitor.py.in
mode = 0644
...
...
stack/monitor/monitor.py.in
View file @
cd1c0816
#!{{ python_executable }}
import datetime
import json
import os
import subprocess
...
...
@@ -60,10 +59,8 @@ class Popen(subprocess.Popen):
return event.__killed
return killed
def init_db():
db = sqlite3.connect(db_path)
c = db.cursor()
c.executescript("""
def init_db(db):
db.executescript("""
CREATE TABLE IF NOT EXISTS status (
timestamp INTEGER UNIQUE,
status VARCHAR(255));
...
...
@@ -73,8 +70,6 @@ CREATE TABLE IF NOT EXISTS individual_status (
element VARCHAR(255),
output TEXT);
""")
db.commit()
db.close()
def getListOfScripts(directory):
"""
...
...
@@ -136,25 +131,20 @@ def runScripts(directory):
def writeFiles(monitors):
timestamp = int(time.time())
date = datetime.datetime.now().ctime()
init_db()
db = sqlite3.connect(db_path)
fail = False
init_db(db)
status = SUCCESS
for key, value in monitors.iteritems():
element_status = SUCCESS
if value != "" :
fail = True
element_status =
FAILURE
if value:
element_status = status = FAILURE
else:
element_status =
SUCCESS
db.execute("insert into individual_status(timestamp, element, output, status) values (?, ?, ?, ?)", (timestamp, key, value, element_status))
db.commit()
status = SUCCESS
if fail:
status = FAILURE
db.execute("insert into status(timestamp, status) values (?, ?)", (timestamp, status))
db.commit()
db.close()
monitors['datetime'] =
date
open(monitoring_file_json, "w+").write(json.dumps(monitors
))
monitors['datetime'] =
time.ctime(timestamp)
json.dump(monitors, open(monitoring_file_json, "w+"
))
def main():
parser = OptionParser(option_list=option_list)
...
...
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