Ad Widget

Collapse

Item preprocessing with external check

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prasad_SL
    Member
    • May 2018
    • 35

    #1

    Item preprocessing with external check

    I am testing zabbix 3.4 to monitor old PSTN switch. It only has telnet login. so I used External check with "expect" script. the output gives the list of current alarms in the system. but the problem is the text item contain blank lines. so the regex exit on the first match.

    Output,

    Header line

    Header line 2

    Alarm xxxxxx11

    Alarm xxxxxx22

    Alarm xxxxxx33

    END

    I am using Dependent Item from this and doing a pre-processing..
    ^Alarm (.+)

    Capture group only contain Alarm xxxxxx11.
    I am sure this is due to blank line, next to the mach.
    Unable to find a method to remove those blank spaces.

    Or is there better way to monitor this node ?
    Please help ..
  • prasad_SL
    Member
    • May 2018
    • 35

    #2
    I found a solution. If anyone interested, this is the way I did...


    1. Modified external telnet script to dump the output to a file (log)
    2. Read the file and extract lines specific regex and put in to another file; (marked as Newlog)
    3. Append the file content by formatting according to SNMP lines


    I did it by 6 scripts; including telnet script.
    As follows.

    1. telnet script

    #!/usr/bin/expect

    spawn telnet x.x.x.x
    send "username"
    send "\r"
    send "password"
    send "\r"
    expect "Windows NT Domain:"
    send "\r"
    expect ">"
    send "mml -a"
    send "\r"
    expect "<"
    send "alarmlist command;"
    send "\r"
    send "exit \r"
    send "exit \r"


    2. Main command script : : this is the external script places at /usr/lib/zabbix/externalscripts
    Alarm dump location is /home/appliance/prasadAXEscripts

    #!/bin/bash

    /usr/lib/zabbix/externalscripts/isc4A1.sh | tee /home/appliance/prasadAXEscripts/log.txt
    sleep 0.25
    /home/appliance/prasadAXEscripts/Tony_v1.bash
    sleep 0.1

    3. Here Tony_v1.bash will trigger 3 new scripts ...

    #!/bin/bash

    #Extracting A1 and A2 alarms from capture file
    /home/appliance/prasadAXEscripts/Mark42AXEAlarmExtractor_v1.sh
    sleep 0.1

    #Compare New list with Old list and genarate Triggers
    /home/appliance/prasadAXEscripts/Mark43AXEFileAnalyser_v1.bash
    sleep 0.1

    #Tunneling genarated Triggers to Zabbix SNMP train
    /home/appliance/prasadAXEscripts/Mark47SnmpTunnel_v1.sh
    sleep 0.1


    Following are those 3 files...

    If you have any better way or issues ...please comment.


    4. Mark42AXEAlarmExtractor_v1.sh

    #!/bin/bash

    REGEX="^(A1|A2).*"

    file="/home/appliance/prasadAXEscripts/PrasadAXE10log.txt"
    while IFS= read -r line
    do
    if [[ "$line" =~ $REGEX ]]
    then
    echo "$line" >> /home/appliance/prasadAXEscripts/PrasadAXE10logNEW.txt
    fi
    done < "$file"


    5. Mark43AXEFileAnalyser_v1.bash

    #!/bin/bash

    #reading new file to arrayNEW
    file="/home/appliance/prasadAXEscripts/PrasadAXE10logNEW.txt"
    while IFS= read -r line || [[ -n "$line" ]];
    do
    line=$(echo "$line" | tr -d '\r')
    arrayNEW+=("$line")
    done < "$file"

    #reading old file to arrayOLD
    file="/home/appliance/prasadAXEscripts/PrasadAXE10logOLD.txt"
    while IFS= read -r line || [[ -n "$line" ]];
    do
    line=$(echo "$line" | tr -d '\r')
    arrayOLD+=("$line")
    done < "$file"


    for ((k=0; k < ${#arrayNEW[*]}; k++))
    do
    for ((z=0; z < ${#arrayOLD[*]}; z++))
    do
    if [ "${arrayNEW[k]}" = "${arrayOLD[z]}" ];
    #then echo "${arrayNEW[k]}"
    #then arrayBoth+=("${arrayNEW[k]}")
    then
    break
    fi

    var=$((z+1))
    if [ $var = ${#arrayOLD[*]} ];
    #then echo "Not in old file..${arrayNEW[k]}"
    then arrayNewOnly+=("${arrayNEW[k]}")
    fi
    done

    if [ ${#arrayOLD[*]} = 0 ];
    #then echo "Not in old file..${arrayNEW[k]}"
    then arrayNewOnly+=("${arrayNEW[k]}")
    fi

    done


    for ((a=0; a < ${#arrayOLD[*]}; a++))
    do
    for ((b=0; b < ${#arrayNEW[*]}; b++))
    do
    if [ "${arrayOLD[a]}" = "${arrayNEW[b]}" ];
    then
    break
    fi

    var=$((b+1))
    if [ $var = ${#arrayNEW[*]} ];
    #then echo "Not in old file..${arrayOLD[k]}"
    then arrayOldOnly+=("${arrayOLD[a]}")
    fi
    done

    if [ ${#arrayNEW[*]} = 0 ];
    #then echo "Not in old file..${arrayNEW[k]}"
    then arrayOldOnly+=("${arrayOLD[a]}")
    fi



    done

    # File appending
    >/home/appliance/prasadAXEscripts/Mark11snmptraps.txt

    for ((p=0; p < ${#arrayNewOnly[*]}; p++))
    do
    echo "${arrayNewOnly[p]} :: RatFire" >> /home/appliance/prasadAXEscripts/Mark11snmptraps.txt
    done

    for ((q=0; q < ${#arrayOldOnly[*]}; q++))
    do
    echo "${arrayOldOnly[q]} :: RatClear" >> /home/appliance/prasadAXEscripts/Mark11snmptraps.txt
    done

    # File swapping
    >/home/appliance/prasadAXEscripts/PrasadAXE10logOLD.txt

    cp /home/appliance/prasadAXEscripts/PrasadAXE10logNEW.txt /home/appliance/prasadAXEscripts/PrasadAXE10logOLD.txt

    >/home/appliance/prasadAXEscripts/PrasadAXE10logNEW.txt


    6. Mark47SnmpTunnel_v1.sh

    #!/bin/bash

    ratT="$(date +'%Y%m%d.%H%M%S')"
    ratip="x.x.x.x"
    file="/home/appliance/prasadAXEscripts/Mark11snmptraps.txt"

    while IFS= read -r line
    do
    echo "$ratT ZBXTRAP $ratip PrasadAXEalarm $line" >> /var/log/snmptrap/snmptrap.log
    done < "$file"

    Comment

    Working...