forked from paleg/bareos_zabbix_integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-jobs.py
executable file
·22 lines (16 loc) · 862 Bytes
/
get-jobs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
import subprocess
import locale
import json
from conf import conf
encoding = locale.getdefaultlocale()[1]
if conf['type'] == 'bareos':
command="echo show jobs | timeout %d bconsole -c %s | grep -i name | cut -d \'\"\' -f 2" % (conf['bconsole_wait'], conf['bconsole_conf_file'])
elif conf['type'] == 'bacula':
command="echo show jobs | timeout %d bconsole -c %s | grep \'Job: name=\' | sed -e \'s/Job\: name\=\(.*\) JobType.*/\\1/\'" % (conf['bconsole_wait'], conf['bconsole_conf_file'])
else:
command="echo"
proc=subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
jobs_raw=proc.communicate()[0]
result = dict( {'data': [ { "{#JOBNAME}": job.replace(" ", "_") } for job in jobs_raw.decode(encoding).split('\n') if job ]} )
print(json.JSONEncoder(sort_keys=True, indent=3).encode(result))