AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[json](server)

Martin Hope
IGGt
Asked: 2021-11-18 07:21:34 +0800 CST

使用 Zabbix 记录来自 REST api 的 JSON 输出?可能吗

  • 1

我正在尝试使用 Zabbix (5.0) 来捕获来自 REST API 的响应。

如果我将以下内容粘贴到网络浏览器(或 wget / curl 等)

http://{username}:{password}@10.1.2.3:8443/api/metadata/

我得到了我期望的回应:

{"items":[{"name":"this_is_my_name"}]}

我试图捕捉name到 zabbix 的价值。

web scenario我已经针对我的模板设置了一个,并且在该steps部分中我有:

Name: test_name
URL: http://{username}:{password}@10.1.2.3:8443/api/metadata/
Raw Data
Retrieve Mode: Body
Timeout: 15s
Required String: $.items:["name"]
Required Status Code: 200

然后查看它的最新数据,我看到我有一个响应 conde 200,但有一个错误:

required pattern "$.items:["name"]" was not found on http://{username}:{password}@10.1.2.3:8443/api/metadata/

我在必填字符串字段中尝试了各种变体,结果始终相同。

我是否错过了什么,或者误解了什么。Zabbix 甚至会做我想做的事情吗?

http json zabbix
  • 1 个回答
  • 665 Views
Martin Hope
Ress
Asked: 2021-10-05 03:02:26 +0800 CST

在“命令”任务中动态传递 json 作为参数

  • 0

我的剧本中有这个任务:

- name: Update instance tags
    command: oci compute instance update -c {{ compartment }} --freeform-tags {{ tag_var_json }}

根据该命令的oracle 文档,该参数--freeform-tags接受一个表示标签键值对的 json。我需要在剧本本身中动态创建这个 json,所以在运行该任务之前,我有一个用于测试目的:

  - name: Create a json object to use as tag
    set_fact:
      tag_var: '{ "test": "thisisatest" }'
    set_fact:
      tag_var_json: "{{ tag_var | to_json }}"

但我一定是做错了什么,因为我不断收到这个错误:
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'tag_var' is undefined

有没有更简单的方法可以直接在剧本中创建 json 并将其作为参数传递给该参数?

谢谢你。

json ansible
  • 1 个回答
  • 207 Views
Martin Hope
AniK
Asked: 2021-08-19 03:27:02 +0800 CST

附加 JSON 字典

  • 1

我正在使用 ansible 2.9 并且无法寻找在 JSON 结构下方附加数据的方法

"Variables":[
    {
        "Strings": [
            "abc",
            "xyz"
        ],
        "Inputs": true
    }
]

我想在字符串中添加“efg”,但不确定在此使用的语法是什么。使用 Ansible set_fact 附加它。

我知道我们可以使用 combine_filter 做到这一点,但我猜这只适用于 ansible 2.10。关于如何做到这一点的任何建议。

json ansible
  • 1 个回答
  • 483 Views
Martin Hope
safect
Asked: 2021-05-18 00:39:27 +0800 CST

使用嵌套值将 JSON 转换为 CSV 的问题

  • 0

到目前为止,我过去将标准 JSON 转换为 CSV 没有问题jq。但是现在我的数据变得复杂了。

主要的基本标签是account和subaccount。所有其他值都是变量。该条目year具有可变值并经常随时间更改。这是我无法解决的任务。

这是输出

{
    "jsonrpc": "2.0",
    "result": {
        "current": [{
            "number": 171883808,
            "commission": 10,
            "year": [
                [1999, 9224, 0],
                [2000, 41919, 9224],
                [2001, 162945, 41919],
                [2002, 397993, 162945],
                [2003, 751570, 397993],
                [2004, 886466, 751570]
            ],
            "status": true,
            "last": 9782473,
            "account": "VFUIJOPQW",
            "subaccount": "BLPORDGS"
        }, {
            "number": 69999012,
            "commission": 15,
            "year": [
                [2012, 97587, 0],
                [2013, 472685, 97587],
                [2014, 605963, 472685],
                [2015, 698634, 605963],
                [2016, 1931094, 1745922]
            ],
            "status": true,
            "last": 9782490,
            "account": "VFUIJOXXX",
            "subaccount": "BLPORXXX"
        }],
    "id": 1
    }
}
csv json convert jq
  • 1 个回答
  • 236 Views
Martin Hope
JohnLBevan
Asked: 2021-04-22 04:09:43 +0800 CST

Azure 策略定义即代码:避免重复的参数定义

  • -1

我正在寻找使用基础架构即代码创建许多 Azure 策略。

MS 文档建议的结构如下:

