Duansg opened a new issue, #3644:
URL: https://github.com/apache/hertzbeat/issues/3644

   ### Feature Request
   
   _No response_
   
   ### Is your feature request related to a problem? Please describe
   
   In some scenarios, there may be custom endpoints in the system (Spring Boot 
Actuator). However, due to historical reasons or the inability to modify 
existing response data, some custom endpoints return unformatted information.
   
   For example:
   
   ```json
   {
     "method": "GET",
     "time": 1754579874357,
     "type": "channelItem",
     "info": 
"{\"current\":537132,\"grantTotal\":63129,\"instanceCode\":\"CSDZMC\",\"timeMillis\":1754579874357}"
   }
   ```
   
   ---
   
   At first, I used the following configuration in the custom monitoring 
template
   ```yaml
     - name: channel_item_info
      i18n:
        en-US: channel item info
      priority: 2
      fields:
        - field: type
          i18n:
            en-US: type
          type: 1
          label: true
        - field: current
          i18n:
            en-US: current
          type: 0
        - field: instanceCode
          i18n:
            en-US: instanceCode
          type: 1
        - field: timeMillis
          i18n:
            en-US: timeMillis
          type: 1
      aliasFields:
        - type
        - $.info.current
        - $.info.instanceCode
        - $.info.timeMillis
      calculates:
        - type=type
        - current=$.info.current
        - instanceCode=$.info.instanceCode
        - timeMillis=$.info.timeMillis
      protocol: http
      http:
        host: ^_^host^_^
        port: ^_^port^_^
        url: ^_^base_path^_^/item-center/channelItem
        method: GET
        ssl: ^_^ssl^_^
        authorization:
          type: Basic Auth
          basicAuthUsername: ^_^username^_^
          basicAuthPassword: ^_^password^_^
        parseType: jsonPath
        parseScript: '$'
   ```
   
   However, I found that there was an abnormality in the collection process in 
the system,Similarly, the page cannot display any data for this metric.
   
   ```
   INFO  org.apache.hertzbeat.collector.dispatch.MetricsCollect - [Collect 
Failed, Run 19ms, All 23ms] Reason: parse response data error:Expected to find 
an object with property ['current'] in path $['info'] but found 
'java.lang.String'. This is not a json object according to the JsonProvider: 
'com.jayway.jsonpath.spi.json.JsonSmartJsonProvider'.
   ```
   
   
   ### Describe the solution you'd like
   
   Normal capture and rendering
   
   ### Describe alternatives you've considered
   
   After realizing that my JSON nesting issue (JSON path cannot directly 
process JSON information within strings),
   
   I started looking for inline functions for JSON paths, such as 
`$.info.parse('$.current')`, but the current version (2.9.0) does not support 
custom inline functions, and there are no JSON-related functions, although it 
is planned (https://github.com/json-path/JsonPath/issues/988), but it seems to 
have been shelved for a long time.
   
   --- 
   
   So I changed my approach. Since calculates supports dynamic calculations 
(org.apache.hertzbeat.collector.dispatch.MetricsCollect#transformCal), I 
started looking at how JEXL supports JSON parsing functions, such as: 
`current=json:apply($.info).current`
   
   I see that the current `JexlExpressionRunner` has already registered some 
[custom 
functions](https://commons.apache.org/proper/commons-jexl/apidocs/org/apache/commons/jexl3/JexlBuilder.html#namespaces(java.util.Map)),
 so i can just extend it here.
   
   ### Additional context
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to