Ad Widget

Collapse

Value should be a JSON object result during discovery

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abel5405
    Member
    • Jan 2019
    • 47

    #1

    Value should be a JSON object result during discovery

    Greetings All,
    So I have a user parameter to do a low a discovery of the IIS log locations on our Web servers. Below is the result.

    8224:20190501:045018.748 EXECUTE_STR() command:'powershell "Get-Website | % { $_.logFile.Directory} | ConvertTo-Json"' len:19 cmd_result:'"D:\\Website\\Logs"'
    8224:20190501:045018.748 for key [IISLogLocation.discovery] received value ["D:\\Website\\Logs"]
    8224:20190501:045018.748 In process_value() key:'ServerName:IISLogLocation.discovery' value:'"D:\\Website\\Logs"'
    8224:20190501:045018.748 In send_buffer() host:'XX.XX.XX.XX' port:XXXXX entries:1/100
    8224:20190501:045018.748 send_buffer() now:1556707818 lastsent:1556707816 now-lastsent:2 BufferSend:5; will not send now
    8224:20190501:045018.748 End of send_buffer():SUCCEED
    8224:20190501:045018.748 In need_meta_update() key:IISLogLocation.discovery
    8224:20190501:045018.748 End of need_meta_update():FAIL

    For the life of me I can not figure out why it keeps getting the error "Value should be a JSON". I read several posts that seemed to indicate the back slash "" was the issue and it needed to be escaped. By outputting the PowerShell command as JSON I would have thought that would have taken care of it but the error still persists. Any help with this would be greatly appreciated.

    v/r
    Chris
  • brunohl
    Senior Member
    Zabbix Certified Specialist
    • Mar 2019
    • 215

    #2
    Hello,

    The LLD should always return valid JSON. This:
    Code:
     ["D:\\Website\\Logs"]
    Works as JSON, but I guess that not in a way that LLD is able to parse. I always follow the File System Discovery when creating my own LLDs, and make the return something like:
    Code:
    {
      "data": [
        {
          "{#ID}": 160,
          "{#NAME}": "Break (7º Floor)",
          "{#IP}": "10.200.10.12",
          "{#TIPO}": "BREAK"
        },
        {
          "{#ID}": 170,
          "{#NAME}": "LOGOUT (7º Floor)",
          "{#IP}": "10.200.10.11",
          "{#TIPO}": "LOGOUT"
        }
      ]
    }
    So you can iterate through it and parse your values in your object to build your keys, names and triggers.

    Comment

    • abel5405
      Member
      • Jan 2019
      • 47

      #3
      Thanks for the reply Brunohl, but that is a little over my head. I am not a JSON expert by any means. Would happen to have an example of how you would do my data stream? Many thanks in advance for your help.

      v/r
      Chris

      Comment

      • brunohl
        Senior Member
        Zabbix Certified Specialist
        • Mar 2019
        • 215

        #4
        OK, I guess that it would work like this:

        Code:
        {
          "data": [
            {
              "{#SERVER}": "Server 1",
              "{#LOGPATH}": "D:\Website\Logs\Server1"
            },
            {
              "{#SERVER}": "Server 2",
              "{#LOGPATH}": "D:\Website\Logs\Server2"
            }
          ]
        }
        If you'd like to learn more on JSON structure I would recommend you to read a bit on JSON (https://www.json.org/).

        Comment

        • abel5405
          Member
          • Jan 2019
          • 47

          #5
          I very much appreciate the reply but not sure that's going to help me much. What I am trying to do is discover the location of the IIS Logs in Zabbix. Below is how I am trying to do it.

          1 - Use a User Parameter to get the IIS Log Location.
          UserParameter=IISLogLocation.discovery[*],powershell.exe -NoProfile -ExecutionPolicy Bypass "Get-Website | % { $_.logFile.Directory} | ConvertTo-Json"
          2 - The output of the User Parameter is:
          "D:\\Website\\Logs"
          3 - From that I am trying to create a new Application with the following syntax:
          IIS Log Location Size {#IISLogLocation}
          4 - Then I am trying to get a folder size using the following syntax:
          vfs.dir.size[{#IISLogLocation},log.^+\.cab$,,0]
          5 - Then once I have that information I hope to create an action to compress the IIS Logs in the folder that was discovered.

          What I am seeing in the log is this:
          6112:20190502:041811.187 In process_value() key:'ServerName:IISLogLocation.discovery' value:'"D:\\Website\\Logs"'
          6112:20190502:041811.187 In send_buffer() host:'ZabixServer' port:10051 entries:0/100
          6112:20190502:041811.187 End of send_buffer():SUCCEED
          6112:20190502:041811.187 buffer: new element 0
          6112:20190502:041811.187 End of process_value():SUCCEED
          6112:20190502:041811.187 In need_meta_update() key:IISLogLocation.discovery
          6112:20190502:041811.187 End of need_meta_update():FAIL
          6112:20190502:041811.187 End of process_active_checks()
          6112:20190502:041811.187 In get_min_nextcheck()
          6112:20190502:041811.187 End of get_min_nextcheck():1556792335
          6112:20190502:041811.187 In send_buffer() host:'ZabbixServer' port:10051 entries:1/100
          6112:20190502:041811.187 JSON before sending [{"request":"agent data","data":[{"host":"ServerName","key":"IISLogLocation.discove ry","value":""D:\\\\Website\\\\Logs"","clock":1556 792290,"ns":379048500}],"clock":1556792290,"ns":386458400}]
          6112:20190502:041811.187 JSON back [{"response":"success","info":"processed: 1; failed: 0; total: 1; seconds spent: 0.000046"}]
          6112:20190502:041811.203 In check_response() response:'{"response":"success","info":"processed: 1; failed: 0; total: 1; seconds spent: 0.000046"}'
          6112:20190502:041811.203 info from server: 'processed: 1; failed: 0; total: 1; seconds spent: 0.000046'
          6112:20190502:041811.203 End of check_response():SUCCEED
          6112:20190502:041811.203 OK
          6112:20190502:041811.203 End of send_buffer():SUCCEED

          I have also tried this with out the ConvertTo-JSON with no luck. It looks like the agent tries to convert the value to Jason:

          4812:20190502:042931.064 EXECUTE_STR() command:'powershell.exe -NoProfile -ExecutionPolicy Bypass "Get-Website | % { $_.logFile.Directory}"' len:15 cmd_result:'D:\Website\Logs'
          4812:20190502:042931.064 for key [IISLogLocation.discovery] received value [D:\Website\Logs]
          4812:20190502:042931.064 In process_value() key:'ServerName:IISLogLocation.discovery' value:'D:\Website\Logs'
          4812:20190502:042931.064 In send_buffer() host:'ZabbixServer' port:10051 entries:0/100
          4812:20190502:042931.064 End of send_buffer():SUCCEED
          4812:20190502:042931.064 buffer: new element 0
          4812:20190502:042931.064 End of process_value():SUCCEED
          4812:20190502:042931.064 In need_meta_update() key:IISLogLocation.discovery
          4812:20190502:042931.080 End of need_meta_update():FAIL
          4812:20190502:042931.080 End of process_active_checks()
          4812:20190502:042931.080 In get_min_nextcheck()
          4812:20190502:042931.080 End of get_min_nextcheck():1556792981
          4812:20190502:042931.080 In send_buffer() host:'ZabbixServer' port:10051 entries:1/100
          4812:20190502:042931.080 JSON before sending [{"request":"agent data","data":[{"host":"CAEW2K8AM8DEPL1","key":"IISLogLocation.di scovery","value":"D:\\Website\\Logs","clock":15567 92971,"ns":250222700}],"clock":1556792971,"ns":265251600}]
          4812:20190502:042931.095 JSON back [{"response":"success","info":"processed: 1; failed: 0; total: 1; seconds spent: 0.000065"}]
          4812:20190502:042931.095 In check_response() response:'{"response":"success","info":"processed: 1; failed: 0; total: 1; seconds spent: 0.000065"}'
          4812:20190502:042931.095 info from server: 'processed: 1; failed: 0; total: 1; seconds spent: 0.000065'
          4812:20190502:042931.095 End of check_response():SUCCEED
          4812:20190502:042931.095 OK
          4812:20190502:042931.095 End of send_buffer():SUCCEED


          I think it's this line, "End of need_meta_update():FAIL", is the key but I do not know what it means. The rest of the lines look ok to me so this should work but it's not. This is very important for my shop and would appreciate a solution if possible. Many thanks in advance for your time.

          v/r
          Chris

          Comment

          • brunohl
            Senior Member
            Zabbix Certified Specialist
            • Mar 2019
            • 215

            #6
            Hey,

            I don't know if you got what LLD is for. Are you trying to create just one key? Maybe using a host macro?

            If you check the manual, all the examples of the JSON that should be returned are like the one that I sent you, so I guess either you create a script to deliver it in that format or try to do it some other way.

            Comment

            Working...