Ad Widget

Collapse

system.run syntax?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • trikke
    Senior Member
    • Aug 2007
    • 140

    #1

    system.run syntax?

    Hi,

    I'm having trouble with a system.run Command.
    How do I "escape" the ',' ?

    e.g.
    zabbix_get -s servername -k "system.run[wmic service get DisplayName]" --> works

    zabbix_get -s servername -k "system.run[wmic service get DisplayName,StartMode,State]" --> doesn't work because of the ',' (comma).

    How can I make this work?

    Tried \, already, any other suggestions?

    greets
    Patrick
  • Biobabar
    Junior Member
    • Jan 2011
    • 15

    #2
    Hi !

    For me, the syntax is "system.run[command,<mode>]" with "wait (default)".

    mode "StartMode or State" isn't correct mode

    choice "wait" or "nowait", only correct value.

    Comment

    • trikke
      Senior Member
      • Aug 2007
      • 140

      #3
      Hi Biobabar,

      I'm aware that ,wait or ,nowait is a parameter to the key, my question was: how to escape a ',' in case this is part of the Command I'm trying to execute!

      Greets
      Patrick

      Comment

      • Biobabar
        Junior Member
        • Jan 2011
        • 15

        #4
        OK sorry :

        Do you have test :

        zabbix_get -s servername -k system.run["wmic service get DisplayName,StartMode,State"]

        with command in quote ?

        Comment

        • Biobabar
          Junior Member
          • Jan 2011
          • 15

          #5
          I find this syntax for this command :

          system.run[wmic service where "Startmode='Auto' and state!='Running'" get DisplayName /Format:csv]

          (Output as text)

          a solution maybe

          Comment

          • trikke
            Senior Member
            • Aug 2007
            • 140

            #6
            yep, tried the quotes to no avail,
            The other Command is not quite what i need, sorry

            greets
            Patrick

            Comment

            • Rudd
              Member
              • Mar 2011
              • 69

              #7
              Hi Patrick,

              Do I understand correctly that the problem is executing zabbix_get when the key contains ','? If that is the case, which shell are you using?

              Comment

              • trikke
                Senior Member
                • Aug 2007
                • 140

                #8
                Hi, Tahnx for the suggestion.
                I tried with bash and ksh, both the Same Result:

                zabbix-zone#bash
                zabbix-zone#zabbix_get -s xxxx -k system.run["wmic service DisplayName\,Name"]
                ZBX_NOTSUPPORTED
                zabbix-zone#zabbix_get -s xxxx -k system.run["wmic service DisplayName,Name"]
                ZBX_NOTSUPPORTED
                zabbix-zone#zabbix_get -s xxxx -k "system.run[wmic service DisplayName,Name]"
                ZBX_NOTSUPPORTED
                zabbix-zone#zabbix_get -s xxxx -k "system.run[wmic service DisplayName\,Name]"
                ZBX_NOTSUPPORTED
                zabbix-zone#
                zabbix-zone#
                zabbix-zone#ksh
                zabbix-zone#zabbix_get -s xxxx -k system.run["wmic service DisplayName\,Name"]
                ZBX_NOTSUPPORTED
                zabbix-zone#zabbix_get -s xxxx -k system.run["wmic service DisplayName,Name"]
                ZBX_NOTSUPPORTED
                zabbix-zone#zabbix_get -s xxxx -k "system.run[wmic service DisplayName,Name]"
                ZBX_NOTSUPPORTED
                zabbix-zone#zabbix_get -s xxxx -k "system.run[wmic service DisplayName\,Name]"
                ZBX_NOTSUPPORTED
                zabbix-zone#
                zabbix-zone#
                zabbix-zone#exit

                I'm on Zabbix v1.8.3 (revision 13928) (16 August 2010)

                Any other suggestion?

                Comment

                • Rudd
                  Member
                  • Mar 2011
                  • 69

                  #9
                  ZBX_NOTSUPPORTED means that the key you are trying to retrieve is not supported by the agent. Not that the command you are trying to execute is failing.

                  Do you have "EnableRemoteCommands=1" in zabbix_agentd.conf?

                  Comment

                  • MrKen
                    Senior Member
                    • Oct 2008
                    • 652

                    #10
                    Trikke,

                    I really don't think that what you are trying to do will work, because as Biobabar pointed out earlier, the correct syntax is "system.run[command,<mode>]" with "wait (default)".

                    So anything that you add after the comma will be interpreted as <mode>.

                    May I suggest you try "system.run[my_script]", where my_script is a small script that you are going to write. Here is a link that might be helpful, it also has example scripts. http://www.robvanderwoude.com/wmistart.php

                    Alternatively, google: wmi scripting

                    MrKen
                    Disclaimer: All of the above is pure speculation.

                    Comment

                    • trikke
                      Senior Member
                      • Aug 2007
                      • 140

                      #11
                      Hi MrKen,

                      You are and Biobabar are absolutely right that the command is "misinterpreted" and everything behind the ',' is interpreted as <mode>. I'm aware of that. ( This "behaviour" used to occure with UserParameters as well.)
                      I was just looking for a way to get passed this.

                      I already thought of the scripting to. There is just one Problem, I have to run the Command on 540 hosts and i really don't want to distribute the script to all of them.

                      Besides it's not just for this wmi-command but could/is helpfull for other commands using ',' as well,
                      greets
                      Patrick

                      Comment

                      • qix
                        Senior Member
                        Zabbix Certified SpecialistZabbix Certified Professional
                        • Oct 2006
                        • 423

                        #12
                        Can you try:
                        zabbix_get -s xxxx -k "system.run['wmic service DisplayName,Name']"

                        and

                        zabbix_get -s xxxx -k system.run['wmic service DisplayName,Name']
                        With kind regards,

                        Raymond

                        Comment

                        • trikke
                          Senior Member
                          • Aug 2007
                          • 140

                          #13
                          Hi QIX,
                          tried that already, no luck!

                          zabbix-zone#zabbix_get -s xxx -k "system.run['wmic service DisplayName,Name']"
                          ZBX_NOTSUPPORTED
                          zabbix-zone#zabbix_get -s xxx -k system.run['wmic service DisplayName,Name']
                          ZBX_NOTSUPPORTED

                          Greets
                          Patrick

                          Comment

                          • qix
                            Senior Member
                            Zabbix Certified SpecialistZabbix Certified Professional
                            • Oct 2006
                            • 423

                            #14
                            darn, too bad
                            With kind regards,

                            Raymond

                            Comment

                            • mcintoshj
                              Junior Member
                              • Oct 2013
                              • 9

                              #15
                              Solution

                              I added a key:
                              system.run["ps -eo pcpu,user,args | sort -k 1 -r|head -4|awk 'NR==2 { firstRow=$0; found=0 } NR>1{ if ($1 > 15) { found=1; print $0 } } END { if (found !=1) { print firstRow } }'"]

                              Which works. The trick is making sure your commands are escpaed correctly. Using zabbix_get, you'd do the below:

                              zabbix_get -s zab01aa01p -k "system.run[\"ps -eo pcpu,user,args | sort -k 1 -r|head -14|awk 'NR==2 { firstRow=\$0; found=0 } NR>1{ if (\$1 > 5) { found=1; print \$0 } } END { if (found != 1) { print firstRow } } '\"]"

                              This is a fairly complicated example. Note I had to escape the quotes and $ values when using the zabbix_get command. The reason is bash interprets things differently than through the items. I use the above to get the current processes using over 15% CPU use.

                              Comment

                              Working...