Monitoring Azure resources with Zabbix
Comments  
Kingsley
# zabbix monitor from on-prem to cloudKingsley 2018-08-07 17:56
Is it possible to monitor azure resources (i.e server VMs) from on premises zabbix server
Reply | Reply with quote | Quote
Super User
# RE: zabbix monitor from on-prem to cloudSuper User 2018-08-10 16:25
Quoting Kingsley:
Is it possible to monitor azure resources (i.e server VMs) from on premises zabbix server


Hi!

Yep, it's possible, there is no any difference.
Reply | Reply with quote | Quote
Dragan Vucanovic
# Problem with running scripDragan Vucanovic 2018-08-08 20:37
Powershell script runs fine on Windows but on zabbbix server no results, only get {"data":}, and how did you manage to run sh script, just replaced ps1 with sh, i tried it but got bunch of errors, installed powershell following this guide:https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-powershell-core-on-linux?view=powershell-6
Reply | Reply with quote | Quote
Super User
# RE: Problem with running scripSuper User 2018-08-10 16:33
Quoting Dragan Vucanovic:
Powershell script runs fine on Windows but on zabbbix server no results, only get {"data":}, and how did you manage to run sh script, just replaced ps1 with sh, i tried it but got bunch of errors, installed powershell following this guide:https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-powershell-core-on-linux?view=powershell-6


Hi!

I believe you're talking about discovery script...

1. I think the problem, when script's working on Windows, but not on Linux, is somewhere around 56 and 66 strings:
$sql_servers = (Invoke-RestMethod -Uri $uri -Headers $azure_header -Method Get -ErrorAction Stop).content.properties;

I've faced some issues and played with data returned from API - for some reason there were no "content.properties" - just echo $sql_servers and check if you're getting correct data.

2.
How to run ps1 from sh:

pwsh /usr/lib/zabbix/externalscripts/azure.discovery.sql.databases.ps1 $1 $2
Reply | Reply with quote | Quote
Dragan Vucanovic
# RE: Problem with running scripDragan Vucanovic 2018-08-11 20:40
yes, when testing on windows had to replace content.properties with Value, and when pasted it on Linux forgot to revert it back, all works now
Reply | Reply with quote | Quote
Dragan Vucanovic
# RE: Problem with running scriptsDragan Vucanovic 2018-08-20 22:10
i created multiple scripts (for multiple services) and getting "Value Should be JSON object"
Reply | Reply with quote | Quote
Super User
# RE: Problem with running scriptsSuper User 2018-08-21 11:24
Quoting Dragan Vucanovic:
i created multiple scripts (for multiple services) and getting "Value Should be JSON object"


Could you please run script manually and provide output?
Reply | Reply with quote | Quote
Dragan Vucanovic
# RE: Problem with running scriptsDragan Vucanovic 2018-08-21 15:09
Fixed it: the issue was that when Azure token expires (after 60 minutes), new one couldn't be created because zabbix user had no right to write to azure.json file, once i gave ownership to zabbix user over that file-issue was solved. Manually running scripts gives desired output,it took me few hours to figure out what was the problem. When found out (after googling) that Azure token expires after 60 minutes then i had a clue what could have been an issue. Thank you for quick response.
Reply | Reply with quote | Quote
Super User
# RE: Problem with running scriptsSuper User 2018-08-21 15:45
Quoting Dragan Vucanovic:
Fixed it: the issue was that when Azure token expires (after 60 minutes), new one couldn't be created because zabbix user had no right to write to azure.json file, once i gave ownership to zabbix user over that file-issue was solved. Manually running scripts gives desired output,it took me few hours to figure out what was the problem. When found out (after googling) that Azure token expires after 60 minutes then i had a clue what could have been an issue. Thank you for quick response.


Yeah, I've closed public comments because of tons of spam coming ... ;(
So reviewing them manually.

I'll update article to point you guys to verify linux permissions on files.
Reply | Reply with quote | Quote
Guig
# Problem with running scripts again...Guig 2018-11-13 01:35
I
I have the same issue than Dragan,
when i link the template to the host, the discovry rules is on error, with the info : Value should be a JSON object.
if i run the .sh i have a valid json, the token is renewed automatically each hour on azure.json...
Reply | Reply with quote | Quote
Super User
# RE: Problem with running scripts again...Super User 2018-11-15 15:15
Quoting Guig:
I
I have the same issue than Dragan,
when i link the template to the host, the discovry rules is on error, with the info : Value should be a JSON object.
if i run the .sh i have a valid json, the token is renewed automatically each hour on azure.json...


Hi Guig!

Please remember that you're running .sh script under your user account which might have permissions to write file to the disk.

However, zabbix-server running this script under 'zabbix' user which might not have permissions. Please check the working folder - 'zabbix' user should have 777 or 466 ... something like that.
Reply | Reply with quote | Quote
Guig
# Always same issue...Guig 2018-12-18 23:35
Always same issue, i change right, azure.json file change with the new token each hour (without a manual run), but on zabbix interface i have always the same issue : Value should be a json objet
Reply | Reply with quote | Quote
Super User
# RE: Always same issue...Super User 2018-12-20 11:42
Quoting Guig:
Always same issue, i change right, azure.json file change with the new token each hour (without a manual run), but on zabbix interface i have always the same issue : Value should be a json objet


