【发布时间】:2021-10-25 20:40:32
【问题描述】:
我有如下示例 yaml
scrape_configs:
- job_name: 'snmp-moxa'
static_configs:
- targets:
- job_name: prometheus
static_configs:
- targets:
- localhost:9090
我想添加job_name等于'snmp-moxa'的IP地址,我尝试了以下但没有工作
验证它到达正确的路径
# yq eval '.scrape_configs[] | select(.job_name == "snmp-moxa") | .static_configs' prom.yaml
- targets:
以下是两次更新值的尝试
#yq eval -i '.scrape_configs[] | select(.job_name == "snmp-moxa") | .static_configs.targets |= . + ["10.11.158.177"]' prom.yaml
Error: Cannot index array with 'targets' (strconv.ParseInt: parsing "targets": invalid syntax)
# yq eval -i '.scrape_configs[] | select(.job_name == "snmp-moxa") | .static_configs.targets |= . + [10.11.158.177]' prom.yaml
Error: expected end of expression but found '|', please check expression syntax
生成的 yaml 应该是这样的
scrape_configs:
- job_name: 'snmp-moxa'
static_configs:
- targets: 10.11.158.177
or
- targets:
- 10.11.158.177
- job_name: prometheus
static_configs:
- targets:
- localhost:9090
【问题讨论】: