Ad Widget

Collapse

How to use powershell JSON output to create items in Zabbix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mskieszabbix
    Junior Member
    • Jun 2019
    • 5

    #1

    How to use powershell JSON output to create items in Zabbix

    Hi,
    I'm new to zabbix.
    I have a powershell script that gives me all databases in a specific sqlserver instance with its size, how much of the datafile is free etc.
    This information is provided in JSON format.
    I have created a userparameter in the agent config file on the target host and restarted the zabbix agent on the host (Windows).
    In the frontend of zabbix I would like to create an itemprototype that collects the size of the database ( and maybe other itemprototypes to collect the other data that the JSON output from the database server provides).
    Then based on that Itemprototype I want to create a triggerprototype that signals me when the database had too little space left ( smaller than 10GB for example).

    My userparameter looks like this:
    UserParameter=mssql.filesize,powershell -NoProfile -ExecutionPolicy Bypass -File "C:\scripts\monitoring_db_sizes.ps1"

    The output looks like this:
    {
    "{#SQLSERVER.HostName}": "HOST1",
    "{#SQLSERVER.Instance}": "INSTANCE1",
    "{#SQLSERVER.DBName}": "database1",
    "{#SQLSERVER.DBSizeGB}": 30,
    "{#SQLSERVER.DataFilesSizeGB}": 30,
    "{#SQLSERVER.DataFilesFreeGB}": 20,
    "{#SQLSERVER.DataFilesUsedGB}": 10,
    "{#SQLSERVER.LogFilesSizeGB}": 100,
    "{#SQLSERVER.LogFilesUsedGB}": 10,
    "{#SQLSERVER.LogFilesFreeGB}": 0,
    }
    {
    "{#SQLSERVER.HostName}": "HOST1",
    "{#SQLSERVER.Instance}": "INSTANCE2",
    "{#SQLSERVER.DBName}": "database1",
    "{#SQLSERVER.DBSizeGB}": 30,
    "{#SQLSERVER.DataFilesSizeGB}": 35,
    "{#SQLSERVER.DataFilesFreeGB}": 20,
    "{#SQLSERVER.DataFilesUsedGB}": 10,
    "{#SQLSERVER.LogFilesSizeGB}": 100,
    "{#SQLSERVER.LogFilesUsedGB}": 10,
    "{#SQLSERVER.LogFilesFreeGB}": 0,
    }

    My item key looks like this:
    mssql.filesize[{#SQLSERVER.DataFilesFreeGB}]

    My trigger expression looks like:
    {dba_sqlserver_template_marian:mssql.filesize[{#SQLSERVER.DataFilesFreeGB}].last(#5,300s)}<10

    What am I doing wrong.

    Could someone please help me?
    Thanks in advance.
    Regards,
    Marian
  • mskieszabbix
    Junior Member
    • Jun 2019
    • 5

    #2
    Does anyone have an idea?
    Your help is much appreciated.

    Comment

    • splitek
      Senior Member
      • Dec 2018
      • 101

      #3
      If output is in one JSON file and look like you provided then there is a problem to know if {#SQLSERVER.DataFilesFreeGB}" is for instance 1 or 2. Key: mssql.filesize[{#SQLSERVER.DataFilesFreeGB}] ask for instance 1 or 2?

      Good example:
      https://blog.zabbix.com/zabbix-3-4-m...784/#more-5784
      Last edited by splitek; 23-07-2019, 14:15.

      Comment


      • mskieszabbix
        mskieszabbix commented
        Editing a comment
        Hi Splitek,
        Thanks for your reply. I will read the blog.
        Regards,
        Marian
    • mskieszabbix
      Junior Member
      • Jun 2019
      • 5

      #4
      Hi Splitek,
      I have read the blog. Please correct me if I'm wrong.
      If I get the JSON results at once for all the databases in all the instances running on the server, I need to create one master Item ( which is the call of the powershell script that returns all the output in json) and create multiple dependent items. For each type of information one item:
      So a seperate item for hostname, seperate item for datafilefreegb ...etc with preprocessing with json path?
      thanks in advance.
      Regards,
      Marian

      Comment

      • splitek
        Senior Member
        • Dec 2018
        • 101

        #5
        Yes, you can do this way.
        I suggest you to little tune the script... Make "levels" in JSON for every database instance (similar to JSON in blog).

        Comment

        Working...