cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Former Member
Not applicable
Report Inappropriate Content
Message 1 of 4

Tagging Help - Python help for Dummies

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")

3 Replies
Former Member
Not applicable
Report Inappropriate Content
Message 2 of 4

Re: Tagging Help - Python help for Dummies

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.

Former Member
Not applicable
Report Inappropriate Content
Message 3 of 4

Re: Tagging Help - Python help for Dummies

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....

Former Member
Not applicable
Report Inappropriate Content
Message 4 of 4

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.

You Deserve an Award
Don't forget, when your helpful posts earn a kudos or get accepted as a solution you can unlock perks and badges. Those aren't the only badges, either. How many can you collect? Click here to learn more.

Community Help Hub

    New to the forums or need help finding your way around the forums? There's a whole hub of community resources to help you.

  • Find Forum FAQs
  • Learn How to Earn Badges
  • Ask for Help
Go to Community Help

Join the Community

    Thousands of customers use the McAfee Community for peer-to-peer and expert product support. Enjoy these benefits with a free membership:

  • Get helpful solutions from McAfee experts.
  • Stay connected to product conversations that matter to you.
  • Participate in product groups led by McAfee employees.
Join the Community
Join the Community