import sys curpath = os.path.dirname(os.path.abspath(__file__)) sys.path[:0] = [os.path.join(curpath, os.pardir)] from pancloud import HTTPClient, LoggingService, EventService, \ DirectorySyncService, Credentials url = 'https://api.us.paloaltonetworks.com' c = Credentials() session = HTTPClient(url=url, credentials=c) ls = LoggingService(session=session) dss = DirectorySyncService(session=session) es = EventService(session=session) f = es.get_filters('EventFilter') print("\nGET EVENT FILTERS...") print("STATUS_CODE: {}, RESULT: \n\n{}\n".format(f.status_code, f.text)) a = dss.attributes() print("\nGET ATTRIBUTES...") print("STATUS_CODE: {}, RESULT: \n\n{}\n".format(a.status_code, a.text)) data = { # Prepare 'query' data "query": "SELECT * FROM panw.traffic LIMIT 1", "startTime": 0, # 1970 "endTime": 1609459200, # 2021 "maxWaitTime": 0 # no logs in initial response
# -*- coding: utf-8 -*- """Example interaction with Directory-Sync Service using attributes.""" import os import sys curpath = os.path.dirname(os.path.abspath(__file__)) sys.path[:0] = [os.path.join(curpath, os.pardir)] from pancloud import DirectorySyncService url = 'https://apigw-stg4.us.paloaltonetworks.com' # `export ACCESS_TOKEN=<access token>` access_token = os.environ['ACCESS_TOKEN'] # Create Directory-Sync Service instance ds = DirectorySyncService(url=url, headers={ 'Authorization': 'Bearer {}'.format(access_token), "Content-Type": "application/json", "Accept": "application/json" }) # Retrieve attributes from directory-sync a = ds.attributes() # Print results print("\nSTATUS_CODE: {}, RESULT: {}\n".format(a.status_code, a.text))
#!/usr/bin/env python # -*- coding: utf-8 -*- """Example interaction with Directory Sync Service using query.""" import os import sys curpath = os.path.dirname(os.path.abspath(__file__)) sys.path[:0] = [os.path.join(curpath, os.pardir)] from pancloud import DirectorySyncService, Credentials url = 'https://api.us.paloaltonetworks.com' c = Credentials() # Create Directory-Sync Service instance ds = DirectorySyncService(url=url, credentials=c) OBJ_CLASS = "users" # users | computers | containers | groups | ous DOMAIN = "example.com" # use domains() method to retrieve available domains # Retrieve attributes from directory-sync q = ds.query(object_class=OBJ_CLASS, json={'domain': DOMAIN}) # Print results print("\nSTATUS_CODE: {}, RESULT: \n\n{}\n".format(q.status_code, q.text))
#!/usr/bin/env python # -*- coding: utf-8 -*- """Example interaction with Directory Sync Service using count.""" import os import sys curpath = os.path.dirname(os.path.abspath(__file__)) sys.path[:0] = [os.path.join(curpath, os.pardir)] from pancloud import DirectorySyncService, Credentials url = 'https://api.us.paloaltonetworks.com' c = Credentials() # Create Directory-Sync Service instance ds = DirectorySyncService(url=url, credentials=c) OBJ_CLASS = "users" # users | computers | containers | groups | ous DOMAIN = "example.com" # use domains() method to retrieve available domains # Retrieve attributes from directory-sync c = ds.count(object_class=OBJ_CLASS, params={'domain': DOMAIN}) # Print results print("\nSTATUS_CODE: {}, RESULT: \n\n{}\n".format(c.status_code, c.text))
def directory_sync(options, session): def generic(api, options, func, k): R = options['R'] try: r = func(**R['R2_obj'][k]) except Exception as e: print_exception(k, e) sys.exit(1) print_status(k, r, options) print_response(r, options, k) exit_for_http_status(r) def query(api, options): k = 'DirectorySyncService.query' R = options['R'] try: r = api.query(object_class=options['id'], json=R['R1_obj'][k], **R['R2_obj'][k]) except Exception as e: print_exception(k, e) sys.exit(1) print_status(k, r, options) print_response(r, options, k) exit_for_http_status(r) def count(api, options): k = 'DirectorySyncService.count' R = options['R'] try: r = api.count(object_class=options['id'], params=R['R1_obj'][k], **R['R2_obj'][k]) except Exception as e: print_exception(k, e) sys.exit(1) print_status(k, r, options) print_response(r, options, k) exit_for_http_status(r) def domains(api, options): k = 'DirectorySyncService.domains' generic(api, options, api.domains, k) def attributes(api, options): k = 'DirectorySyncService.attributes' generic(api, options, api.attributes, k) k = 'DirectorySyncService' R = options['R'] try: api = DirectorySyncService(session=session, **R['R0_obj'][k]) except Exception as e: print_exception(k, e) sys.exit(1) if options['debug'] > 0: print(api, file=sys.stderr) if options['query']: query(api, options) if options['count']: count(api, options) if options['domains']: domains(api, options) if options['attributes']: attributes(api, options) setters(options, api) methods(options, api)
#!/usr/bin/env python # -*- coding: utf-8 -*- """Example interaction with Directory Sync Service using domains.""" import os import sys curpath = os.path.dirname(os.path.abspath(__file__)) sys.path[:0] = [os.path.join(curpath, os.pardir)] from pancloud import DirectorySyncService, Credentials url = 'https://api.us.paloaltonetworks.com' c = Credentials() # Create Directory-Sync Service instance ds = DirectorySyncService( url=url, credentials=c ) # Retrieve domains d = ds.domains() # Print results print( "\nSTATUS_CODE: {}, RESULT: \n\n{}\n".format(d.status_code, d.text) )
url = 'https://apigw-stg4.us.paloaltonetworks.com' # `export ACCESS_TOKEN=<access token>` access_token = os.environ['ACCESS_TOKEN'] session = HTTPClient(url=url, max_retries=5, pool_maxsize=30, headers={ 'Authorization': 'Bearer {}'.format(access_token), "Content-Type": "application/json", "Accept": "application/json" }) ls = LoggingService(session=session) dss = DirectorySyncService(session=session) es = EventService(session=session) filters = { # Prepare 'filter' data "filters": [{ "panw.threat": "SELECT * FROM panw.threat" }, { "panw.traffic": "SELECT * FROM panw.traffic" }, { "panw.system": "SELECT * FROM panw.system" }, { "panw.config": "SELECT * FROM panw.config" }] } channel_id = 'EventFilter'
# -*- coding: utf-8 -*- """Example interaction with Directory-Sync Service using count.""" import os import sys curpath = os.path.dirname(os.path.abspath(__file__)) sys.path[:0] = [os.path.join(curpath, os.pardir)] from pancloud import DirectorySyncService url = 'https://apigw-stg4.us.paloaltonetworks.com' # `export ACCESS_TOKEN=<access token>` access_token = os.environ['ACCESS_TOKEN'] # Create Directory-Sync Service instance ds = DirectorySyncService(url=url, headers={ 'Authorization': 'Bearer {}'.format(access_token), "Content-Type": "application/json", "Accept": "application/json" }) # Retrieve attributes from directory-sync a = ds.count(object_class="computer", params={'domain': 'parent.com'}) # Print results print("\nSTATUS_CODE: {}, RESULT: {}\n".format(a.status_code, a.text))
#!/usr/bin/env python # -*- coding: utf-8 -*- """Example interaction with Directory Sync Service using attributes.""" import os import sys curpath = os.path.dirname(os.path.abspath(__file__)) sys.path[:0] = [os.path.join(curpath, os.pardir)] from pancloud import DirectorySyncService, Credentials url = 'https://api.us.paloaltonetworks.com' c = Credentials() # Create Directory-Sync Service instance ds = DirectorySyncService( url=url, credentials=c ) # Retrieve attributes from directory-sync a = ds.attributes() # Print results print( "\nSTATUS_CODE: {}, RESULT: \n\n{}\n".format(a.status_code, a.text) )