Ad Widget

Collapse

Problems creating a new script media type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jarenas
    Junior Member
    • Mar 2018
    • 5

    #1

    Problems creating a new script media type

    Hello, I'm trying to create a script that receive a phone number as a parameter from zabbix and write this phone number in a text file.

    I'm doing this for testing purpose only, because after that, I will create a script that will call using my pbx.







    $1 must be my phone number passed as a parameter when the script is executed after an alert.




    After an alert other scripts that I downloaded from the Internet are working fine, but my script doesn't work. It have to create a new txt file but it doesn't work.

    What am I doing wrong?

    Thanks, I'm a newbie with zabbix.

    Regards!
    Last edited by jarenas; 27-03-2018, 10:02.
  • aigars.kadikis
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Mar 2018
    • 208

    #2
    Hello,

    You must set you script executable:
    chmod +rx test.sh

    There is no capital X option for chmod command. Please execute the command all in lowercase.

    Before moving forward please execute the script from command line:
    ./test.sh 12345678

    Comment

    • jarenas
      Junior Member
      • Mar 2018
      • 5

      #3
      Originally posted by aigars.kadikis
      Hello,

      You must set you script executable:
      chmod +rx test.sh

      There is no capital X option for chmod command. Please execute the command all in lowercase.

      Before moving forward please execute the script from command line:
      ./test.sh 12345678
      Hi thanks, I did everything and works in the shell, but not with zabbix alerts.



      It says that was sent, but the script wasn't executed, there is not any txt file in the folder.

      Comment

      • aigars.kadikis
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Mar 2018
        • 208

        #4
        Hello,

        Try with full path saving it to /tmp
        echo "$1" >> /tmp/test.txt

        What operating system are you running? if CentOS then SELinux may block your file creation.
        Take a look at current SELinux status:
        sestatus
        You can temporary turn off SElinux with:
        setenforce 0
        ..and turn it back with:
        setenforce 1

        Comment

        • jarenas
          Junior Member
          • Mar 2018
          • 5

          #5
          Originally posted by aigars.kadikis
          Hello,

          Try with full path saving it to /tmp
          echo "$1" >> /tmp/test.txt

          What operating system are you running? if CentOS then SELinux may block your file creation.
          Take a look at current SELinux status:
          sestatus
          You can temporary turn off SElinux with:
          setenforce 0
          ..and turn it back with:
          setenforce 1
          Thanks for comment, yes, selinux is disabled, and I have tried with full path to /tmp and the same problem, the script is not executed.

          Comment

          • aigars.kadikis
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • Mar 2018
            • 208

            #6
            Hello,

            Please make sure the /tmp/test.txt file do not exist before trying scenario in zabbix. If you test scenario in direct shell then /tmp/test.txt will be owned by root. When you run alerter from zabbix server it is executed by user zabbix, but zabbix user cannot write to file which is owned by root.

            Can you show permissions of?
            ls -l /var/zabbix/
            ls -l /var/zabbix/alertscripts

            These directories also should be owned by zabbix
            chown -R /var/zabbix

            Comment

            • jarenas
              Junior Member
              • Mar 2018
              • 5

              #7
              Originally posted by aigars.kadikis
              Hello,

              Please make sure the /tmp/test.txt file do not exist before trying scenario in zabbix. If you test scenario in direct shell then /tmp/test.txt will be owned by root. When you run alerter from zabbix server it is executed by user zabbix, but zabbix user cannot write to file which is owned by root.

              Can you show permissions of?
              ls -l /var/zabbix/
              ls -l /var/zabbix/alertscripts

              These directories also should be owned by zabbix
              chown -R /var/zabbix
              Now it works! It was a folder permission problem

              Comment

              Working...