<s> HTTP_PROXY = { } <EOL> import sys <EOL> import os <EOL> import urllib <EOL> import urllib2 <EOL> import traceback <EOL> import argparse <EOL> libpath = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> sys . path [ : <NUM_LIT:0> ] = [ os . path . join ( libpath , '<STR_LIT>' ) ] <EOL> import common <EOL> import environment <EOL> logger = common . logging . getLogger ( ) . getChild ( '<STR_LIT>' ) <EOL> if environment . run_by_splunk ( ) : <EOL> try : <EOL> import splunk . Intersplunk <EOL> import splunk . entity as entity <EOL> except Exception as e : <EOL> logger . error ( "<STR_LIT>" ) <EOL> logger . error ( traceback . format_exc ( ) ) <EOL> raise e <EOL> def get_cli_args ( ) : <EOL> """<STR_LIT>""" <EOL> parser = argparse . ArgumentParser ( description = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , help = "<STR_LIT>" ) <EOL> options = parser . parse_args ( ) <EOL> return options <EOL> def createOpener ( ) : <EOL> """<STR_LIT>""" <EOL> proxy_handler = urllib2 . ProxyHandler ( HTTP_PROXY ) <EOL> opener = urllib2 . build_opener ( proxy_handler ) <EOL> urllib2 . install_opener ( opener ) <EOL> return opener <EOL> def retrieveWildFireData ( apikey , serial , reportid ) : <EOL> opener = createOpener ( ) <EOL> wfUrl = '<STR_LIT>' <EOL> post_data = urllib . urlencode ( { <EOL> '<STR_LIT>' : apikey , <EOL> '<STR_LIT>' : serial , <EOL> '<STR_LIT>' : reportid , <EOL> } ) <EOL> wfReq = urllib2 . Request ( wfUrl ) <EOL> result = opener . open ( wfReq , post_data ) <EOL> return result <EOL> def main_cli ( ) : <EOL> options = get_cli_args ( ) <EOL> data = retrieveWildFireData ( options . apikey , options . serial , options . reportid ) <EOL> print data . read ( ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> def main_splunk ( ) : <EOL> args , kwargs = splunk . Intersplunk . getKeywordsAndOptions ( ) <EOL> debug = common . check_debug ( kwargs ) <EOL> logger = common . logging . getLogger ( ) <EOL> if debug : <EOL> logger . setLevel ( common . logging . DEBUG ) <EOL> logger . debug ( "<STR_LIT>" ) <EOL> results , unused1 , settings = splunk . Intersplunk . getOrganizedResults ( ) <EOL> sessionKey = settings [ '<STR_LIT>' ] <EOL> if len ( results ) < <NUM_LIT:0> : <EOL> logger . debug ( "<STR_LIT>" ) <EOL> splunk . Intersplunk . outputResults ( results ) <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> logger . debug ( "<STR_LIT>" ) <EOL> wf_apikey = common . get_wildfire_apikey ( sessionKey ) <EOL> logger . debug ( "<STR_LIT>" % len ( results ) ) <EOL> for idx , result in enumerate ( results ) : <EOL> if '<STR_LIT>' in result and '<STR_LIT>' in result : <EOL> logger . debug ( "<STR_LIT>" % ( idx , result [ '<STR_LIT>' ] ) ) <EOL> try : <EOL> wfReportXml = retrieveWildFireData ( wf_apikey , result [ '<STR_LIT>' ] , <EOL> result [ '<STR_LIT>' ] ) . read ( ) . strip ( ) <EOL> wfReportXml = wfReportXml . replace ( "<STR_LIT>" , "<STR_LIT>" + result [ '<STR_LIT>' ] + "<STR_LIT>" , <NUM_LIT:1> ) <EOL> result [ '<STR_LIT>' ] = wfReportXml <EOL> except : <EOL> logger . warn ( "<STR_LIT>" % result [ '<STR_LIT>' ] ) <EOL> logger . info ( "<STR_LIT>" % result ) <EOL> stack = traceback . format_exc ( ) <EOL> logger . warn ( stack ) <EOL> else : <EOL> logger . debug ( "<STR_LIT>" <EOL> "<STR_LIT>" % idx ) <EOL> splunk . Intersplunk . outputResults ( results ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> if environment . run_by_splunk ( ) : <EOL> main_splunk ( ) <EOL> else : <EOL> main_cli ( ) </s>
