Reputation: 93
I'm trying to make discovery rule to add file size monitor. But when I add my Template to Host, zabbix says me:
Value should be a JSON object
I've written the python-script:
import os
import sys
import json
logdir = sys.argv[1]
data = []
for (logdir, _, files) in os.walk(logdir):
for f in files:
if f.endswith(".log"):
path = os.path.join(logdir, f)
data.append({'#LOGFILEPATH':path})
jsondata = json.dumps(data)
print jsondata
It works fine and gets follows:
[{"#LOGFILEPATH": "/opt/logs/projects/cms/cms.log"}, {"#LOGFILEPATH": "/opt/logs/projects/books/nginx.log"}]
I've checked it by jsonlint.com - valid JSON.
UserParameter in conf.d:
UserParameter = discovery.logfile.path, python /opt/scripts/zabbix/find.logfile.path.and.size.py /opt/logs/
There are attachments show my discovery configuration:
User zabbix has permission to directory with script and logs.
Upvotes: 2
Views: 5237
Reputation: 93
It has to make the array a value with a key of "data".
print json.dumps({"data": data})
so it produces...
{ "data": [{"#LOGFILEPATH": "/opt/logs/projects/cms/cms.log"}, {"#LOGFILEPATH": "/opt/logs/projects/books/nginx.log"}] }
And macro {#LOGFILEPATH} should be in brackets {}
Upvotes: 3