What I got already:
I have a template attached to few hosts with an item whose value is a json document representing an array of hosts with name, properties and sub elements like this like this:
I can retrieve the json just fine from zabbix, and I've added a discovery rule with host prototype to generate hosts (one host per item in the array) with their own template (different from the parent host which caused the discovery).
To achieve this, I have added a dependent item as discovery rule with a preprocessing javascript snippet which extracts the fields into macros:
And the host prototype simply has {#NAME} as its host name. The hosts are properly generated which is great, but so far they have no item configured.
What I'm trying to achieve:
I want my generated host to have an item "Available" whose value is {#AVAILABLE} from the json (without having to query a second time the REST endpoint ideally).
I can add items in the template assigned to the host prototype but I don't know how to refer to that {#AVAILABLE} macro.
Is there a non convoluted way to achieve this?
Ultimately the algorithm should be:
1) query REST endpoint
2) create any missing host based on host prototype
3) for each host, update items value based on content of json response
I have a template attached to few hosts with an item whose value is a json document representing an array of hosts with name, properties and sub elements like this like this:
Code:
[
{
"Name": "A",
"Available": true,
"Items": [
{
"ItemName": "z",
"Active": true
},
{
"ItemName": "y",
"Active": true
}
]
},
{
"Name": "B",
"Available": false,
"Items": [
{
"ItemName": "x",
"Active": true
}
]
},
{
"Name": "C",
"Available": false,
"Items": [
{
"ItemName": "w",
"Active": false
},
{
"ItemName": "u",
"Active": false
}
]
}
]
To achieve this, I have added a dependent item as discovery rule with a preprocessing javascript snippet which extracts the fields into macros:
Code:
output = JSON.parse(value).map(function(item){
return {
"{#NAME}": item.Name,
"{#AVAILABLE}": item.Available
}})
return JSON.stringify({"data": output})
What I'm trying to achieve:
I want my generated host to have an item "Available" whose value is {#AVAILABLE} from the json (without having to query a second time the REST endpoint ideally).
I can add items in the template assigned to the host prototype but I don't know how to refer to that {#AVAILABLE} macro.
Is there a non convoluted way to achieve this?
Ultimately the algorithm should be:
1) query REST endpoint
2) create any missing host based on host prototype
3) for each host, update items value based on content of json response
Comment