Hi
I've a new problem with json / python.
My json is:
Thanks for help
I've a new problem with json / python.
My json is:
Output:{
"domaine": {
"name": {
"service": ["service1", "service2"],
"threshold": ["100", "200"]
},
...On my python script, I'm trying to make a request post to my icinga configuration for monitoring.#!/usr/bin/env python3
..
with open('/tmp/config.json') as json_file1:
data1 = json.load(json_file1)
for domaine, value in data1.items():
for name, value2 in value.items():
service = data1[domaine][name]['service']
threshold = data1[domaine][name]['threshold']
try:
url = "https://localhost:5665/v1/objects/hosts/"
request_url = url+hostname
headers = {
'Accept': 'application/json',
'X-HTTP-Method-Override': 'PUT'
}
data = {
"templates": service,
"attrs": {
"address":"BLABLA",
"zone":"BLIBLI",
"vars": { threshold }
}
}
r = requests.post(request_url,
headers=headers,
verify=False,
auth=('admin', 'XXXXXXXXXXXXXXXXXX'),
data=json.dumps(data))Result is:Output: "vars": { threshold }
TypeError: unhashable type: 'list'If I changeOutput: threshold = data1[domaine][name]['threshold']
to:
threshold = tuple(data1[domaine][name]['threshold'])My result is: Output:TypeError: Object of type set is not JSON serializableI'm trying to change key, format, ... but i'm blocked with this point...Thanks for help
