3 Replies Latest reply on Jul 31, 2013 6:18 PM by elsean

    Tagging Help - Python help for Dummies

    jsharky-1960

      I'm a newbie to posting and specifically Python, but am in dire need of tagging a list of systems.  I'm a little disappointed that Platinum support states that they do not support Python scripting, and that know one there know anyone that would help.

       

      I am able to perform the following, but fail at iterating through my list.  The last system in the list is tagged, but all previous systems in the list remain untagged.  Any help would be greatly appreciated.  Importing the McAfee module, logging onto my ePO server, and tagging the last system in my list work.

       

      What am I missing?

       

      Do I need to make any other changes to the McAfee supplied sample?

       

       

       

       

      import mcafee

      #initiate connection
      #mc = mcafee.client('myeposerver','8443','usr','pwd')
      mc = mcafee.client('usspsepo52v', '8443', 'userid','password', output='json', display=True)


      #open text file
      file = open('C:/Program Files (x86)/python-remote-client/pyclient/Python26/mcafee-samples/systems1.txt', 'r')

      #iterate through list and assign tags
      for line in file:
          mc.system.applyTag(line, "BO 4.0")

        • 1. Re: Tagging Help - Python help for Dummies
          tkincher

          After debugging into this, it looks like it is picking up the linefeed characters (\n) as part of the system name (system "foo" gets read in as "foo\n" and it can't find the system). This is, obviously, less than ideal. However, if you provide the list of system names as a comma-delimited list, it will work properly and tag them all in one pass (you will want a comma after the final name, as well, to avoid the linefeed character being picked up there).

           

          I am not sure if this is a behavior that changed at some point, as all of the examples provided in the guide were tested, but hopefully this workaround will work for your situation. I will file a defect to track this issue further.

          1 of 1 people found this helpful
          • 2. Re: Tagging Help - Python help for Dummies
            jsharky-1960

            Thanks for the reply tkincher.

             

            I found out just before you posted your response. Kind of silly since the docs provided don't mention that and the sample doc is laid out and the assumption was made that it's suppose to be that way, not as a comma seperated file.  Since I'm not a Pyhton expert it was very frustrating, but it's all good now.

             

             

            Thanks....

            • 3. Re: Tagging Help - Python help for Dummies

              So McAfee shouldn't be expected by anybody to debug scripts that their customers are using, but they should document the feature with enough information so that the feature can be used. After having the same problem, (and not wanting to manipulate the file) I prowled the python forums, and found the rstrip method, which strips out the \n and the whitespace in the file. 

               

              i modified the for loop in the example a bit to look like:

               

              file = open('foo.txt')

               

              for line in file:

                   HOSTNAMEVAR=line.rstrip()

                   mc.system.applyTag(HOSTNAMEVAR, "<tag>")

               

              After that it works like a champ.

               

              BTW I checked and re-checked the McAfee published Python API guide, and it says that the systems should be listed one per line.