hertzbeat icon indicating copy to clipboard operation
hertzbeat copied to clipboard

snmp结果需要做值映射转换

Open bestsiyue opened this issue 7 months ago • 9 comments

Question

Image

Image

目前使用snmp获取的值,尤其是状态类的值,基本都以数字结果呈现。这样在展示时并不能很好的看到真实的状态。我也搜索过相关issue,目前并没有很好的解决办法。或许可以参考zabbix的实现逻辑,在模板中添加一个mapping配置项,在mapping中列举数字的映射关系,这样可以很好的展示想要的结果。

bestsiyue avatar May 21 '25 01:05 bestsiyue

+1 good ideas, but the mapping logic we need design carefully.

tomsun28 avatar May 21 '25 13:05 tomsun28

hi, is it possible to use the existing calculates, which is based on JexlExpression underneath?

valueString = (value == 1 ? "Normal" : (value == 2 ? "Warning" : "Critical"));

refer to : https://hertzbeat.apache.org/zh-cn/docs/advanced/extend-http-default

bigcyy avatar May 21 '25 15:05 bigcyy

嗨,是否可以使用现有的 ,它是基于 Below的?calculates``JexlExpression

valueString = (value == 1 ? "Normal" : (value == 2 ? "Warning" : "Critical"));

请参阅 : https://hertzbeat.apache.org/zh-cn/docs/advanced/extend-http-default

hi,我参考了你的示例文档,文档中更多的是对于json结果的获取,snmp结果与json返回值有明显区别。

或许snmp的mappings可以这么设计?

` aliasFields: - memoryDeviceIndex - memoryDeviceManufacturerName - memoryDeviceStatus - memoryDeviceLocationName - memoryDeviceSpeed - memoryDeviceSize

mappings:
    memoryDeviceStatus: [1: "ABSENT", 2: "OK", 3: "WARNING", 4: "CRITICAL"]


# mapping and conversion expressions, use these and aliasField above to calculate metrics value
# eg: cores=core1+core2, usage=usage, waitTime=allTime-runningTime
calculates:
  - Index=memoryDeviceIndex
  - ManufacturerName=memoryDeviceManufacturerName
  - Status=memoryDeviceStatus
  - LocationName=memoryDeviceLocationName
  - Speed=memoryDeviceSpeed
  - Size=memoryDeviceSize / 1024 / 1024

`

bestsiyue avatar May 22 '25 03:05 bestsiyue

At the protocol level, the collected metrics are mapped to aliasField - value, and then further processed using a calculation expression to produce realField - realValue. If I understood the code correctly, I hope this is helpful to you.

fields:
  - field: myStatus
    type: 1
    i18n:
      zh-CN: 状态
      en-US: Status

aliasFields:
  - memoryDeviceStatus

calculates:
  - myStatus = (memoryDeviceStatus == 1 ? "ABSENT" : (memoryDeviceStatus == 2 ? "OK" : (memoryDeviceStatus == 3 ? "WARNING" : "CRITICAL")))

refer to:

bigcyy avatar May 22 '25 04:05 bigcyy

在协议级别,收集的指标映射到 aliasField - value,然后使用计算表达式进一步处理以生成 realField - realValue。如果我正确理解了代码,希望这对您有所帮助。

fields:
  - field: myStatus
    type: 1
    i18n:
      zh-CN: 状态
      en-US: Status

aliasFields:
  - memoryDeviceStatus

calculates:
  - myStatus = (memoryDeviceStatus == 1 ? "ABSENT" : (memoryDeviceStatus == 2 ? "OK" : (memoryDeviceStatus == 3 ? "WARNING" : "CRITICAL")))

指:

很抱歉,我不懂java代码,不过我会测试这种方式。谢谢

bestsiyue avatar May 22 '25 05:05 bestsiyue

在协议级别,收集的指标映射到 aliasField - value,然后使用计算表达式进一步处理以生成 realField - realValue。如果我正确理解了代码,希望这对您有所帮助。

fields:
  - field: myStatus
    type: 1
    i18n:
      zh-CN: 状态
      en-US: Status

aliasFields:
  - memoryDeviceStatus

calculates:
  - myStatus = (memoryDeviceStatus == 1 ? "ABSENT" : (memoryDeviceStatus == 2 ? "OK" : (memoryDeviceStatus == 3 ? "WARNING" : "CRITICAL")))

指:

Image 或许这是一个不太正确的写法?

bestsiyue avatar May 22 '25 05:05 bestsiyue

在协议级别,收集的指标映射到 aliasField - value,然后使用计算表达式进一步处理以生成 realField - realValue。如果我正确理解了代码,希望这对您有所帮助。

fields:
  - field: myStatus
    type: 1
    i18n:
      zh-CN: 状态
      en-US: Status

aliasFields:
  - memoryDeviceStatus

calculates:
  - myStatus = (memoryDeviceStatus == 1 ? "ABSENT" : (memoryDeviceStatus == 2 ? "OK" : (memoryDeviceStatus == 3 ? "WARNING" : "CRITICAL")))

指:

Image 或许这是一个不太正确的写法?

 "myStatus = (memoryDeviceStatus == 1 ? 'ABSENT' : (memoryDeviceStatus == 2 ? 'OK' : (memoryDeviceStatus == 3 ? 'WARNING' : 'CRITICAL')))"

bigcyy avatar May 22 '25 06:05 bigcyy

https://dl.360safe.com/public/360%E6%97%A5%E5%BF%97%E6%94%B6%E9%9B%86%E4%B8%8E%E5%88%86%E6%9E%90%E7%B3%BB%E7%BB%9F%E6%93%8D%E4%BD%9C%E6%8C%87%E5%8D%97pdf_52b3bea1071054aa2f04c8ebbcaa8f1a_1.0.0.pdf
8.2.1.4数据映射 This is a commercial product that supports multiple mapping way and is for reference only

MasamiYui avatar May 22 '25 10:05 MasamiYui

对对对 ,太需要了!!!

状态值映射

  • ifOperStatus=ifOperStatusRaw@map(1=up,2=down)  

还有@where和@count()函数等: calculates: # 直接使用字符串过滤统计 - total_devices=status_list@where(status_list!="Empty")@count() - connected_devices=status_list@where(status_list=="Connected")@count() - disconnected_devices=status_list@where(status_list=="Unconnect")@count() - empty_devices=status_list@where(status_list=="Empty")@count()

gaows20 avatar Jun 10 '25 07:06 gaows20