<s> import sys , requests , time , json <EOL> from clint . textui import colored <EOL> class Bit9 ( object ) : <EOL> def __init__ ( self ) : <EOL> self . b9StrongCert = True <EOL> self . apitoken = "<STR_LIT>" <EOL> self . serverurl = "<STR_LIT>" <EOL> self . authJson = { <EOL> '<STR_LIT>' : self . apitoken , <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' <EOL> } <EOL> self . md5url = self . serverurl + "<STR_LIT>" <EOL> self . fileruleurl = self . serverurl + "<STR_LIT>" <EOL> self . computernameurl = self . serverurl + "<STR_LIT>" <EOL> self . computerurl = self . serverurl + "<STR_LIT>" <EOL> self . pathnameurl = self . serverurl + "<STR_LIT>" <EOL> def find_computer ( self , computername ) : <EOL> r = requests . get ( self . computernameurl + "<STR_LIT>" + computername , headers = self . authJson , verify = self . b9StrongCert ) <EOL> r . raise_for_status ( ) <EOL> result = r . json ( ) <EOL> return result <EOL> def tag_computer ( self , computername , description , computertag ) : <EOL> print colored . yellow ( "<STR_LIT>" + computername ) <EOL> result = self . find_computer ( computername ) <EOL> computerid = str ( result [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] ) <EOL> print colored . green ( "<STR_LIT>" + computername + "<STR_LIT>" + computerid ) <EOL> data = { '<STR_LIT:description>' : description , '<STR_LIT>' : computertag } <EOL> print colored . yellow ( "<STR_LIT>" + computername ) <EOL> r = requests . put ( self . computerurl + computerid , json . dumps ( data ) , headers = self . authJson , verify = self . b9StrongCert ) <EOL> r . raise_for_status ( ) <EOL> result = r . json ( ) <EOL> print colored . green ( "<STR_LIT>" ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> def change_policy ( self , computername ) : <EOL> result = self . find_computer ( computername ) <EOL> computerid = str ( result [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] ) <EOL> data = { '<STR_LIT>' : <NUM_LIT:7> } <EOL> r = requests . put ( self . computerurl + computerid , json . dumps ( data ) , headers = self . authJson , verify = self . b9StrongCert ) <EOL> r . raise_for_status ( ) <EOL> result = r . json ( ) <EOL> def perform_b9_tagging ( workstationdata ) : <EOL> description = workstationdata . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:4> ] + "<STR_LIT:\n>" + workstationdata . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:6> ] + "<STR_LIT:\n>" + workstationdata . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:5> ] + "<STR_LIT:\n>" + workstationdata . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:7> ] + "<STR_LIT:\n>" + workstationdata . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:8> ] + "<STR_LIT:\n>" + workstationdata . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:2> ] + "<STR_LIT:\n>" + workstationdata . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:10> ] + "<STR_LIT:\n>" + workstationdata . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:11> ] <EOL> computertag = workstationdata . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:0> ] + "<STR_LIT:#>" + workstationdata . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:9> ] <EOL> bit9 . tag_computer ( bit9computers [ workstationdata . split ( "<STR_LIT:\t>" ) [ <NUM_LIT:1> ] . lower ( ) ] , description , computertag ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> bit9computers = { } <EOL> bit9 = Bit9 ( ) <EOL> for line in open ( sys . argv [ <NUM_LIT:1> ] ) : <EOL> bit9computers [ line [ <NUM_LIT:3> : ] . lower ( ) . rstrip ( ) ] = line . rstrip ( ) <EOL> for workstation in open ( sys . argv [ <NUM_LIT:2> ] ) : <EOL> if workstation . split ( "<STR_LIT:U+0020>" ) [ <NUM_LIT:1> ] . lower ( ) in bit9computers : <EOL> print workstation . rstrip ( ) <EOL> perform_b9_tagging ( workstation ) <EOL> print colored . green ( "<STR_LIT>" ) </s>
