Ad Widget

Collapse

Execute a remote command

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jaksky
    Junior Member
    • Oct 2013
    • 10

    #1

    Execute a remote command

    Hi,
    I am new to zabbix and I am a bit strugling. I would like to collect some custom metric from the remote host. Something like: number of files in specified directory. Is it possible to create a shell script which will be executet via zabbix agent on monitored host and result will be returned to zabbix server. Or is there a better way how to do that?

    Thx
  • ArtemK
    Senior Member
    • May 2013
    • 232

    #2
    You really should start to use google/forum search tools/etc. As to your question, you will find answer here

    Comment

    • SamuelMaia
      Junior Member
      • Oct 2013
      • 5

      #3
      Originally posted by jaksky
      Hi,
      I am new to zabbix and I am a bit strugling. I would like to collect some custom metric from the remote host. Something like: number of files in specified directory. Is it possible to create a shell script which will be executet via zabbix agent on monitored host and result will be returned to zabbix server. Or is there a better way how to do that?

      Thx
      Jaksky, you can do that, i use the iten "Agent SSH", using the information "ssh.run[<unique short description>,<ip>,<port>,<encoding>]", then, i can enter in a remote host via ssh, collect my results and return to server to show-me in web service, you tryed this option?

      Comment

      • jaksky
        Junior Member
        • Oct 2013
        • 10

        #4
        Originally posted by ArtemK
        You really should start to use google/forum search tools/etc. As to your question, you will find answer here
        I am not sure why "User Parameters" solution doesn't work. My suspicion is that it is because of latency of the command as the result are not returned "immediately" but but far bellow 1s. What to use in that case?

        Comment

        • ArtemK
          Senior Member
          • May 2013
          • 232

          #5
          Originally posted by jaksky
          I am not sure why "User Parameters" solution doesn't work. My suspicion is that it is because of latency of the command as the result are not returned "immediately" but but far bellow 1s. What to use in that case?
          do you get answer from target host using zabbix_get? Run this command on your zabbix server
          Code:
          zabbix_get -s %target_host% -k %your_user_parameter%
          if your script can't return value in 3 sec. (AFAIR, it's default value), then you will see ZBX_NOTSUPPORTED. You have several options:
          1. optimize your script to return needed value in less than 3 seconds
          2. use zabbix_sender and trapper item in zabbix configuration. In this case you can forget about timeouts. Create scheduled task to execute script, which will report some data to zabbix (check also nodata() function).
          3. increase timeout value in server and agent configuration and continue to use passive/active agent checks.

          Comment

          • jaksky
            Junior Member
            • Oct 2013
            • 10

            #6
            Originally posted by ArtemK
            do you get answer from target host using zabbix_get? Run this command on your zabbix server
            Code:
            zabbix_get -s %target_host% -k %your_user_parameter%
            if your script can't return value in 3 sec. (AFAIR, it's default value), then you will see ZBX_NOTSUPPORTED. You have several options:
            1. optimize your script to return needed value in less than 3 seconds
            2. use zabbix_sender and trapper item in zabbix configuration. In this case you can forget about timeouts. Create scheduled task to execute script, which will report some data to zabbix (check also nodata() function).
            3. increase timeout value in server and agent configuration and continue to use passive/active agent checks.
            Unfortunately the latency is not under my control - trying to monitor folder content on Hadoop HDFS.
            Time doesn't look that bad:
            [hdfs@Ac1n1 ~]# time /home/hadoop/hadoop-1.0.4/bin/hadoop fs -count /user/bdhistprocessor/tmp |tr -s '[:space:]' ':' | cut -d':' -f3

            real 0m0.941s
            user 0m1.374s
            sys 0m0.059s

            Even when I increased timeout on Agent I see in the agent log:
            28587:20131030:081115.487 For key [bdhistprocessor.tmp] received value []
            28587:20131030:081115.487 In process_value() key:'Ac1n1:bdhistprocessor.tmp' value:''
            28587:20131030:081115.487 In send_buffer() host:'aim-is01' port:10051 values:1/100
            28587:20131030:081115.487 Will not send now. Now 1383138675 lastsent 1383138675 < 5

            Comment

            • ArtemK
              Senior Member
              • May 2013
              • 232

              #7
              it seems that your command doesn't work under zabbix user. Check it using sudo/su. Lack of permissions?
              Last edited by ArtemK; 30-10-2013, 16:00.

              Comment

              • SamuelMaia
                Junior Member
                • Oct 2013
                • 5

                #8
                Originally posted by jaksky
                I am not sure why "User Parameters" solution doesn't work. My suspicion is that it is because of latency of the command as the result are not returned "immediately" but but far bellow 1s. What to use in that case?
                One example, i use this iten to collect the IP of interfaces ETH1 in my hosts remotes:
                ssh.run[eth1,,22,DCSA]

                User:xxx
                Pass:xxx

                Return: Text

                Command:
                #!/bin/sh
                ifconfig |grep eth1 |grep addr: |awk '{print$2}'

                Then, i have the value that i search.
                Last edited by SamuelMaia; 30-10-2013, 15:53.

                Comment

                • jaksky
                  Junior Member
                  • Oct 2013
                  • 10

                  #9
                  Originally posted by ArtemK
                  it seems that your command doesn't work under zabbix user. Check it using sudo/su. Lack of permissions?
                  That's probably it - thanks for hint!

                  Comment

                  Working...