I'm using this scrip for Azure monitoring with Zabbix:https://b-blog.info/en/monitoring-azure-resources-with-zabbix.html
If only one SQL database in output:
{"data":{
"{#SERVERNAME}": "mojsql",
"{#ID}": "/subscriptions/11111-222222/resourceGroups/rg/providers/Microsoft.Sql/servers/mojsql/databases/mojabaza",
"{#DATABASENAME}": "mojabaza",
"{#RGNAME}": "rg"
}
}
If more than one database then output is:
{"data":[
{
"{#DATABASENAME}": "mojabaza",
"{#SERVERNAME}": "mojsql",
"{#RGNAME}": "rg",
"{#ID}": "/subscriptions1111-22222/resourceGroups/rg/providers/Microsoft.Sql/servers/mojsql/databases/mojabaza"
},
{
"{#DATABASENAME}": "mojabaza1",
"{#SERVERNAME}": "mojsql",
"{#RGNAME}": "rg",
"{#ID}": "/subscriptions/11111-22222/resourceGroups/rg/providers/Microsoft.Sql/servers/mojsql/databases/mojabaza1"
}
]
}
Note square brackets are added automatically.
The issue is if only one database in resource group then i must add square brackets in order to see database in zabbix
'{"data":' + '[' + $($result | ConvertTo-Json) + ']' + "`n}";
If more than one database then double square brackets are added and Zabbix shows error.
Is it possible to write a condition if one output then add square brackets something like
if $($results)=1 then
'{"data":' + '[' + $($result | ConvertTo-Json) + ']' + "`n}";
else
'{"data":' + $($result | ConvertTo-Json) + "`n}";