Ad Widget

Collapse

Zabbix returns wrong value from script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mhk
    Junior Member
    • Dec 2020
    • 9

    #1

    Zabbix returns wrong value from script

    Hello everyone
    I'm having this weird problem with zabbix.
    I'm trying to monitor this process in OPN Sense (20.7.5, FreeBSD 12.1)

    ​​​​​

    My script: (don't judge, I'm really new to this) simply looks if the process is running and returns (in that case for testing purposes) random numbers for yes or no
    Code:
    #!/bin/sh
    
    . /etc/rc.subr
    
    nut=$(ps aux | grep "[U]PS" | cut -b 1,2,3,4)
    
    if [ "$nut" == uucp ]; then
    
       #process is running
       Return_value=5
    else
       #process is not running
       Return_value=3
    fi
    
    echo $Return_value
    if I simply run this from the terminal, it returns the correct value.

    For zabbix integration I ceated a custom UserParameter in the agent conf
    Code:
    ####### USER-DEFINED MONITORED PARAMETERS #######
    
    UserParameter=system.nutservice, /home/mhk/nut_checker.sh
    However:
    When I try to monitor it in Zabbix however, it always displays the value for "not running".
    So the script does get called from Zabbix, but somehow can't seem to execute it properly.

    Any ideas what seems to be the problem here?
    Thanks in advance
    Last edited by mhk; 03-12-2020, 18:21.
  • mhk
    Junior Member
    • Dec 2020
    • 9

    #2
    okay nvm I feel stupid.

    It was as easy as enabling AllowRoot in the Zabbix Agent conf....

    seems to be a difference from Linux

    Comment

    • Singularity
      Member
      • Aug 2020
      • 81

      #3
      I do not recommend running zabbix agent running as root. You can allow the user "zabbix" to execute that specific command with no restrictions. Like for example in ubuntu, we can do it by editing the sudoers file.

      Comment

      • mhk
        Junior Member
        • Dec 2020
        • 9

        #4
        I thought as much, but had no luck with other methods.

        Any idea how I would go about it in FreeBSD? I tried giving ownership of the script to zabbix etc etc, but nothing would work.

        Comment

        • Hamardaban
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • May 2019
          • 2713

          #5
          what "sysctl security.bsd | grep see" show?

          Comment

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

            #6
            if change of ownership does not affect result, then it is probably something IN the script? You did not specify, if you run it from command line, do you do it as user zabbix or as root?
            FreeBSD seems to allow usage of a option in ps only for root in some cases...So maybe your script just does not return all needed processes if run as "normal "user?

            -a Display information about other users' processes as well as your own. If the security.bsd.see_other_uids sysctl is set to zero, this option is honored only if the UID of the user is 0.

            Comment

            • mhk
              Junior Member
              • Dec 2020
              • 9

              #7
              coming back to this.
              Yes that seems to be the problem:

              security.bsd.see_jail_proc: 1
              security.bsd.see_other_gids: 0
              security.bsd.see_other_uids: 0

              and ps aux -a .... returns nothing.

              Guess I should be looking at a completely different approach with the script then.
              Thanks for pointers at least I know now what the problem is

              update:

              Okay, if anyone is interested I found a janky workaround solution.

              Basically I let crontab call the original script, which saves the result (1/0) in a .txt and then have zabbix simply call another script that reads the .txt.

              Not nice, but it works.
              Last edited by mhk; 11-05-2021, 12:06. Reason: found a working solution

              Comment

              Working...