如何基于Token输入在Splunk仪表盘中切换对应面板
用Splunk Token控制面板显示(基于下拉框选择)
你可以通过Splunk仪表盘面板的depends属性实现这个需求,无需依赖钻取功能。核心逻辑是为每个面板设置匹配对应token值的显示条件,当下拉框的$subtype$ token满足条件时,对应面板自动显示,其余面板隐藏。
现有下拉框配置(保留不变)
</input> <input type="dropdown" token="subtype"> <label>Subtype</label> <default>ha</default> <choice value="ha">HA</choice> <choice value="vpn">VPN</choice> <choice value="system">SYSTEME</choice> <initialValue>ha</initialValue> </input>
面板配置示例(添加depends属性)
为每个面板添加depends属性,指定对应的token匹配规则:
面板1(HA查询)
仅当$subtype$为ha时显示:
<panel depends="$subtype$=ha"> <title>HA 监控面板</title> <table> <search> <query>你的HA相关查询语句</query> <earliest>-24h@h</earliest> <latest>now</latest> </search> </table> </panel>
面板2(VPN查询)
仅当$subtype$为vpn时显示:
<panel depends="$subtype$=vpn"> <title>VPN 监控面板</title> <table> <search> <query>你的VPN相关查询语句</query> <earliest>-24h@h</earliest> <latest>now</latest> </search> </table> </panel>
面板3(SYSTEM查询)
仅当$subtype$为system时显示:
<panel depends="$subtype$=system"> <title>SYSTEM 监控面板</title> <table> <search> <query>你的SYSTEM相关查询语句</query> <earliest>-24h@h</earliest> <latest>now</latest> </search> </table> </panel>
效果说明
- 仪表盘加载时,因下拉框默认值为
ha,面板1会自动显示,其余面板隐藏。 - 切换下拉框选项时,Splunk会实时根据
$subtype$的当前值,自动显示对应面板并隐藏其他面板。
内容的提问来源于stack exchange,提问作者Sthefania Moreno Reina
相关产品推荐
相关产品推荐

