1
0
mirror of https://github.com/librenms/librenms-agent.git synced 2024-05-09 09:54:52 +00:00

Add backupninja snmp script (#264)

* Add backupninja snmp script

* jsonify output

* Better codestyle & apply JSON requirements

* Optimize file using redis.py example

* Properly use of the LibreNMS json format

* typo
This commit is contained in:
Anael Mobilia
2020-06-02 17:37:23 +02:00
committed by GitHub
parent 17ae1ee9e4
commit 6b96466473

39
snmp/backupninja.py Normal file
View File

@@ -0,0 +1,39 @@
#!/usr/bin/env python3
import io
import re
import os
import json
version = 1
error = 0
error_string = ''
logfile = '/var/log/backupninja.log'
backupninja_datas = {
'last_actions': 0,
'last_fatal': 0,
'last_error': 0,
'last_warning': 0}
if not os.path.isfile(logfile):
error_string = 'file unavailable'
error = 1
break
with io.open(logfile,'r') as f:
for line in reversed(list(f)):
match = re.search('^(.*) [a-zA-Z]*: FINISHED: ([0-9]+) actions run. ([0-9]+) fatal. ([0-9]+) error. ([0-9]+) warning.$', line)
if match:
backupninja_datas['last_actions'] = int(match.group(2))
backupninja_datas['last_fatal'] = int(match.group(3))
backupninja_datas['last_error'] = int(match.group(4))
backupninja_datas['last_warning'] = int(match.group(5))
break
output = {'version': version,
'error': error,
'errorString': error_string,
'data': backupninja_datas}
print(json.dumps(output))