36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
![]() |
#!/usr/bin/env python3
|
||
|
import os
|
||
|
import sys
|
||
|
import json
|
||
|
import requests
|
||
|
import configparser
|
||
|
|
||
|
###############################################
|
||
|
# Look for oss.cnf file in current working directory
|
||
|
CONFIG_FILE = "./oss.cnf"
|
||
|
if not os.path.isfile(CONFIG_FILE):
|
||
|
logging.error(f"The config file {CONFIG_FILE} doesn't exist")
|
||
|
sys.exit(1)
|
||
|
config = configparser.RawConfigParser()
|
||
|
config.read(CONFIG_FILE)
|
||
|
NTSKP_TENANT = config.get('netskope', 'NTSKP_TENANT')
|
||
|
NTSKP_TOKEN = config.get('netskope', 'NTSKP_TOKEN')
|
||
|
NTSKP_PERIOD = config.get('netskope', 'NTSKP_PERIOD')
|
||
|
|
||
|
###############################################
|
||
|
|
||
|
ssl_session = requests.Session()
|
||
|
uri = f"{NTSKP_TENANT}/api/v1/alerts?token={NTSKP_TOKEN}&timeperiod={NTSKP_PERIOD}&groupby=application&query=access_method+eq+Client+and+action+eq+block"
|
||
|
try:
|
||
|
r = ssl_session.get(uri)
|
||
|
r.raise_for_status()
|
||
|
except Exception as e:
|
||
|
logging.error(f'Error: {str(e)}')
|
||
|
sys.exit(1)
|
||
|
json = r.json()
|
||
|
if 'data' in json:
|
||
|
for item in json['data']:
|
||
|
if 'app' in item:
|
||
|
print(f"{item['app']} - {item['category']}", end=', ')
|
||
|
print()
|