.
|
|- policies/  ________________________ # Root folder for policy resources
|  |- policy1/  ______________________ # Subfolder for a policy
|     |- policy.json _________________ # Policy definition
|     |- policy.parameters.json ______ # Policy definition of parameters
|     |- policy.rules.json ___________ # Policy rule
|     |- assign.<name1>.json _________ # Assignment 1 for this policy definition
|     |- assign.<name2>.json _________ # Assignment 2 for this policy definition
|  |- policy2/  ______________________ # Subfolder for a policy
|     |- policy.json _________________ # Policy definition
|     |- policy.parameters.json ______ # Policy definition of parameters
|     |- policy.rules.json ___________ # Policy rule
|     |- assign.<name1>.json _________ # Assignment 1 for this policy definition
|     |- assign.<name2>.json _________ # Assignment 2 for this policy definition
|

这是有道理的,但我见过的所有策略定义示例都包括参数定义;policy.parameters.json所以如果只是复制信息,我看不到拥有单独文件的价值。

问题

有没有办法避免这种重复?例如,通过让policy.json文件引用policy.parameters.json文件而不是复制其内容,或者通过这种复制是否增加了一些价值?

(规则文件也会出现同样的情况;我假设该部分的答案是相同的......)

这种重复的例子

从 Azure 社区策略存储库:

策略文件包括以下几行:

"parameters": {
  "tagName": {
    "type": "String",
    "defaultValue": "DateCreated",
    "metadata": {
      "displayName": "Tag Name",
      "description": "Name of the tag, such as 'Date'"
    }
  }
}

参数文件完全复制了在上面的参数部分找到的内容(几乎;在这种情况下,描述略有不同,但这感觉像是一个错误而不是一个理由):

{
  "tagName": {
    "type": "String",
    "defaultValue": "DateCreated",
    "metadata": {
      "displayName": "Tag Name",
      "description": "Name of the tag, such as 'DateCreated'"
    }
  }
}
azure json azure-policies
  • 1 个回答
  • 110 Views
Martin Hope
Lethargos
Asked: 2021-04-06 23:48:22 +0800 CST

ansible - docker 容器中环境变量的模板 json

  • 0

我正在尝试将单行 json 字符串分配给 docker 容器中的环境变量。这是json的样子:

{"ip_access": {"IP_whitelist": {"192.168.99.19/32": "grafana/status (Provider)"}}, "vhosts": {"prometheus1": {"dns_names": ["prometheus1.company.internal"], "add_lines_443": ["include IP_whitelist;", "set $prometheus http://prometheus:9090;", "location / { proxy_pass $prometheus; }"], "options": {"cert_path": "/etc/ssl/certs/prometheus1.crt", "key_path": "/etc/ssl/private/prometheus1.key"}}}}

