Ad Widget

Collapse

My script cannot run on zabbix-server for some permissions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bab
    Senior Member
    • Aug 2020
    • 176

    #1

    My script cannot run on zabbix-server for some permissions


    I have created a script on zabbix GUI (zb1) and created a trigger action that use Alarm script for a host now when my trigger fire on the host action status failed and show

    Also this is my script permission :
    [root@Zabbix ~]# ll -hrt /usr/lib/zabbix/alertscripts/alarm.sh
    -rwxr-xr-x 1 root root 78 Jun 11 15:48 /usr/lib/zabbix/alertscripts/alarm.sh

    but while we run script manually it is working

    /usr/bin/sudo -u zabbix /usr/lib/zabbix/alertscripts/alarm.sh


    Attached Files
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    Zabbix runs as local user called "zabbix", why do you put root permissions to a script and try to run that script sudo-ing from zabbix to zabbix and expect it to run? Probably missing sudo rules for that also? Change script ownership to zabbix, get rid of that sudo and run it as much as you like... If that script has to be run as root , then it might work if you sudo without "-u zabbix" and have those sudo rules in place, that zabbix can execute that script as root.
    Last edited by cyber; 12-06-2024, 13:40.

    Comment

    • bab
      Senior Member
      • Aug 2020
      • 176

      #3
      Originally posted by cyber
      Zabbix runs as local user called "zabbix", why do you put root permissions to a script and try to run that script sudo-ing from zabbix to zabbix and expect it to run? Probably missing sudo rules for that also? Change script ownership to zabbix, get rid of that sudo and run it as much as you like... If that script has to be run as root , then it might work if you sudo without "-u zabbix" and have those sudo rules in place, that zabbix can execute that script as root.

      I changed script's owner such as follow :

      [root@Zabbix ~]# ll /usr/lib/zabbix/alertscripts/alarm.sh
      -rwxr-xr-x 1 zabbix zabbix 78 Jun 11 15:48 /usr/lib/zabbix/alertscripts/alarm.sh

      and in the scripts in GUI did not changes but trigger fire and action shows:

      remote command
      failed Sorry, user zabbix is not allowed to execute '/usr/lib/zabbix/alertscripts/alarm.sh' as zabbix on Zabbix.

      Attached Files

      Comment

      • cyber
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Dec 2006
        • 4807

        #4
        As I said... "get rid of that sudo"... remove "sudo -u zabbix" from command ....

        Comment

        • bab
          Senior Member
          • Aug 2020
          • 176

          #5
          Originally posted by cyber
          As I said... "get rid of that sudo"... remove "sudo -u zabbix" from command ....
          Now I changed it such as follow :

          /usr/lib/zabbix/alertscripts/alarm.sh

          but when trigger fire status another failed with attached error

          Even I used follow command

          usermod -aG audio zabbix
          Attached Files
          Last edited by bab; 12-06-2024, 14:26.

          Comment

          • cyber
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • Dec 2006
            • 4807

            #6
            That looks like script (error) output... I guess your script was developed as root user, who has access everywhere and can do anything, then there was no errors... but now trying to run as normal user, it gives errors..
            I doubt I could say anything about it even if you show us the script content... You need to make it work as normal user ...

            Comment

            • bab
              Senior Member
              • Aug 2020
              • 176

              #7
              Originally posted by cyber
              That looks like script (error) output... I guess your script was developed as root user, who has access everywhere and can do anything, then there was no errors... but now trying to run as normal user, it gives errors..
              I doubt I could say anything about it even if you show us the script content... You need to make it work as normal user ...

              My script is so simple it just play a sound when a trigger fire
              This is my script :

              cat /usr/lib/zabbix/alertscripts/alarm.sh
              #!/bin/bash

              /usr/bin/mpg123 -o alsa /usr/share/zabbix/audio/alarm_high.mp3

              Also when I am running script manually it is working on zabbix server

              /usr/lib/zabbix/alertscripts/alarm.sh
              High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
              version 1.25.10; written and copyright by Michael Hipp and others
              free software (LGPL) without any warranty but with best wishes

              Directory: /usr/share/zabbix/audio/

              Terminal control enabled, press 'h' for listing of keys and functions.

              Playing MPEG stream 1 of 1: alarm_high.mp3 ...

              MPEG 2.5 L III cbr48 11025 mono

              [0:02] Decoding of alarm_high.mp3 finished.​

              Comment

              • cyber
                Senior Member
                Zabbix Certified SpecialistZabbix Certified Professional
                • Dec 2006
                • 4807

                #8
                Problem may be in some paths and environment vars missing. When you log on all kind of vars are set. Zabbix is not by default a login account so nothing like that is is set, you may need to add some of it to beginning of the script. But I fail to tell, what you need exactly..

                Comment

                • bab
                  Senior Member
                  • Aug 2020
                  • 176

                  #9
                  Actually the problem solved with restart zabbix server .
                  Actually my plan was to run a script that play a sound when a specific trigger fired and now while trigger fired the status in zabbix GUI changed to executed but cannot hear the sound . While we get GUI console from zabbix virtual machine and run that script it play the sound . What is the issue ?

                  Comment

                  • cyber
                    Senior Member
                    Zabbix Certified SpecialistZabbix Certified Professional
                    • Dec 2006
                    • 4807

                    #10
                    I was actually thinking later that maybe a restart is also needed, as existing processes do not pick up those changes you made....

                    Is it only a very special event that needs that alarm? Why don't you just use frontend messaging from your user profile?

                    Comment

                    • bab
                      Senior Member
                      • Aug 2020
                      • 176

                      #11
                      Originally posted by cyber
                      I was actually thinking later that maybe a restart is also needed, as existing processes do not pick up those changes you made....

                      Is it only a very special event that needs that alarm? Why don't you just use frontend messaging from your user profile?
                      Actually that s not suitable solution for example I want to set alarm for some triggers so at the first step had to change their severity so this is not good idea . Now do you think my solution is possible to do ?

                      Comment

                      • cyber
                        Senior Member
                        Zabbix Certified SpecialistZabbix Certified Professional
                        • Dec 2006
                        • 4807

                        #12
                        It might... You need that console be open and somehow instruct that script to play that sound into that open console session.. I have no idea, how to do it..
                        Many many years ago we had kind of similar setup, where one thing played alarms through a linux box under the table, but I have no recollection, how exactly it was built...

                        Comment

                        • bab
                          Senior Member
                          • Aug 2020
                          • 176

                          #13
                          I want to know what is solution to play sound when trigger fire ? I don't want to use zabbix severity because at the first step I have to change all severity

                          Comment

                          • bab
                            Senior Member
                            • Aug 2020
                            • 176

                            #14
                            Is there any solution to play sound in zabbix GUI web browser ? . My script is running on server and play but can not play on zabbix GUI frontend when trogger fire although showing action status executed

                            Comment

                            Working...