I used this post as starting point.
Creating Azure application
(ID/keys will be used for authentication to Azure)
In Azure portal click Azure Active directory-App registrations-new App registration
In App registrations select All apps from drop-down menu-click on Zabbix application
Write down application ID (we’ll use it on scripts)
Click Settings-Keys-set a name,duration and click Save
Write down key
Write down TenantID
Write down Subscription ID-from Azure dashboard,click Cost Management + Billing under my subscription write subscription ID
Give application read rights to resource group
click on resource group-Access control (IAM)
click Add-select Reader role-Assign access to Azure AD user,group or application and select Zabbix application
Install powershell on Zabbix server (CentOS)
# Register the Microsoft RedHat repository
curl https:
//packages.
microsoft.com
/config/rhel/7/prod
.repo |
sudo
tee
/etc/yum
.repos.d
/microsoft
.repo
# Install PowerShell
sudo
yum
install
-y powershell
Extract azure.zip and copy all files in azure.zip to /usr/lib/zabbix/externalscripts, make sure *.sh files are executable
Supported services are SQL,storage account,Virtual Machines and Virtual Network gateway
All available services and metric: https://docs.microsoft.com/en-us/azure/monitoring-and-diagnostics/monitoring-supported-metrics
Time periods (monitoring intervals) are called timegrains
time_grains = {
"PT1M" => "1 Minute",
"PT5M" => "5 Minutes",
"PT1H" => "1 Hour",
"PT12H" => "12 Hours"
}
In trapper.ps1 and azure.ps1 substitute TenantID,applicationID, application key in appropriate sections/
Files can be downloaded from here
Testing
For VM:
./azure.sh resource group subscription vm
For SQL:
./azure.sh resource group subscription sql
For network gateway:
./azure.sh resource group subscription vng
For Storage account
./azure.sh resource group subscription storage
[root@ip-172-31-27-77 externalscripts]
# ./azure.sh RG subscriptionD storage
{
"data"
:[
{
"{#ID}"
:
"/subscriptions/111-222-333/resourceGroups/RG/providers/Microsoft.Storage/storageAccounts/storageaccount"
,
"{#STORAGEACCOUNT}"
:
"storageaccount"
},
{
"{#ID}"
:
"/subscriptions/111-222-333/resourceGroups/RG/providers/Microsoft.Storage/storageAccounts/storageaccount"
,
"{#STORAGEACCOUNT}"
:
"storageaccount"
},
{
"{#ID}"
:
"/subscriptions/111-222-333/resourceGroups/RG/providers/Microsoft.Storage/storageAccounts/storageaccount"
,
"{#STORAGEACCOUNT}"
:
"storageaccount"
}
]
}
give ownership of azure.json to zabbix user:
chown zabbix:zabbix azure.json
create dummy host and attach template, specify resource group and subscription ID
Test zabbix trapper:
./trapper.sh zabbix-dummy-host
if no issues,create cron job for trapper (for example to run it every 15 minutes):
*/15 * * * * /usr/lib/zabbix/externalscripts/trapper.sh dummy-host
I believe you might want to put a back-link to the original source of your code:
https://b-blog.info/en/monitoring-azure-resources-with-zabbix.html
LikeLiked by 1 person
Already did it at the beginning of my article
LikeLike
Thanks 🙂
LikeLike
Hello. Thanks for your detailed manuals. By the way, I’m the beginner of azure-zabbix.
I wonder what you mean about the below sentence.
“Copy all files in azure.zip to /usr/lib/zabbix/externalscripts, make sure *.sh files are executable”
Which files do I need to make it as a zip file ? Where are the *.sh files located?
I would appreciate your reply asap.
LikeLike
unzip zip file and you’ll see which files have sh extension
LikeLike
I mean there is no zip file. Which zip file do I need to have it?
LikeLike
Read whole post, i provided a link to my OneDrive account,there you can find zip file
LikeLike
Dear good afternoon
Next all the tutorial with no error, however, if you test an integration, do not call anything. Look:
./azure.sh XXXXXX XXXXXXXXXXXXXXXXXXXXXX sql
LikeLike
is azure.json file empty ?
LikeLike
{“data”:[]
}
LikeLike
Dragan979
I try test here but I have one error
You cannot call a method on a null-valued expression.
At /usr/lib/zabbix/externalscripts/azure/azure.ps1:32 char:13
+ if ($token.expires_on.ToInt64($null) – [int64]((Get-Date).ToU …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
LikeLike
azure script should be under /usr/lib/zabbix/externalscripts/azure.ps1, not inside azure folder
LikeLike
I try to run: ./azure.discover.sql.databases.sh XXXXXX XXXXXXXXXXXXXXXXXXXXXX but there is no result appears. Only shows:
{“data”:[]
}
and my azure.json is not empty.
On Zabbix GUI appears “value should be json object”
Any suggestion?
LikeLike
Hi! When I run the azure.sh script from console with “sudo -u zabbix”, it returns correct data, but at zubbix console there is error “value should be a JSON object”. There are no particular errors In the zabbix_server.log with debug level = 5… Do you have any ideas where to look?
LikeLike
hmm, never faced similar issue, i suggest to create cron job to run every 40 minutes under zabbix user, i suspect Azure keys expires every 60 minutes.
LikeLike
I’ve found the issue – create not lld item with the same external check key and type “text” and get the error : ./azure.ps1 not found… I’ve created .sh with the relevant path and this script successfully runs at the console and doesn’t work with as external check…
LikeLike
Can you please re-upload the file the onedrive link is not working ?
LikeLike
It’s working sorry.
LikeLike
Please, can you help me?
What i did wrong?
The only change I made was to insert the PWSH because it was WSH only.
[root@zabbixlab externalscripts]# ./trapper.sh
Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: value
at System.String.IndexOf(String value, Int32 startIndex, Int32 count, StringComparison comparisonType)
at Microsoft.PowerShell.CommandLineParameterParser.MatchSwitch(String switchKey, String match, String smallestUnambiguousMatch)
at Microsoft.PowerShell.CommandLineParameterParser.EarlyParseHelper(String[] args)
at Microsoft.PowerShell.CommandLineParameterParser.EarlyParse(String[] args)
at Microsoft.PowerShell.UnmanagedPSEntry.Start(String consoleFilePath, String[] args, Int32 argc)
at Microsoft.PowerShell.ManagedPSEntry.Main(String[] args) in /PowerShell/src/powershell/Program.cs:line 22
./trapper.sh: line 1: 53019 Aborted pwsh /usr/lib/zabbix/externalscripts/trapper.ps1 $1
LikeLike
i suspect Azure keys has expired, try deleting that file and check again
LikeLike
one drive link is not working .. Kindly Help !!
LikeLike
https://1drv.ms/f/s!AizscpxS0QM4hJ0gB-31IIXC9FX1Ew
it’s working for me
LikeLike
Hi
Nice post!
Does the following mean AppServices cannot be monitored?
“Supported services are SQL,storage account,Virtual Machines and Virtual Network gateway”
LikeLike
Yes, of course, “supported” means what is important for me to monitor 🙂
But i can’t help you with that, try using my pattern to monitor what you need
LikeLike
Thank you very much for your post.
LikeLike
currently following this when I get to the IAM role assignment it can’t see my zabbix application.
would it be possible to update the azure screen shots so they match the current azure portal?
LikeLike
Sorry, not working anymore with Zabbix, but you could google how to find it.
LikeLike
How much does this Zabbix application cost on azure?
LikeLike
No idea.
LikeLike
Hey!
I’ve re-factored original code and solution to be more flexible and modular:
https://b-blog.info/en/monitoring-azure-resources-with-zabbix.html
Everything is on the GitHub now, so you guys are free to create issues.
LikeLiked by 1 person
Hi!
I run ./azure.sh myRG Subscription ID sql
I am getting this message:
Line 165 _servers = (Invoke-RestMethod -Uri $uri -Headers $azure_header -Metho …
The cmdlet cannot run because the -ContentType parameter is not a valid Content-Type header. Specify a valid Content-Type for
| -ContentType, then retry. To suppress header validation, supply the -SkipHeaderValidation parameter.
LikeLike
Uh !, for last 3 years i’m not working with Zabbix and really cannot help you
LikeLike
does it work on mysql? I have this error:
s: /data/zabbix/externalscripts/azure.ps1:1
Line |
1 | s
| ~
| The term ‘s’ is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was
| included, verify that the path is correct and try again.
InvalidOperation: /data/zabbix/externalscripts/azure.ps1:32
Line |
32 | if ($token.expires_in.ToInt64($null) – [int64]((Get-Date).ToU …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
| You cannot call a method on a null-valued expression.
Invoke-RestMethod: /data/zabbix/externalscripts/azure.ps1:165
Line |
165 | … _servers = (Invoke-RestMethod -Uri $uri -Headers $azure_header -Metho …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
| The cmdlet cannot run because the -ContentType parameter is not a valid Content-Type header. Specify a valid Content-Type for -ContentType, then
| retry. To suppress header validation, supply the -SkipHeaderValidation parameter.
{“date”:[]
}
LikeLike
[…] More items… […]
LikeLike
[…] More items… […]
LikeLike
[…] More items… […]
LikeLike
[…] More items… […]
LikeLike