mirror of
https://github.com/KevinMidboe/Node-Com-Handler.git
synced 2025-10-29 17:50:27 +00:00
Added uptime to api request and changed returning state to None
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
v1/__pycache__
|
||||||
Binary file not shown.
Binary file not shown.
19
v1/app.py
19
v1/app.py
@@ -9,8 +9,8 @@ from json import loads, dumps
|
|||||||
from werkzeug.security import generate_password_hash, \
|
from werkzeug.security import generate_password_hash, \
|
||||||
check_password_hash
|
check_password_hash
|
||||||
|
|
||||||
import uptime
|
|
||||||
from diskusage import diskUsage
|
from diskusage import diskUsage
|
||||||
|
from uptime import timeSinceBoot
|
||||||
|
|
||||||
app = Flask(__name__, static_url_path = "")
|
app = Flask(__name__, static_url_path = "")
|
||||||
auth = HTTPBasicAuth()
|
auth = HTTPBasicAuth()
|
||||||
@@ -70,22 +70,15 @@ def get_diskUsage():
|
|||||||
except:
|
except:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
@app.route('/api/v1/disks/<disk_name>', methods=['GET'])
|
|
||||||
@auth.login_required
|
|
||||||
def get_singleDiskUsage(disk_name, other):
|
|
||||||
|
|
||||||
if (diskUsage(disk_name)):
|
|
||||||
return jsonify({task_type: diskUsage(disk_name)})
|
|
||||||
else:
|
|
||||||
abort(404)
|
|
||||||
|
|
||||||
@app.route('/api/v1/uptimes', methods=['GET'])
|
@app.route('/api/v1/uptimes', methods=['GET'])
|
||||||
@auth.login_required
|
@auth.login_required
|
||||||
def get_uptimes():
|
def get_uptimes():
|
||||||
up = uptime.uptime()
|
try:
|
||||||
print(up)
|
return jsonify({ 'uptime': timeSinceBoot() })
|
||||||
return jsonify({'duration': up.duration, 'users': up.users,
|
except:
|
||||||
'load': up.load})
|
abort(404)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/v1/uptimes/duration', methods=['GET'])
|
@app.route('/api/v1/uptimes/duration', methods=['GET'])
|
||||||
@auth.login_required
|
@auth.login_required
|
||||||
|
|||||||
10
v1/uptime.py
10
v1/uptime.py
@@ -3,7 +3,9 @@
|
|||||||
# @Author: KevinMidboe
|
# @Author: KevinMidboe
|
||||||
# @Date: 2017-01-27 19:48:42
|
# @Date: 2017-01-27 19:48:42
|
||||||
# @Last Modified by: KevinMidboe
|
# @Last Modified by: KevinMidboe
|
||||||
# @Last Modified time: 2017-01-31 21:02:21
|
# @Last Modified time: 2017-01-31 23:01:48
|
||||||
|
|
||||||
|
# TODO add better error handling to return statements
|
||||||
|
|
||||||
from psutil import boot_time
|
from psutil import boot_time
|
||||||
from time import time
|
from time import time
|
||||||
@@ -27,16 +29,14 @@ def timeSinceBoot():
|
|||||||
|
|
||||||
# Return in day format
|
# Return in day format
|
||||||
if deltaSeconds >= 86400:
|
if deltaSeconds >= 86400:
|
||||||
# TODO error handling
|
|
||||||
return secToDay(deltaSeconds)
|
return secToDay(deltaSeconds)
|
||||||
|
|
||||||
# Return in hour format
|
# Return in hour format
|
||||||
elif deltaSeconds < 86400 and deltaSeconds >= 0:
|
elif deltaSeconds < 86400 and deltaSeconds >= 0:
|
||||||
# TODO error handling
|
|
||||||
return secToHour(deltaSeconds)
|
return secToHour(deltaSeconds)
|
||||||
else:
|
else:
|
||||||
# Throw error
|
# TODO Throw error
|
||||||
return 'Null'
|
return None
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
print(timeSinceBoot())
|
print(timeSinceBoot())
|
||||||
Reference in New Issue
Block a user