Ad Widget

Collapse

Alert script can't write to file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sosisoft
    Junior Member
    • Oct 2023
    • 4

    #1

    Alert script can't write to file

    Hello everyone,
    I have problems with alert script located in /usr/lib/zabbix/alertscripts:
    Code:
    #!/bin/bash
    sendto="$1"
    message="$2"
    username="sender"
    password="some pwd"
    provider="Orange"
    directory=$(pwd)
    
    # JSON data
    data="{"auth":{"username":"$username","pass word":"$password"},"provider":"$provider",\ "number":"$sendto","content":"$message" }"
    response=$(curl -sS -X POST [URL]http://smsserver/goip/sendsms/[/URL] -H "Content-Type: application/json" -d "$data")
    log_file="sms_server_response.log"
    timestamp=$(date +"%d.%m.%Y %H:%M:%S")
    echo "$timestamp $response" >> "$directory/$log_file"​
    I can call this script with Media type/Test and it works fine(sends SMS over SMS server) if last row echo.... is commented.
    If not I got permission denied to write in log, but SMS is sent .
    Owner of -R /usr/lib/zabbix is zabbix user.

    Please what I need to do to complete the script?

    Kind regards,
    Sosisoft
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    Check your selinux errors... there might be some things missing for zabbix user to be able to create/write etc that logfile in that particular place.

    Comment

    • Sosisoft
      Junior Member
      • Oct 2023
      • 4

      #3
      Hi, selinux is completely disabled, but I foud other solution here https://www.shellhacks.com/sudo-echo...ission-denied/

      Code:
      $ echo '<something>' | sudo tee --append <file.log>
      but now I have other problem the log file is created in / (root dir) not in the directory where alert script is located /usr/lib/zabbix/alertscripts/
      I have the same result even if I define the full path instead of file.log
      with command
      Code:
      sudo visudo
      I added the root permision to the tee command. This doesn't worked for echo command!
      Last edited by Sosisoft; 23-10-2023, 11:06.

      Comment

      Working...