当前位置:网站首页>Splunk中single value视图使用将数值替换为文字
Splunk中single value视图使用将数值替换为文字
2022-07-07 05:19:00 【QYHuiiQ】
在splunk的single value视图中,之前我们一直使用的是直接根据值来展示颜色,也就是single value中用的是什么值,那么颜色的设置就是根据这个值来显示的,换言之,这个展示的值必须是设置颜色规则的值。而有些情况下我们可能只想展示一个指标的名称,然后根据这个指标的值设置颜色,也就是说将原来展示值改为展示指标名称,不展示具体的值,但是依然以这个值来设置颜色。
对于这种案例,我们的实现思路就是还是按照值来展示,最后再将这个值替换为指标名称(文本)。
假设原来的情况是这样的,当grade值大于60时显示绿色,小于等于60时,显示红色,注意这楼里我们的视图中是根据grade的值设置颜色,并将grade的值展示出来:
| makeresults
| eval grade="37"
| table grade

而我们现在要实现的需求是,将这个展示的值变为指标名称/文本,颜色规则依然不变。
如果我们使用replace进行替换最终显示的值,那么使用"格式"里设置的颜色规则自然也会失效,因为"格式"中的规则是在spl执行结束后才生效的,可以看一下这个测试:
| makeresults
| eval grade="37"
| table grade
| replace "37" with "Student Grade" in grade
因为最终的值被替换为文本了,所以这个数值类型的规则设置就失效了,最终展示的是灰色。
因此,我们需要使用的方法是使用Splunk官方提供的一个rangemap的命令来帮助我们设置颜色,然后再replace文本,实现方法如下:
| makeresults
| eval grade="37"
| rangemap field=grade low=61-100 severe=0-60 default=gray
#这里low和severe分别对应的是绿色和红色,这是Splunk官方默认的配置,可以参考官方文档中的其他使用案例。
#如果你要设置的颜色规则是具体的某个数值而不是范围,那么你可以设置为-前后数值相同,都设置为你要定义的那个数值即可。如:| rangemap field=grade low=60-60 severe=100-100 default=gray
此时需要注意将"格式"中的颜色禁用掉,因为我们是通过spl里的rangemap来设置颜色的。

设置好颜色后,开始替换展示的值:
| makeresults
| eval grade="87"
| rangemap field=grade low=61-100 severe=0-60 default=gray
| replace "87" with "Student Grade" in grade
#replace后面的第一个参数是被替换的值,with后面是替换后的值,in后面的是替换哪个字段里的值

此时视图中展示的值就变成了一个自定义的文本,而与颜色设置背后的值无关,需要注意的是replace后面的值是只当grade字段的值为"87"时才会替换,否则不会替换。

这里我只是对值的替换做一个示例,但是实际应用中replace的值可能时多样的,所以需要具体再根据业务调整逻辑。
以上就是通过rangemap和replace实现single value中的展示值替换,更多使用案例可以参考官方文档:
边栏推荐
- Search for an element in a binary search tree (BST)
- Zsh shell adds automatic completion and syntax highlighting
- CTF-WEB shrine模板注入nmap的基本使用
- Qinglong panel -- finishing usable scripts
- 雅思考试自己的复习进度以及方法使用【日更版】
- Use of out covariance and in inversion in kotlin
- 饥荒云服管理脚本
- 央视太暖心了,手把手教你写HR最喜欢的简历
- Unityhub cracking & unity cracking
- Example of file segmentation
猜你喜欢

eBPF Cilium实战(2) - 底层网络可观测性

【雅思口语】安娜口语学习记录 Part2

buureservewp(2)

The simple problem of leetcode is to judge whether the number count of a number is equal to the value of the number

CCTV is so warm-hearted that it teaches you to write HR's favorite resume hand in hand

Network learning (I) -- basic model learning

一文了解如何源码编译Rainbond基础组件

Avatary's livedriver trial experience

Network learning (III) -- highly concurrent socket programming (epoll)

漏洞复现-easy_tornado
随机推荐
复杂网络建模(二)
Domain specific language / DSL in kotlin
让Livelink初始Pose与动捕演员一致
Unityhub cracking & unity cracking
The element with setfieldsvalue set is obtained as undefined with GetFieldValue
积分商城管理系统中应包含的四大项
game攻防世界逆向
opencv学习笔记四——膨胀/腐蚀/开运算/闭运算
Leetcode medium question my schedule I
Use of JMeter
Introduction à l'objet blob
Interactive book delivery - signed version of Oracle DBA work notes
【Go ~ 0到1 】 第七天 获取时间戳,时间比较,时间格式转换,Sleep与定时器
Lua 编程学习笔记
Don't stop chasing the wind and the moon. Spring mountain is at the end of Pingwu
Zcmu--1396: queue problem (2)
JS复制图片到剪切板 读取剪切板
It took "7" years to build the robot framework into a micro service
Function extension, attribute extension and non empty type extension in kotlin
Standard function let and generic extension function in kotlin