因此,["prometheus1.company.internal"]我不想拥有["{{ inventory_hostname }} .company.internal"](以及其他prometheus1.

我正在使用 docker_container 如下:

- name: create nginx reverse proxy container
  docker_container:
    image: registry.company.com/devops/nginx-reverseproxy:{{ nginx_version }}
    name: nginx-reverseproxy
    labels:
      role=metrics
    volumes:
      - /etc/ssl/certs/{{ inventory_hostname }}.crt:/etc/ssl/certs/{{ inventory_hostname }}.crt
      - /etc/ssl/private/{{ inventory_hostname }}.key:/etc/ssl/private/{{ inventory_hostname }}.key
    container_default_behavior: compatibility
    networks_cli_compatible: yes
    network_mode: default
    purge_networks: yes
    networks:
      - name: metrics-net
      - name: proxy-net
    env:
      STAGING_ENVIRONMENT: 'production'
      NGINX_VHOSTS_JSON: '{{ lookup("template", "rproxy/nginx_vhosts_prometheus_develop.j2") }}'

不幸的是,我不断得到:

TASK [prometheus : create nginx reverse proxy container] **********************************************
fatal: [prometheus_vag]: FAILED! => {"changed": false, "msg": "Non-string value found for env option. Ambiguous env options must be wrapped in quotes to avoid them being interpreted. Key: NGINX_VHOSTS_JSON"}

奇怪的是,如果我只是使用模板模块,它会按预期工作:

  template:
    src: rproxy/nginx_vhosts_prometheus_develop.j2
    dest: /tmp/tempo.json
  when: "prometheus_host in inventory_hostname"
  tags:
    - copytmp

inventory_hostname将被库存中的实际价值取代,我得到了正确的东西。此外,如果我将这个确切的结果作为 yaml playbook 中 NGINX_VHOSTS_JSON 的值粘贴到 playbook 中,它也可以正常工作。

但是查找模板似乎没有提供预期的字符串。

有什么想法可以解决这个问题吗?

json ansible jinja2
  • 2 个回答
  • 811 Views
Martin Hope
sarvesh.lad
Asked: 2020-12-08 07:09:58 +0800 CST

包含 json 数据到 Influx 的 Telegraf Tail 文件

  • 0

如何通过拖尾包含 JSON 数据的文件将 json 数据提取到 influx 中?

例如:

我的日志是这样的:

2020-12-01T18:34:06+02:00 10.132.90.194 {"wfd_successful_hits_sec": "0", "sql_hits_sec_max": "0", "timestamp": "2020/12/01 18:34:01", "connection_sec_max": "1922", "http_hits_sec_max": "1106", "http_hits_sec": "106", "wfd_successful_hits_sec_max": "0", "sql_hits_sec": "0", "sql_audit_phase2_events_sec_max": "0", "hdfs_hits_sec": "0", "connection_sec": "26"}

有没有办法只提取 JSON 部分并将其发送给 influx?

我知道 grok 模式(\{.*\})$会提取 JSON 部分。

我的配置如下所示:

[global_tags]
[agent]
  interval = "10s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "0s"
  precision = ""
  hostname = ""
  omit_hostname = false
[[inputs.tail]]
  files = ["/opt/share/host*log"]
  data_format = "json"
[[outputs.influxdb_v2]]
  urls = ["http://localhost:8086"]
  token = "TOKEN"
  organization = "ORG"
  bucket = "performance_stats
json telegraf
  • 1 个回答
  • 357 Views
Martin Hope
user2680530
Asked: 2020-05-13 12:52:29 +0800 CST

在 Ansible 中构建 JSON 对象列表

  • 3

我正在尝试在 Ansible 中构建 JSON 对象的数组/列表。我的剧本是通过指定来调用的--extra-vars "userids=123456,654321"。

然后我尝试使用以下内容构建列表。“待定”只是一个占位符。我将在后面的剧本中使用从 SQL 查询中检索到的数据填充这些值。

- name: Initiate User List
      set_fact:
        all_users: []    

    - name: Add new JSON Objects to List
      set_fact:
        all_users: "{{ all_users+ [{ 'UserID': '{{ item }}', 'UserType': 'TBD', 'UserName': 'TBD' }] }}"
      loop: "{{ userids.split(',') }}"

    - name: Debug
      debug:
        var: all_users

列表排序的构建,但它跳过了列表中的第一项。这是结果输出:

TASK [Initiate User List] *************************************************************************************************************************************************************
ok: [localhost]

TASK [Add new JSON Objects to List] ******************************************************************************************************************************************************
ok: [localhost] => (item=123456)
ok: [localhost] => (item=654321)

TASK [Debug] *****************************************************************************************************************************************************************************
ok: [localhost] => {
    "all_users": [
        {
            "UserID": "654321",
            "UserType": "TBD",
            "UserName": "TBD"
        },
        {
            "UserID": "{{ item }}",
            "UserType": "TBD",
            "UserName": "TBD"
        }
    ]
}

我不确定我错过了什么。我尝试在循环任务之前执行“set_fact”以首先执行 split(),但这没有帮助。我也试过“with_items”而不是循环,没有运气

json ansible
  • 1 个回答
  • 13691 Views
Martin Hope
Mise
Asked: 2020-05-13 00:01:07 +0800 CST

如何以可读格式读取 docker json 日志文件?

  • 2

部署新映像版本时,我总是备份 docker json 日志文件。

是否有一个 linux 程序或命令可以让我以可读格式浏览备份的 json 日志文件的日志输出,例如使用“docker logs”时?

或更广泛的问题:处理 docker 日志记录的好方法是什么,让我可以轻松地查看已废弃图像中的日志?

linux logging docker json
  • 1 个回答
  • 478 Views
Martin Hope
Michael Martinez
Asked: 2016-10-05 10:11:20 +0800 CST

如何告诉 jq 为 aws ec2 cli 返回的每个实例打印两个键的内容

  • 7

运行 aws ec2 describe-instances 将返回类似于以下内容的 json 文本:

{
    "Reservations": [
        {
            "Instances": [
                  "PublicDnsName": "ec2..."
                    "VpcId": "vpc-...",
                        ...
            "Instances": [

我知道对于每个“实例”,我可以提取单个字段的内容,例如 PublicDnsName,使用 jq 如下: jq '.Reservations[].Instances[].PublicDnsName'这将列出我的实例的 dns 名称但是我如何提取两个或多个字段并用空格分隔它们还是逗号什么的?我希望为每个实例并排列出 PublicDnsName 和 VpcId。

具体来说,我要查找的是 VpcId 为空、未定义或不存在的实例列表。换句话说,我想要一个我的经典实例的列表,我需要通过 api 来处理结果。

amazon-ec2 json
  • 1 个回答
  • 10821 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve