Ad Widget

Collapse

LLD extract embedded dicts from json

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aeromaks
    Junior Member
    • May 2012
    • 5

    #1

    LLD extract embedded dicts from json

    Hi folks,
    I'm trying to create template to monitor some metrics of docker swarm services/tasks.
    I've created a python script and LLD template. The script runs on docker swarm node and generates next json structure

    Code:
    {
    "service_name": "portainer_agent",
      "tasks": [
        {
         "task_id": "cje2yvfy6hmvxm41dduwzclcm",
         "image_tag": "latest"
       },
       {
         "task_id": "l7nzsod5k9goullaetlquppm9",
         "image_tag": "latest"
       },
       {
         "task_id": "to6udk3hjf7061ohfmeebuxww",
         "image_tag": "latest"
       }
      ],
      "repl_cnt": 3,
      "repl_req": 3,
      "image_tag_req": "latest"
    },
    {
      "service_name": "squirrel-stable_readonly",
        "tasks": [
        {
          "task_id": "7zwg1q89zlvvmozphe500xbk9",
          "image_tag": "infra-1108-08"
        },
        {
          "task_id": "cqkj25q600cqebg0qfz4ctjug",
          "image_tag": "infra-1108-08"
        },
        {
          "task_id": "ohc9acmzr7ylmknxkzczgsaf0",
          "image_tag": "infra-1108-08"
        }
       ],
      "repl_cnt": 3,
      "repl_req": 3,
      "image_tag_req": "infra-1108-08"
    },
    I've managed to extract service name as user macros and based on it to extract required replicas count (repl_req), replicas current number (repl_cnt) and required docker image tag (image_tag_req) as a service bound metrics.
    I also need somehow to monitor is service's tasks are running with required image tag. So I need to extract all task ids per service somehow and check it against each service required image tag metric.
    I can't understand how to create item which will identify service it's task and task image tag.
    My current template
    zbx_export_templates-2.xml
    Attached Files
    Last edited by aeromaks; 03-09-2021, 11:24.
  • aeromaks
    Junior Member
    • May 2012
    • 5

    #2
    Will this work, using LLD macro inside another LLD macro like this?

    Click image for larger version

Name:	image_19942.png
Views:	161
Size:	93.5 KB
ID:	431030
    Last edited by aeromaks; 06-09-2021, 10:55.

    Comment

    Working...