Ad Widget

Collapse

system.run[] Issues while reading variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vshah
    Junior Member
    • Nov 2016
    • 7

    #1

    system.run[] Issues while reading variable

    Hello Folks,

    I am trying to execute these commands on the hosts that are been monitored:
    1) system.run[pid=$(ps -ef | awk '$8 ~/java/ && $1 ~/twadmin/ {print $2}') | ls -l /proc/$pid/fd | wc -l]

    Error on Zabbix:
    ls: cannot access /proc//fd: No such file or directory
    0

    2) system.run[pid=$(ps -ef | awk '$8 ~/java/ && $1 ~/twadmin/ {print $2}') | cat /proc/$pid/limits | grep "Max open files" | awk '{print $5}']

    Error on Zabbix:
    cat: /proc//limits: No such file or directory

    It seems to me that Zabbix (system.run[]) is not able to read the $pid variable.

    Any help will be greatly appreciated
    Thanks in advance!!!


    --Vaibhav
  • vso
    Zabbix developer
    • Aug 2016
    • 190

    #2
    Originally posted by vshah
    Hello Folks,

    I am trying to execute these commands on the hosts that are been monitored:
    1) system.run[pid=$(ps -ef | awk '$8 ~/java/ && $1 ~/twadmin/ {print $2}') | ls -l /proc/$pid/fd | wc -l]

    Error on Zabbix:
    ls: cannot access /proc//fd: No such file or directory
    0

    2) system.run[pid=$(ps -ef | awk '$8 ~/java/ && $1 ~/twadmin/ {print $2}') | cat /proc/$pid/limits | grep "Max open files" | awk '{print $5}']

    Error on Zabbix:
    cat: /proc//limits: No such file or directory

    It seems to me that Zabbix (system.run[]) is not able to read the $pid variable.

    Any help will be greatly appreciated
    Thanks in advance!!!


    --Vaibhav
    please put your command in the script, then execute this script manually from the same user that you would execute zabbix agent, does it work ?

    Comment

    • vshah
      Junior Member
      • Nov 2016
      • 7

      #3
      Hey VSO,

      Thanks for the assistance.

      I have tried the script method and that does work
      But we have literally 1000s of hosts to put this script on. We can use Salt or something, but I am trying to make this work through just one command using system.run on Zabbix

      Comment

      • vso
        Zabbix developer
        • Aug 2016
        • 190

        #4
        Originally posted by vshah
        Hey VSO,

        Thanks for the assistance.

        I have tried the script method and that does work
        But we have literally 1000s of hosts to put this script on. We can use Salt or something, but I am trying to make this work through just one command using system.run on Zabbix
        you could try exporting pid variable etc, improving your command.. but this means that it's not something wrong with the zabbix, also you could try puppet or ansible to deploy script etc..

        I suggest you also enable remote command logging on agent and attach the output, then it can become clearer.

        Please do LogRemoteCommands=1
        Last edited by vso; 22-08-2017, 17:24.

        Comment

        • kloczek
          Senior Member
          • Jun 2006
          • 1771

          #5
          Originally posted by vso
          please put your command in the script, then execute this script manually from the same user that you would execute zabbix agent, does it work ?
          There are at least three alternative solutions:
          1. replace "ls" by "sudo ls"
          2. if SELinux is in use you can add permission for exact command executed by user zabbix with access to procfs
          3. best would be replace this oneliner by "ulimit -n"
          http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
          https://kloczek.wordpress.com/
          zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
          My zabbix templates https://github.com/kloczek/zabbix-templates

          Comment

          Working...