6 Replies Latest reply on Nov 30, 2011 1:57 PM by andrep1

    running ad-hoc query in Python, wake on lan project


      Having a little difficulty with getting started in running queries using python. The following always comes back with a "CommandInvokerError: Invalid column name:" and the content of the string I'm trying to match.


      Here's the query I'm trying to execute:


      import mcafee

      mc=mcafee.client("server", "port", "user","password")





                           select="(select EPOLeafNode.NodeName EPOComputerProperties.NetAddress EPOComputerProperties.IPSubnet EPOComputerProperties.IPSubnetMask)",

                           where="(where(eq EPOLeafNode.NodeName "+device+"))"



      Any input would be appreciated.


      As a side note, what I'm trying to do is extract information from ePO to script a wake on lan tool. Input a device name, and extract the mac, subnet address and mask from ePO. Transform the info provided by ePO to a usable format to send a wake on lan packet to the subnet on which the device resides.



        • 1. Re: running ad-hoc query in Python, wake on lan project

          I had a play and converted the python query into a web query to test and i got it to work


 t EPOLeafNode.NodeName EPOComputerProperties.NetAddress EPOComputerProperties.IPSubnet EPOComputerProperties.IPSubnetMask)&where=(where(eq EPOLeafNode.NodeName "spare-till1"))


          Note that i hard-coded the nodename instead of substituting a variable.


          Have you tried replacing +device+ with just a text value?

          1 of 1 people found this helpful
          • 2. Re: running ad-hoc query in Python, wake on lan project

            I did have my original query as a web query and it was working. Problem is that if you want to script it, you start getting into situation where you can't get to the page because of the untrusted root certificate. If it werent for that  I would have shoved that into a vbs and would have been half way there. My original test script with the literal device name was also generating the same error message.


            Did you end up trying it as a pyton ?


            Thanks for the suggestions, I'm open to more...

            • 3. Re: running ad-hoc query in Python, wake on lan project

              I think the problem is you need to have quotes around the system name.  This worked for me ...


              >>> import mcafee

              >>> mc = mcafee.client("localhost","8443","uname","password")                                                         

              >>> systemname="system-1"                                                                                     

              >>> mc.core.executeQuery(target="EPOLeafNode",select="(select EPOLeafNode.NodeName)",where="(where(eq EPOLeafNode.NodeName \""+systemname+"\"))")

              [{u'EPOLeafNode.NodeName': u'system-1'}]



              Note the backslash-quote around my 'systemname' ...



              • 4. Re: running ad-hoc query in Python, wake on lan project

                Perfect that did it! Thanks.


                Python is still very new to me. Any idea how I can parse the output to an array or discrete varaibles? I thought it would be accessible with an index, it looks like  a dictionnary structure...

                • 5. Re: running ad-hoc query in Python, wake on lan project

                  python parses json natively, so if you just assign the result to a variable, you can then index into it.


                  And it's actually an array of dictionaries ... so here's a quick extension of the above ...


                  // this is mostly the example above, but I added a second column, and used 'contains' instead of 'eq' so I get more than one match

                  >>> systemname="system"                                                                                       

                  >>> systems=mc.core.executeQuery(target="EPOLeafNode",select="(select EPOLeafNode.NodeName EPOLeafNode.ManagedState)",where="(where(contains EPOLeafNode.NodeName \""+systemname+"\"))")


                  // note I assigned the result to the variable systems.  It now contains three items.

                  >>> len(systems)


                  >>> systems

                  [{u'EPOLeafNode.NodeName': u'system-1', u'EPOLeafNode.ManagedState': u'unmanaged'}, {u'EPOLeafNode.NodeName': u'system-2', u'EPOLeafNode.ManagedState': u'unmanaged'}, {u'EPOLeafNode.NodeName': u'system-3', u'EPOLeafNode.ManagedState': u'unmanaged'}]


                  // if I look at the first system, I can see both properties

                  >>> systems[0]

                  {u'EPOLeafNode.NodeName': u'system-1', u'EPOLeafNode.ManagedState': u'unmanaged'}


                  // but I can also index into individual values from the dictionary as well

                  >>> systems[0]["EPOLeafNode.NodeName"]





                  Hope that's useful.



                  1 of 1 people found this helpful
                  • 6. Re: running ad-hoc query in Python, wake on lan project

                    Perfect, I had tried a similar syntax but with numeric indexes and it wasn't working. It really clears things up.

                    I have my data, just need to transform it to a usable state now.