def main(argv): debug_level = 0 debug = False mylogger = rtclogger.LOGGER("rtcQ", debug_level, "") try: post = str(sys.stdin.read()) info = json.loads(post) guid = info["guid"] # creds = json.loads(open("/tmp/config.json").read()) dbconn = rtcdb.RTCDB() dbresult = dbconn.getXconfig("ampconfig") creds = json.loads(dbresult["configstring"]) AMP_api_client_id = creds["amp_api_client_id"] AMP_api_key = creds["amp_api_key"] amp = cats.AMP(cloud="us", api_client_id=AMP_api_client_id, api_key=AMP_api_key, debug=debug, logfile="") rsp = amp.stopHostIsolation(guid=guid) rsp.update({"rtcResult": "OK"}) except Exception as err: rsp = {"rtcResult": mylogger.exception_info(err)} print("Content-type:application/json\n\n") print(json.dumps(rsp))
def __init__(self,name,thresholdLogLevel,logfilename): try: threading.Thread.__init__(self) self.logthreshold = thresholdLogLevel self.logger = rtclogger.LOGGER(name,thresholdLogLevel,logfilename) self.logger.log_debug(0,"starting {} thread with log level {}".format(name,str(thresholdLogLevel))) self.db = rtcdb.RTCDB() dbresult = self.db.getConfig("rtcconfig") self.rtcConfig = json.loads(dbresult["configstring"]) self.threshold = self.rtcConfig["rtcThreshold"] dbresult = self.db.getConfig("iseconfig") creds = json.loads(dbresult["configstring"]) ISE_SERVER = creds["ise_server"] ISE_USERNAME = creds["ise_username"] ISE_PASSWORD = creds["ise_password"] if "pxgrid_password" in creds: PXGRID_PASSWORD = creds["pxgrid_password"] else: PXGRID_PASSWORD = "" PXGRID_CLIENT_CERT = creds["pxgrid_client_cert"] PXGRID_CLIENT_KEY = creds["pxgrid_client_key"] PXGRID_CLIENT_KEY_PASSWORD = creds["pxgrid_client_key_pw"] PXGRID_SERVER_CERT = creds["pxgrid_server_cert"] PXGRID_NODENAME = creds["pxgrid_nodename"] self.pxgrid = cats.ISE_PXGRID(server=ISE_SERVER,clientcert=PXGRID_CLIENT_CERT,clientkey=PXGRID_CLIENT_KEY,clientkeypassword=PXGRID_CLIENT_KEY_PASSWORD,servercert=PXGRID_SERVER_CERT,nodename=PXGRID_NODENAME,password=PXGRID_PASSWORD,debug=False,logfile="") self.ise_anc = cats.ISE_ANC(ISE_SERVER,ISE_USERNAME,ISE_PASSWORD,debug=False) self.ancpolicy = self.rtcConfig["rtcPolicyName"] dbresultAMP = self.db.getXconfig("ampconfig") credsAMP = json.loads(dbresultAMP["configstring"]) AMP_cloud = "us" AMP_api_client_id = credsAMP["amp_api_client_id"] AMP_api_key = credsAMP["amp_api_key"] self.amp = cats.AMP(cloud=AMP_cloud,api_client_id=AMP_api_client_id,api_key=AMP_api_key,debug=False,logfile="") except Exception as err: self.logger.log_debug(0,self.logger.exception_info(err))
def main(argv): debug_level = 0 mylogger = rtclogger.LOGGER("AMPeventDetails", debug_level, "") try: if 'REQUEST_METHOD' in os.environ: ### this is called as CGI script and we should avoid printouts debug = False post = str(sys.stdin.read()) request = json.loads(post) days = int(request["days"]) hours = int(request["hours"]) minutes = int(request["hours"]) else: ### this is called via CLI for troubleshooting recurring = "True" debug = True days = 0 hours = 1 minutes = 0 dbconn = rtcdb.RTCDB() dbresult = dbconn.getXconfig("ampconfig") creds = json.loads(dbresult["configstring"]) API_CLIENT_ID = creds["amp_api_client_id"] API_KEY = creds["amp_api_key"] a = cats.AMP(cloud="us", api_client_id=API_CLIENT_ID, api_key=API_KEY, debug=False, logfile="/tmp/rtcAMPevents.log") amp_rsp = a.events(days=days, hours=hours, minutes=minutes) rsp = {"rtcResult": "OK"} rsp.update({"events": amp_rsp["data"]}) except Exception as err: rsp = {"rtcResult": mylogger.exception_info(err)} print("Content-type:application/json\n\n") print(json.dumps(rsp))
def main(argv): debug_level = 0 mylogger = rtclogger.LOGGER("AMPeventDetails", debug_level, "") try: dbconn = rtcdb.RTCDB() dbresult = dbconn.getXconfig("adconfig") ad_config = json.loads(dbresult["configstring"]) ADgroups = [] if "ad_server" in ad_config: ad_server = Server(ad_config["ad_server"], get_info=ALL) ad_conn = Connection(ad_server,user=ad_config["ad_username"],password=ad_config["ad_password"], auto_bind\ = True) ad_conn.search(search_base=ad_config["ad_base_dn"], search_filter='(objectclass=Group)', attributes=['cn']) groups = ad_conn.entries for group in groups: ADgroups.append(group.cn.values[0]) dbresult = dbconn.getXconfig("iseconfig") iseconfig = json.loads(dbresult["configstring"]) server = iseconfig["ise_server"] username = iseconfig["ise_username"] password = iseconfig["ise_password"] ise = cats.ISE_ANC(server=server, username=username, password=password, debug=False) isePolicies = ise.listPolicies() dbresult = dbconn.getXconfig("swconfig") swconfig = json.loads(dbresult["configstring"]) server = swconfig["sw_server"] username = swconfig["sw_username"] password = swconfig["sw_password"] sw = cats.SW(server=server, username=username, password=password, debug=False) swEvents = sw.eventList() dbresult = dbconn.getXconfig("ampconfig") ampConfig = json.loads(dbresult["configstring"]) API_CLIENT_ID = ampConfig["amp_api_client_id"] API_KEY = ampConfig["amp_api_key"] amp = cats.AMP(cloud="us", api_client_id=API_CLIENT_ID, api_key=API_KEY, debug=False, logfile="") ampEvents = amp.eventTypes() rsp = {"rtcResult": "OK"} rsp.update({"ADgroups": ADgroups}) rsp.update({"swEvents": swEvents}) rsp.update({"ampEvents": ampEvents}) rsp.update({"isePolicies": isePolicies}) print("Content-type:application/json\n\n") ret = json.dumps(rsp) print(ret) except Exception as err: print("Content-type:application/json\n\n") result = { "rtcResult": "Error", "info": "some error {}".format(mylogger.exception_info(err)) } print(json.dumps(result))
def main(argv): ### default never log,change this if needed debug_level = 0 mylogger = rtclogger.LOGGER("getHosts", debug_level, "") try: if 'REQUEST_METHOD' in os.environ: ### this is called as CGI script and we should avoid printouts debug = False post = str(sys.stdin.read()) temp = json.loads(post) recurring = temp["recurring"] else: ### this is called via CLI for troubleshooting recurring = "True" debug = True dbconn = rtcdb.RTCDB() rsp = dbconn.getHosts() hosts = rsp["items"] mylogger.log_debug(7, json.dumps(hosts)) dbresult = dbconn.getXconfig("iseconfig") creds = json.loads(dbresult["configstring"]) i = None if "ise_server" in creds: ISE_SERVER = creds["ise_server"] ISE_USERNAME = creds["ise_username"] ISE_PASSWORD = creds["ise_password"] if "pxgrid_password" in creds: PXGRID_PASSWORD = creds["pxgrid_password"] else: PXGRID_PASSWORD = "" PXGRID_CLIENT_CERT = creds["pxgrid_client_cert"] PXGRID_CLIENT_KEY = creds["pxgrid_client_key"] PXGRID_CLIENT_KEY_PASSWORD = creds["pxgrid_client_key_pw"] PXGRID_SERVER_CERT = creds["pxgrid_server_cert"] PXGRID_NODENAME = creds["pxgrid_nodename"] i = cats.ISE_PXGRID(server=ISE_SERVER, debug=debug, logfile="", clientcert=PXGRID_CLIENT_CERT, clientkey=PXGRID_CLIENT_KEY, clientkeypassword=PXGRID_CLIENT_KEY_PASSWORD, servercert=PXGRID_SERVER_CERT, nodename=PXGRID_NODENAME, password=PXGRID_PASSWORD) anc = cats.ISE_ANC(ISE_SERVER, ISE_USERNAME, ISE_PASSWORD, debug=debug, logfile="") dbresult = dbconn.getXconfig("ampconfig") creds = json.loads(dbresult["configstring"]) a = None if "amp_api_client_id" in creds: API_CLIENT_ID = creds["amp_api_client_id"] API_KEY = creds["amp_api_key"] a = cats.AMP(cloud="us", api_client_id=API_CLIENT_ID, api_key=API_KEY, debug=debug, logfile="") for h in hosts: mylogger.log_debug(7, "Host is ".format(json.dumps(h))) if i: try: mylogger.log_debug(7, "getting sessions for " + h["mac"]) rsp = i.getSessions(mac=h["mac"]) mylogger.log_debug( 7, "pxgrid rsp {}".format(json.dumps(rsp))) h.update({"ise": rsp}) except Exception as err: mylogger.log_debug( 2, "ise sessions " + mylogger.exception_info(err)) h.update({"ise": {}}) else: h.update({"ise": {}}) if a: try: # is this the same rsp as gotten from getsessions?!?! ip = rsp["ipAddresses"][0] rsp = a.computers(internal_ip=ip) mylogger.log_debug(7, "AMP resp" + json.dumps(rsp)) h.update({"amp": rsp}) except Exception as err: mylogger.log_debug( 1, "amp exception" + mylogger.exception_info(err)) h.update({"amp": {}}) else: h.update({"amp": {}}) if anc: try: mylogger.log_debug(7, "reading ISE ANC for " + h["mac"]) rsp = anc.macPolicy(h["mac"]) h.update({"ancpolicy": rsp["policy"]}) except Exception as err: h.update({"ancpolicy": ""}) mylogger.log_debug( 1, "ise anc exception" + mylogger.exception_info(err)) else: h.update({"ancpolicy": ""}) # get all the rtcEvent for this host try: rsp = dbconn.getAMPevents(h["mac"]) h.update({"ampevents": rsp}) except Exception as err: h.update({"ampevents": {}}) mylogger.log_debug( 1, "ampevents exception" + mylogger.exception_info(err)) try: rsp = dbconn.getSWevents(h["mac"]) h.update({"swevents": rsp}) except Exception as err: h.update({"swevents": {}}) try: rsp = dbconn.getUMBevents(h["mac"]) h.update({"umbevents": rsp}) except Exception as err: h.update({"umbevents": {}}) mylogger.log_debug( 1, "umbevents exception" + mylogger.exception_info(err)) rsp = {"rtcResult": "OK"} rsp.update({"items": hosts}) rsp.update({"recurring": recurring}) except Exception as err: rsp = {"rtcResult": mylogger.exception_info(err)} print("Content-type:application/json\n\n") print(json.dumps(rsp))
def main(argv): debug_level = 0 mylogger = rtclogger.LOGGER("GetDynOptions",debug_level,"") try: if 'REQUEST_METHOD' in os.environ : ### this is called as CGI script and we should avoid printouts debug = False post = str(sys.stdin.read()) temp = json.loads(post) item = temp["item"] else : ### this is called via CLI for troubleshooting item = "all" recurring = "True" debug = True item = "all" dbconn = rtcdb.RTCDB() dbresult = dbconn.getXconfig("adconfig") ADgroups = [] if item == "all" or item=="adconfig": ad_config = json.loads(dbresult["configstring"]) if "ad_server" in ad_config: ad_server = Server(ad_config["ad_server"],get_info = ALL) ad_conn = Connection(ad_server,user=ad_config["ad_username"],password=ad_config["ad_password"], auto_bind\ = True) ad_conn.search(search_base=ad_config["ad_base_dn"],search_filter = '(objectclass=Group)',attributes=['cn']) groups = ad_conn.entries for group in groups: ADgroups.append(group.cn.values[0]) isePolicies = [] if item == "all" or item=="iseconfig": dbresult = dbconn.getXconfig("iseconfig") iseconfig = json.loads(dbresult["configstring"]) if "ise_server" in iseconfig: server = iseconfig["ise_server"] username = iseconfig["ise_username"] password = iseconfig["ise_password"] ise = cats.ISE_ANC(server=server,username=username,password=password,debug=False) isePolicies = ise.listPolicies() swEvents = [] swHostGroups = [] if item == "all" or item=="swconfig": dbresult = dbconn.getXconfig("swconfig") swconfig = json.loads(dbresult["configstring"]) if "sw_server" in swconfig: server = swconfig["sw_server"] username = swconfig["sw_username"] password = swconfig["sw_password"] sw = cats.SW(server=server,username=username,password=password,debug=False) swEvents = sw.eventList() swHostGroups = sw.getHostGroups() ampEvents = [] if item == "all" or item=="ampconfig": dbresult = dbconn.getXconfig("ampconfig") ampConfig = json.loads(dbresult["configstring"]) if "amp_api_client_id" in ampConfig: API_CLIENT_ID = ampConfig["amp_api_client_id"] API_KEY = ampConfig["amp_api_key"] amp = cats.AMP(cloud="us",api_client_id=API_CLIENT_ID,api_key=API_KEY,debug=False,logfile="") ampEvents = amp.eventTypes() rsp = {"rtcResult":"OK"} rsp.update({"item": item}) rsp.update({"ADgroups": ADgroups}) rsp.update({"swEvents": swEvents}) rsp.update({"swHostGroups": swHostGroups}) rsp.update({"ampEvents": ampEvents}) rsp.update({"isePolicies": isePolicies}) print("Content-type:application/json\n\n") ret = json.dumps(rsp) print (ret) except Exception as err: print("Content-type:application/json\n\n") result = { "rtcResult":"Error","info":"some error {}".format(mylogger.exception_info(err)) } print(json.dumps(result))