Hi!

Please verify that JSON object coming from discovery script similar to the following:

{
"data": [
{
"{#HOST}": "Japan 1",
"{#COUNT}": "5"
},
{
"{#HOST}": "Japan 2",
"{#COUNT}": "12"
},
{
"{#HOST}": "Latvia",
"{#COUNT}": "3"
}
]
}

I think that's the only thing I can advise :(. Can you run your discovery script and put it's output here?
Reply | Reply with quote | Quote
Guig
# Here is my JSONGuig 2018-12-20 18:30
{"data":[
{
"{#ID}": "/subscriptions/blablabla/resourceGroups/synchrotool-lab-rg/providers/Microsoft.Sql/servers/synchrotool-lab-sqlsrv/databases/synchrotool-pi-sqldb",
"{#SERVERNAME}": "synchrotool-lab-sqlsrv",
"{#DATABASENAME}": "synchrotool-pi-sqldb",
"{#RGNAME}": "synchrotool-lab-rg"
},
{
"{#ID}": "/subscriptions/blablabla/resourceGroups/synchrotool-lab-rg/providers/Microsoft.Sql/servers/synchrotool-lab-sqlsrv/databases/synchrotool-qa-sqldb",
"{#SERVERNAME}": "synchrotool-lab-sqlsrv",
"{#DATABASENAME}": "synchrotool-qa-sqldb",
"{#RGNAME}": "synchrotool-lab-rg"
}
]}
Reply | Reply with quote | Quote
Dragan Vucanovic
# RE: Always same issue...Dragan Vucanovic 2018-12-20 15:21
Create cron job to run discovery script every 50 minutes
Reply | Reply with quote | Quote
Super User
# RE: Always same issue...Super User 2018-12-21 11:51
Quoting Dragan Vucanovic:
Create cron job to run discovery script every 50 minutes


Discovery script is triggered by Zabbix Server. This is configured in Template (check "Zabbix template" section of the article).
Reply | Reply with quote | Quote
stban
# Problem with pulling metricsstban 2018-09-07 16:37
Hi guys,
i'm able to discover Zabbix item, t works.
But i'm stuck with the pulling metrics script.
it doesn't create the export file.
If i show $host_item variable, it's empty.

I launch manually the script with:
pwsh azure.monitor.metrics.ps1 HOSTNAME
HOSTNAME is the zabbix hostname of my server who own the item discovered (like windowsDB1)

is it ok?
Reply | Reply with quote | Quote
Super User
# RE: Problem with pulling metricsSuper User 2018-09-10 13:05
Quoting stban:
Hi guys,
i'm able to discover Zabbix item, t works.
But i'm stuck with the pulling metrics script.
it doesn't create the export file.
If i show $host_item variable, it's empty.

I launch manually the script with:
pwsh azure.monitor.metrics.ps1 HOSTNAME
HOSTNAME is the zabbix hostname of my server who own the item discovered (like windowsDB1)

is it ok?


Hi!

Yep, looks like you're running your script in proper way.

What can I suggest - is that you run script in debug mode (windows or linux - doesn't matter) and check if you have issues while pulling 'items' from Zabbix - and I believe you will have.

Only one issue I've faced during development - certificate assigned to Zabbix Server front-end was not valid for me.
Reply | Reply with quote | Quote
stban
# RE: Problem with pulling metricsstban 2018-09-26 16:51
It's working, user who import the files needs to be super admin in zabbix :)
Reply | Reply with quote | Quote
jane
# SQL Databasejane 2018-12-20 02:52
I figured out when you making a disvovery rule, you used a SQL Database. Does it have to be a SQL DB? Also, Should I add a resource SQL Database in Azure Portal before making a discovery rule?

I'm the beginner of azure-zabbix. Thanks for the your kindness full explanations. I will wait for your reply.
Reply | Reply with quote | Quote
Super User
# RE: SQL DatabaseSuper User 2018-12-20 11:23
Quoting jane:
I figured out when you making a disvovery rule, you used a SQL Database. Does it have to be a SQL DB? Also, Should I add a resource SQL Database in Azure Portal before making a discovery rule?

I'm the beginner of azure-zabbix. Thanks for the your kindness full explanations. I will wait for your reply.


Hi Jane!

Of course, it's not necessary to be a SQL DB. Screens here are just example for discovering of Azure SQL database. If you with to discover another resource type (let's say ServiceBus, CosmosDB, Kubernetes, whatever - the only need is to be supported by Azure Monitor API) - you will have to change "Key" in discovery rule to something like "azure.discovery.servicebus.sh[....]"
After that you will create a copy of the first script and modify it according your resource type. So, strings 48-76 will be different, because you will query different URLs to get the list of resources.

Regarding your second question. Creation is not required, but essentially you will want to have at least one resource to test your modified script.

Hope that will help you. Don't hesitate to ask.
Reply | Reply with quote | Quote
Add comment