Ad Widget

Collapse

Running commands

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • passado
    Junior Member
    • Sep 2015
    • 4

    #1

    Running commands

    Hello, I was nagios user but recently decided to spend now to Zabbix, I'm trying to perform the following test:

    Have a bash shell script that returns 0 or 1. I wanted then zabbix run this command every day 23h and wait for the outcome 0 or 1 and thus warn or not ... I already understood that I have to use the system .run but I'm not able to run the script that I have. Can anyone give an indication
  • jamesNJ
    Senior Member
    • Jun 2015
    • 103

    #2
    You can use system.run[] or create a UserParameter in the zabbix agentd configuration.

    system.run[] against a linux server should be straightforward for simple commands. However if your program requires root access that could be an issue and may require use of sudo, etc.

    Also, load up the zabbix_get and zabbix_send utilities as they can help. On the zabbix server you should be able to run simple tests like:

    zabbix_get -s server1 -k system.run[ls]

    That would produce an 'ls' of some directory.

    Also zabbix will need your 0 or 1 to be printed to standard out, and not a shell return code like exit(0)

    Comment

    • tim.mooney
      Senior Member
      • Dec 2012
      • 1427

      #3
      Originally posted by passado
      Hello, I was nagios user but recently decided to spend now to Zabbix, I'm trying to perform the following test:

      Have a bash shell script that returns 0 or 1. I wanted then zabbix run this command every day 23h and wait for the outcome 0 or 1 and thus warn or not ... I already understood that I have to use the system .run but I'm not able to run the script that I have. Can anyone give an indication
      We do stuff like this on many of our hosts.

      I recommend you read the section of the Zabbix manual on creating your own custom item keys:



      In addition, so that it's obvious within the dashboard what your 0 or 1 mean, I highly recommend you also take the 3 extra minutes and create a custom value mapping:




      Note that by default Zabbix agent checks only wait a few seconds (I think the default is 5). You can change this, but last I checked it required that you modify the source code and recompile. If your bash script should always finish in less than 5 seconds, you should be fine.

      Tim

      Comment

      • passado
        Junior Member
        • Sep 2015
        • 4

        #4
        Hello,
        Thank you very much for your help, you are precious and managed to solve exactly what he needed

        Comment

        • passado
          Junior Member
          • Sep 2015
          • 4

          #5
          I just wanted to put another question.

          I run a script that may take 1h 10m as, how can I do to be executed at a specified time and no check is not done but wait the result that I write the script?

          Comment

          • tim.mooney
            Senior Member
            • Dec 2012
            • 1427

            #6
            Originally posted by passado
            I just wanted to put another question.

            I run a script that may take 1h 10m as, how can I do to be executed at a specified time and no check is not done but wait the result that I write the script?
            You probably should have started a new thread, since this is a separate question.

            If your item takes a long time to run, then you probably shouldn't use a standard "Zabbix agent" type. Instead, you probably want to look into using an "active" check. You can search the forums and the documentation for information on active checks, but here's an example from the forums that might be interesting to you:

            Comment

            • passado
              Junior Member
              • Sep 2015
              • 4

              #7
              Thank you for your help.

              Finally I will use zabbix_sender is an excellent tool

              Comment

              Working...