Prüflauf parametrisiert in Funktion verlagert
This commit is contained in:
54
app.py
54
app.py
@@ -3,24 +3,50 @@ from subprocess import check_output
|
|||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
# http://192.168.177.48:5000/check-qnap-disk-state?ip=192.168.177.61&oid=.1.3.6.1.4.1.24681.1.2.11.1.7
|
# http://192.168.177.48:5000/check-qnap-disk-smart?ip=192.168.177.61
|
||||||
@app.route('/check-qnap-disk-state')
|
@app.route('/check-qnap-disk-smart')
|
||||||
def snmpcheck():
|
def snmp_disk_smart_status():
|
||||||
# Die Parameter aus der URL abrufen
|
# Die Parameter aus der URL abrufen
|
||||||
Ip = request.args.get('ip')
|
Ip = request.args.get('ip')
|
||||||
Oid = request.args.get('oid')
|
Oid = '.1.3.6.1.4.1.24681.1.2.11.1.7'
|
||||||
|
result = startsnmpwalk(Ip, Oid, 'good')
|
||||||
|
return result
|
||||||
|
|
||||||
process = check_output(['/usr/bin/snmpwalk', '-v', '1', '-c', 'public', Ip, Oid])
|
# http://192.168.177.48:5000/check-qnap-status?ip=192.168.177.61
|
||||||
decoded_string = process.decode('utf-8')
|
@app.route('/check-qnap-status')
|
||||||
healthy = True
|
def snmp_disk_status():
|
||||||
statuscode = 200
|
# Die Parameter aus der URL abrufen
|
||||||
for line in decoded_string.splitlines():
|
Ip = request.args.get('ip')
|
||||||
print(line)
|
Oid = '.1.3.6.1.4.1.24681.1.2.11.1.4'
|
||||||
if not 'good' in line.lower():
|
result = startsnmpwalk(Ip, Oid, 'integer: 0')
|
||||||
healthy = False
|
return result
|
||||||
statuscode = 418
|
|
||||||
|
# http://192.168.177.48:5000/check-volume-status?ip=192.168.177.61
|
||||||
|
@app.route('/check-volume-status')
|
||||||
|
def snmp_volume_status():
|
||||||
|
# Die Parameter aus der URL abrufen
|
||||||
|
Ip = request.args.get('ip')
|
||||||
|
Oid = '.1.3.6.1.4.1.24681.1.2.17.1.6.1'
|
||||||
|
result = startsnmpwalk(Ip, Oid, 'ready')
|
||||||
|
return result
|
||||||
|
|
||||||
|
def startsnmpwalk(ip, oid, expectedtext):
|
||||||
|
try:
|
||||||
|
process = check_output(['/usr/bin/snmpwalk', '-v', '1', '-c', 'public', ip, oid])
|
||||||
|
decoded_string = process.decode('utf-8')
|
||||||
|
healthy = True
|
||||||
|
statuscode = 200
|
||||||
|
for line in decoded_string.splitlines():
|
||||||
|
if not expectedtext.lower() in line.lower():
|
||||||
|
healthy = False
|
||||||
|
statuscode = 418
|
||||||
|
except:
|
||||||
|
statuscode = 400
|
||||||
|
healthy = False
|
||||||
|
decoded_string = "snmpwalk failed"
|
||||||
|
|
||||||
|
return f'SNMP result for IP {ip}\nOID: {oid}\nSNMP-Output: {decoded_string}\nHealthy: {healthy}\n', statuscode
|
||||||
|
|
||||||
return f'SNMP result for IP {Ip}\nHealthy: {healthy}\n', statuscode
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True, host='192.168.177.48')
|
app.run(debug=True, host='192.168.177.48')
|
Reference in New Issue
Block a user