Ad Widget

Collapse

Discovery rule -> external check

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Robot
    Junior Member
    • Apr 2018
    • 3

    #1

    Discovery rule -> external check

    I try to add a discovery rule by external check for cisco switch to make dynamicaly creating items.

    my script is


    Code:
    #!/bin/bash
    . FILIAL_IP_LIST
    printf "{\n"
    printf '\t"data":['
    first=true
    cisco_ip=$1
    filial_mask=$(echo $cisco_ip | cut -d '.' -f3)
    
    for i in $filial_list
    do
    
    if [[ $(echo $i | cut -d '.' -f3) -eq "$filial_mask" || ( $filial_mask -eq "19" && $(echo $i | cut -d '.' -f3) -eq "2" ) ]]; then
    filial_name=$(ssh username@$i "cat /etc/hostname")
    filial_port=$(echo $(snmpwalk -c snmpmod@2 -v 2c $cisco_ip 1.3.6.1.2.1.17.4.3.1.2.$(printf "%d.%d.%d.%d.%d.%d\n" $(echo $(ssh username@$i "ifconfig | grep -i hw | sed -r 's/[[:space:]]+/\t/g' | cut -f5" ) | sed -e 's/://g' | sed 's/\(..\)/\.0x\1/g' | sed -e  's/^\.//' | sed -e 's/\./ /g'))) | cut -d ":" -f2 | sed -re  's/^[[:space:]]//' )
    
        if $first ; then
        printf "\n\t{\n"
        first=false
        else
        printf ",\n"
        printf "\t{\n"
        fi
    
    printf "\t\t\"{#FILIALNAME}\":\t\"$filial_name\",\n"
    printf "\t\t\"{#FILIALPORT}\":\t\"$filial_port\"\n"
    printf "\t}"
    
    fi
    
    done
    
    printf "\n\t]\n"
    printf "}\n"

    i get output like this

    Code:
    {
        "data":[
        {
            "{#FILIALNAME}":    "vladimir",
            "{#FILIALPORT}":    "25"
        },
        {
            "{#FILIALNAME}":    "izhevsk",
            "{#FILIALPORT}":    "21"
        },
        {
            "{#FILIALNAME}":    "kazan",
            "{#FILIALPORT}":    "24"
        },
        {
            "{#FILIALNAME}":    "Cheboksari",
            "{#FILIALPORT}":    "22"
        },
        {
            "{#FILIALNAME}":    "Kirov",
            "{#FILIALPORT}":    "23"
        }
        ]
    }

    I allways get error "Value should be a JSON object". But it is valid - checked on https://jsonlint.com/ .

    zabbix_server_log in debug mode says
    In lld_rows_get()
    End of lld_rows_get():FAIL

    and nothing else.

    Where am i wrong ?
    p.s. zabbix server v 2.4.1
    Last edited by Robot; 04-04-2018, 22:03.
  • DmitryL
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2016
    • 278

    #2
    Try to execute script locally as zabbix user.
    By the way, 2.4.1 is quite an old version. I can understand possible trouble to do major upgrade, but at least try to keep with latest minor version

    Comment

    • Robot
      Junior Member
      • Apr 2018
      • 3

      #3
      Originally posted by Dmitryb
      Try to execute script locally as zabbix user.
      By the way, 2.4.1 is quite an old version. I can understand possible trouble to do major upgrade, but at least try to keep with latest minor version
      thx, problem realy was in zabbix user *facepalm*

      Comment

      Working...