Created
November 25, 2023 17:43
-
-
Save elpatron68/a729e36632b7123664eae3b46e8d89b1 to your computer and use it in GitHub Desktop.
SNMP2HTML Broker for Update-Kuma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Webserver to check a device disk state by SNMP with Uptime-Kuma | |
# Requirements: | |
# pip install flask | |
# apt install snmp | |
# | |
# Run: python app.py | |
# | |
# Example: # 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 | |
from flask import Flask, request | |
from subprocess import check_output | |
app = Flask(__name__) | |
@app.route('/check-qnap-disk-state') | |
def snmp_disk_status(): | |
# Die Parameter aus der URL abrufen | |
Ip = request.args.get('ip') | |
Oid = request.args.get('oid') | |
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 'good' in line.lower(): | |
healthy = False | |
statuscode = 418 | |
return f'SNMP result for IP {Ip}\nOID: {Oid}\nSNMP-Output: {decoded_string}\nHealthy: {healthy}\n', statuscode | |
if __name__ == '__main__': | |
app.run(debug=True, host='192.168.177.48') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment