Ad Widget

Collapse

Zabbix-get incomplete string

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • oxpy
    Junior Member
    • Oct 2022
    • 8

    #1

    Zabbix-get incomplete string

    Hello everybody. I have a problem with a receiving data from host to zabbix server. I have the script which make JSON format for zabbix server for discovery rules.
    #!/bin/bash
    TERM=linux

    while [ -n "$1" ]
    do
    case "$1" in​​

    .................................................. ...............................

    -j) p="$2"
    g=$(top -Hbn1 | grep $p | awk '{print $NF}' ORS=',')
    IFS=$',' read -r -a customArray <<< $g
    echo -e "["
    for ((c=0; c<${#customArray[@]}; c++))
    do
    if ((c==$((${#customArray[@]}-1))));
    then
    echo -e "{"proc":"${customArray[c]}"}"
    else
    echo -e "{"proc":"${customArray[c]}"},"
    fi
    done
    echo -e "]"
    shift ;;​

    .................................................. .................................

    esac
    shift
    done​
    This script returns the following if execute it from host(agent):
    /zabbix_proc.sh -j kworker/85

    [
    {"proc":"kworker/85:0H"},
    {"proc":"kworker/85:1H"},
    {"proc":"kworker/85:2"},
    {"proc":"kworker/85:0"}
    ]
    But when I doing the get request from zabbix server with this command:
    zabbix_get -s 172.16.164.72 -k di[kworker/85]

    I get the output:
    [
    {"proc":"kworker/85+"},
    {"proc":"kworker/85+"},
    {"proc":"kworker/85+"},
    {"proc":"kworker/85+"}
    ]
    Here is incomplete value which ends "+". Everytime I have output limited to 10 symbols with every process which has more than 10 symbols

    My config file for zabbix-agent:
    UserParameter=di[*],/etc/zabbix/zabbix_proc.sh -j $1
    UnsafeUserParameters=1
    AllowKey=system.run[*]
    Help me please to understand it and I will be glad if you have a solution. Thank you
  • Answer selected by oxpy at 09-10-2022, 16:33.
    Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1781

    Looks like your top output lines are being truncated when run noninteractively. Try adding -w 200 (or some other value larger than 80 that maybe is the default), like top -Hbn1 -w 200

    Markku

    Comment


    • oxpy
      oxpy commented
      Editing a comment
      You are right, it is works. Thank you.

      Also we can use another command:
      g=$(ps -e -T | grep $p | awk '{print $NF}' ORS=',')
  • Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1781

    #2
    Looks like your top output lines are being truncated when run noninteractively. Try adding -w 200 (or some other value larger than 80 that maybe is the default), like top -Hbn1 -w 200

    Markku

    Comment


    • oxpy
      oxpy commented
      Editing a comment
      You are right, it is works. Thank you.

      Also we can use another command:
      g=$(ps -e -T | grep $p | awk '{print $NF}' ORS=',')
Working...