Ad Widget

Collapse

LLD in 2.2.3 - "Value should be a JSON object" error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nail
    Member
    • Jun 2012
    • 32

    #1

    LLD in 2.2.3 - "Value should be a JSON object" error

    After migrating some hosts to Zabbix 2.2.3(also same on 2.3.0) got this error for custom lld:
    "Value should be a JSON object."
    Still works on our 2.0.0 server though.

    Using this script to create JSON formatted response:
    Code:
    # Powershell script to fetch a list of autostarted services via WMI and report back in a JSON
    # formatted message that Zabbix will understand for Low Level Discovery purposes.
    #
    
    # First, fetch the list of auto started services
    $colItems = Get-WmiObject Win32_Service | where-object { $_.StartMode -ne 'Disabled' }
    # Output the JSON header
    write-host "{"
    write-host " `"data`":["
    write-host
    
    # For each object in the list of services, print the output of the JSON message with the object properties that we are interessted in
    foreach ($objItem in $colItems) {
     $exe_dir = $objItem.PathName
     $exe_dir = $exe_dir -replace '"?(.+\\).+exe.*','$1'
     $exe_dir = $exe_dir -replace '\\','/'
     $line = " { `"{#SERVICESTATE}`":`"" + $objItem.State + "`" , `"{#SERVICEDISPLAY}`":`"" + $objItem.DisplayName + "`" , `"{#SERVICENAME}`":`"" + $objItem.Name + "`" , `"{#SERVICEDESC}`":`"" + $objItem.Description + "`" , `"{#SERVICEDIR}`":`"" + $exe_dir + "`" },"
     write-host $line
    }
    
    # Close the JSON message
    write-host
    write-host " ]"
    write-host "}"
    write-host
    In zabbix_server.log (Debug=4):
    Code:
     14160:20140522:181056.951 In lld_rows_get()
     14160:20140522:181056.952 End of lld_rows_get():FAIL
     14160:20140522:181056.952 End of lld_process_discovery_rule()
    I've tried changing script to this, but it didn't helped:
    Code:
    # Powershell script to fetch a list of autostarted services via WMI and report back in a JSON
    # formatted message that Zabbix will understand for Low Level Discovery purposes.
    #
    
    # First, fetch the list of auto started services
    $colItems = Get-WmiObject Win32_Service | where-object { $_.StartMode -ne 'Disabled' }
    # Output the JSON header
    write-host "{"
    write-host " `"data`":["
    write-host
    
    # For each object in the list of services, print the output of the JSON message with the object properties that we are interessted in
    foreach ($objItem in $colItems) {
     $i++
     if ($i -lt $colItems.Count){
         $exe_dir = $objItem.PathName
         $exe_dir = $exe_dir -replace '"?(.+\\).+exe.*','$1'
         $exe_dir = $exe_dir -replace '\\','/'
         $line = " { `"{#SERVICESTATE}`":`"" + $objItem.State + "`" , `"{#SERVICEDISPLAY}`":`"" + $objItem.DisplayName + "`" , `"{#SERVICENAME}`":`"" + $objItem.Name + "`" , `"{#SERVICEDESC}`":`"" + $objItem.Description + "`" , `"{#SERVICEDIR}`":`"" + $exe_dir + "`" },"
         write-host $line
     }
     else{
         $exe_dir = $objItem.PathName
         $exe_dir = $exe_dir -replace '"?(.+\\).+exe.*','$1'
         $exe_dir = $exe_dir -replace '\\','/'
         $line = " { `"{#SERVICESTATE}`":`"" + $objItem.State + "`" , `"{#SERVICEDISPLAY}`":`"" + $objItem.DisplayName + "`" , `"{#SERVICENAME}`":`"" + $objItem.Name + "`" , `"{#SERVICEDESC}`":`"" + $objItem.Description + "`" , `"{#SERVICEDIR}`":`"" + $exe_dir + "`" }"
         write-host $line
     }
    }
    
    # Close the JSON message
    write-host
    write-host " ]"
    write-host "}"
    write-host
    Can anyone tell me what am I doing wrong?
  • aib
    Senior Member
    • Jan 2014
    • 1615

    #2
    Do you mind to show the output of zabbix_get command ?

    Code:
    zabbix_get -s {IP_of_CLIENT} -k {name_of_lld_script}
    Also check the thread "Windows services monitoring". There are some nice ideas and programs for your needs.
    Last edited by aib; 22-05-2014, 17:32.
    Sincerely yours,
    Aleksey

    Comment

    • nail
      Member
      • Jun 2012
      • 32

      #3
      Originally posted by aib
      Do you mind to show the output of zabbix_get command ?

      Code:
      zabbix_get -s {IP_of_CLIENT} -k {name_of_lld_script}
      Also check the thread "Windows services monitoring". There are some nice ideas and programs for your needs.

      problem is here:
      Code:
      { "{#SERVICESTATE}":"Running" , "{#SERVICEDISPLAY}":"IPsec Policy Agent" , "{#SERVICENAME}":"PolicyAgent" , "{#SERVICEDESC}":"Internet Protocol security (IPsec) supports network-level peer authentication, data origin authentication, data integrity, data confidentiality (encryption), and replay protection.  This service enforces IPsec policies created through the IP Security Policies snap-in or the command-line tool "netsh ipsec".  If you stop this service, you may experience network connectivity issues if your policy requires that connections use IPsec.  Also,remote management of Windows Firewall is not available when this service is stopped." , "{#SERVICEDIR}":"C:/Windows/system32/" },
      the " in description made this error happen.
      http://jsonlint.com/ - this helped a lot.
      Last edited by nail; 23-05-2014, 09:13.

      Comment

      • zeds
        Junior Member
        Zabbix Certified Specialist
        • Jan 2009
        • 20

        #4
        check your JSON result with http://jsonlint.com/

        I suspect that you do not process last comma in your output:
        $line = " { `"{#SERVICESTATE}`":`"" + $objItem.State + "`" , `"{#SERVICEDISPLAY}`":`"" + $objItem.DisplayName + "`" , `"{#SERVICENAME}`":`"" + $objItem.Name + "`" , `"{#SERVICEDESC}`":`"" + $objItem.Description + "`" , `"{#SERVICEDIR}`":`"" + $exe_dir + "`" },"
        write-host $line

        your json must not be
        {LINE},
        {LINE},
        }
        but
        {LINE},
        {LINE}
        }

        Comment

        • aib
          Senior Member
          • Jan 2014
          • 1615

          #5
          Originally posted by zeds
          check your JSON result with http://jsonlint.com/

          I suspect that you do not process last comma in your output:
          $line = " { `"{#SERVICESTATE}`":`"" + $objItem.State + "`" , `"{#SERVICEDISPLAY}`":`"" + $objItem.DisplayName + "`" , `"{#SERVICENAME}`":`"" + $objItem.Name + "`" , `"{#SERVICEDESC}`":`"" + $objItem.Description + "`" , `"{#SERVICEDIR}`":`"" + $exe_dir + "`" },"
          write-host $line

          your json must not be
          {LINE},
          {LINE},
          }
          but
          {LINE},
          {LINE}
          }
          You are wrong.
          nail was very careful about last comma and he made a special IF-THEN-ELSE block for last comma situation
          Code:
           if ($i -lt $colItems.Count){
          Sincerely yours,
          Aleksey

          Comment

          Working...