Ad Widget

Collapse

Alert Script Failed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ppark126
    Junior Member
    • Apr 2022
    • 2

    #1

    Alert Script Failed


    I am using zabbix 5.4. I want to use a custom alarm script. During the alarm test, the message was received normally, but it is recognized as a failure. What is the problem?


    Port 80,443 of the destination server is open.


    Please see the script below

    #!/bin/bash
    # Dooray incoming web-hook URL and user name
    username='Zabbix'
    ## Values received by this script:
    # sendTo = $1 / Dooray hook url to send the message to
    # Subject = $2 / subject of the message sent by Zabbix; by default, it is usually something like "(Problem|Resolved): Lack of free swap space on Zabbix server"
    # Message = $3 / message body sent by Zabbix; by default, it is usually approximately 4 lines detailing the specific trigger involved
    # Get the sendTo ($1), subject ($2), and message ($3)
    sendTo="$1"
    subject="$2"
    message=`echo $3 | perl -pe 's/\r/\\\\n/g; s/\n/\\\\n/g;'`
    # Change message emoji and notification color depending on the subject indicating whether it is a trigger going in to problem state or recovering
    recoversub='^RECOVER(Y|ED)?$|^OK$|^Resolved.*'
    problemsub='^PROBLEM.*|^Problem.*'
    if [[ "$subject" =~ $recoversub ]]; then
    emoji=':smile:'
    color='#0C7BDC'
    elif [[ "$subject" =~ $problemsub ]]; then
    emoji=':frowning:'
    color='#FFC20A'
    else
    emoji=':question:'
    color='#CCCCCC'
    fi
    # Build JSON payload which will be HTTP POST'ed to the Dooray web-hook URL
    payload="{"botName": "${username//"/\\"}", "botIconImage": "https://assets.zabbix.com/dist/images/fd87efa6da9bed3fd8c9cfb442a3d537.svg", "attachments": [{"fallback": "${subject//"/\\"}", "title": "${subject//"/\\"}", "text": "${message//"/\\"}", "color": "${color}"}], "text": "${emoji}"}"
    # Execute the HTTP POST request of the payload to Dooray via curl, storing stdout (the response body)
    return=$(curl $sendTo -H "Content-Type: application/json; charset=UTF-8" -d "${payload}")
    if [[ "$return" != 'ok' ]]; then
    echo >&2 "$return"
    exit 1
    fi
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    Exit 1 probably...
    Usually exit 0 is success and nonzero indicates issues...

    Comment


    • ppark126
      ppark126 commented
      Editing a comment
      Thanks your answer
      How i fix It?
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #3
    Fixing the script?

    Comment


    • ppark126
      ppark126 commented
      Editing a comment
      Thanks your answer
      I fixed script.
      exit 0
      very cool !!! succeded to send massage
Working...