Ad Widget

Collapse

External Check works fine only in zabbix server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sergioyy
    Junior Member
    • Sep 2016
    • 4

    #1

    External Check works fine only in zabbix server

    I'm beginner user of Zabbix, and I'm trying to verify if a service is running on linux machine (other than zabbix server).

    I created a script (zbx_service_check.sh) on /usr/lib/zabbix/externalscripts.
    (I'm using postfix to test)

    #!/bin/sh -x
    service="postfix"
    status=`/usr/sbin/service $service status`
    if echo "$status" |grep -q "Active: active"; then
    echo 0
    else
    echo 1
    fi
    fi

    I created an item and a trigger (using expression {zabbix-lab:zbx_service_check.sh.last()}<>0 )

    When I test it on Zabbix server, this works fine (I stop and start postfix using systemctl command and I got different values on "Latest data")

    I configure same item and trigger on other server to be verifyied.
    But, when I try to check other server, it is not work. I stop and start postfix on monitored server, but zabbix server only shows same status(value 0).

    Is there a tip to make it work?
  • kaspars.mednis
    Senior Member
    Zabbix Certified Trainer
    Zabbix Certified SpecialistZabbix Certified Professional
    • Oct 2017
    • 349

    #2
    Hi,

    Zabbix external checks works only from Zabbix Server (or Proxy if configured)

    You need to use agent userparameters or system.run agent keys to execute commands on remote hsots

    The documentation:https://www.zabbix.com/documentation...types/external

    External check is a check executed by Zabbix server by running a shell script or a binary. Zabbix server will look in the directory defined as the location for external scripts (parameter 'ExternalScripts' in Zabbix server configuration file) and execute the command.

    Comment

    • zabbixfk
      Senior Member
      • Jun 2013
      • 256

      #3
      Try builtin service check , if you know what's the port number of postfix running
      Code:
      net.tcp.port[ip,port]
      , i would check net.tcp.port[,25] in case of port 25 checking in the machine.

      Other way is , system.run[command,<mode>], replace command with your command such as '
      Code:
      /etc/init.d/zabix_server status 2>/dev/null | grep -c running
      , based on the return value create trigger.

      If you still wanted to use custom script, create script, create a userparameter filed under zabbix_agentd.conf, then create as agent.

      Thanks.

      Comment

      • sergioyy
        Junior Member
        • Sep 2016
        • 4

        #4
        ActiveCheck with UserParameter

        I'm create an UserParameter that works.
        In this example, it is possible to check if postfix is running (returned [ + ] postfix by service command)

        UserParameter=service_status, /usr/sbin/service --status-all 2>/dev/null| grep -F "[ + ] postfix" | wc -l;

        When I stop postfix (sudo systemctl stop postfix), the trigger work well indicating service down.

        But now, I facing a stranger behaviour. I configured this UserParameter on two linux ubuntu clients, monitored by one zabbix-server.

        Only one is working correct. Comparing both zabbix-agent.conf, they are set as same way.

        Comment

        • zabbixfk
          Senior Member
          • Jun 2013
          • 256

          #5
          Yes, comparing agnentd.conf should help.
          Other thing you should do is, increase debug level 'DebugLevel=' in agentd.conf file, also make sure EnableRemoteCommands=1 & LogRemoteCommands=1, then checking log should help.
          You can also simulate using zabbix_get.

          Thanks

          Comment

          • sergioyy
            Junior Member
            • Sep 2016
            • 4

            #6
            Different Ubuntu Versions

            Thanks for your support !

            I checked both zabbix-agent.conf and they are set as same way.
            Versions of zabbix-agent are same:
            zabbix_agentd (daemon) (Zabbix) 3.2.11
            Revision 76339 27 December 2017, compilation time: Dec 27 2017 15:17:18

            But linux versions are different.

            [Zabbix-Server]
            sudo lsb_release -a
            No LSB modules are available.
            Distributor ID: Ubuntu
            Description: Ubuntu 16.04.3 LTS
            Release: 16.04
            Codename: xenial

            sudo zabbix_server -V
            zabbix_server (Zabbix) 3.2.8
            Revision 72884 25 September 2017, compilation time: Sep 26 2017 17:51:56

            Copyright (C) 2017 Zabbix SIA



            [machine 1: not getting data from item]
            $ sudo lsb_release -a
            No LSB modules are available.
            Distributor ID: Ubuntu
            Description: Ubuntu 14.04.5 LTS
            Release: 14.04
            Codename: trusty

            [machine 2: getting data from item]
            $ sudo lsb_release -a
            No LSB modules are available.
            Distributor ID: Ubuntu
            Description: Ubuntu 16.04.3 LTS
            Release: 16.04
            Codename: xenial

            It could be a reason?

            complementary information: zabbix-server, is monitoring both machines. I can see information about cpu load, memory, etc for each one. So zabbix-agents are working well.

            Comment

            • kaspars.mednis
              Senior Member
              Zabbix Certified Trainer
              Zabbix Certified SpecialistZabbix Certified Professional
              • Oct 2017
              • 349

              #7
              Hi,

              try to run your command
              /usr/sbin/service --status-all 2>/dev/null| grep -F "[ + ] postfix" | wc -l;
              on both servers as Zabbix user, there may be permission issues. All userparameters are executed with Zabbix system user permissions

              Regards,
              Kaspars

              Comment

              • sergioyy
                Junior Member
                • Sep 2016
                • 4

                #8
                Active Check permissions

                Hi Kaspars, you were rigth. Running command as zabbix user, not working on machine 1. Now, what permissions should be checked?


                [machine 1: executing command as zabbix user, no work]
                sudo -u zabbix /usr/sbin/service --status-all 2>/dev/null| grep -F "[ + ] postfix" | wc -l;
                0
                [machine 1: executing command sudo, work]
                sudo /usr/sbin/service --status-all 2>/dev/null| grep -F "[ + ] postfix" | wc -l;
                1

                [machine2: executing command as zabbix user, work]
                sudo -u zabbix /usr/sbin/service --status-all 2>/dev/null| grep -F "[ + ] postfix" | wc -l;
                1
                [machine2: executing command sudo, work]
                sudo /usr/sbin/service --status-all 2>/dev/null| grep -F "[ + ] postfix" | wc -l;
                1

                Comment

                Working...