def exit_with_error(self, e, errorcode=2, log_traceback=True): if log_traceback: self.logger.error(''.join(traceback.format_stack())) self.logger.error(str(e)) if run_by_splunk(): splunk.Intersplunk.generateErrorResults(str(e)) sys.exit(errorcode)
# certain of the ramifications of the changes ######################################################### import sys # for system params and sys.exit() import os libpath = os.path.dirname(os.path.abspath(__file__)) sys.path[:0] = [os.path.join(libpath, 'lib')] import common import environment logger = common.logging.getLogger().getChild('panTag') #logger.setLevel(pan_common.logging.INFO) try: if environment.run_by_splunk(): import splunk.Intersplunk # so you can interact with Splunk import splunk.entity as entity # for splunk config info libpath = os.path.dirname(os.path.abspath(__file__)) sys.path[:0] = [os.path.join(libpath, 'lib')] sys.path[:0] = [os.path.join(libpath, 'lib', 'pan-python', 'lib')] sys.path[:0] = [os.path.join(libpath, 'lib', 'pandevice')] import pandevice from pandevice.panorama import Panorama from pandevice.firewall import Firewall import pan.xapi from common import log except Exception as e:
# certain of the ramifications of the changes ######################################################### import sys # for system params and sys.exit() import os libpath = os.path.dirname(os.path.abspath(__file__)) sys.path[:0] = [os.path.join(libpath, "lib")] import common import environment logger = common.logging.getLogger().getChild("panUserUpdate") try: if environment.run_by_splunk(): import splunk.Intersplunk # so you can interact with Splunk import splunk.entity as entity # for splunk config info libpath = os.path.dirname(os.path.abspath(__file__)) sys.path[:0] = [os.path.join(libpath, "lib")] sys.path[:0] = [os.path.join(libpath, "lib", "pan-python", "lib")] sys.path[:0] = [os.path.join(libpath, "lib", "pandevice")] import pandevice from pandevice.panorama import Panorama from pandevice.firewall import Firewall import pan.xapi from common import log except Exception as e:
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # Author: Brian Torres-Gil <*****@*****.**> """Common functions used by all custom searchbar commands""" import os import sys import traceback import json from environment import run_by_splunk '''Import different logging library depending if script was run by Splunk or on cli''' if run_by_splunk(): import splunk.Intersplunk import splunk.mining.dcutils as logging import splunk.entity as entity # for splunk config info from splunk import ResourceNotFound logger = logging.getLogger() else: import logging # python 2.6 doesn't have a null handler, so create it if not hasattr(logging, 'NullHandler'): class NullHandler(logging.Handler): def emit(self, record): pass logging.NullHandler = NullHandler
def create_logger(in_splunk): if in_splunk: import splunk.mining.dcutils as logging # this logs to python.log logger = logging.getLogger() else: import logging logger = logging.getLogger() ch = logging.StreamHandler(sys.stdout) logger.addHandler(ch) formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') ch.setFormatter(formatter) return logger # Import library if script was run by Splunk if run_by_splunk(): import splunk.Intersplunk import splunk.entity as entity # for splunk config info from splunk import ResourceNotFound libpath = os.path.dirname(os.path.abspath(__file__)) sys.path[:0] = [os.path.join(libpath)] sys.path[:0] = [os.path.join(libpath, 'pan-python', 'lib')] sys.path[:0] = [os.path.join(libpath, 'pandevice')] try: import pandevice.base except Exception as e: sys.exit(4) class NoCredentialsFound(Exception):