def get_vnf_compute_kpi(FOS_INFO, ACC_INFO): usage = {} for vnf in FOS_INFO.keys(): vnf_conn = FortigateApi.Fortigate(FOS_INFO[vnf]['ip'], ACC_INFO['domain'], ACC_INFO['id'], FOS_INFO[vnf]['pw']) Response = vnf_conn.ApiGet( 'monitor/system/resource/usage') # usage history #print '3=',Response.status_code,'==' print '-logout-' print FortigateApi.Fortigate.Logout(vnf_conn) if Response.status_code != 200: ''' abnormal process ''' #print 'Response.status_code : [',Response.status_code,']' #print "Not valid connect to forti-os. Check the connection to [",vnf,"], please.." usage['timestamp'] = str(time.time()) usage['message'] = 'Invalid connect to forti-os' else: ''' normal process ''' data = Response.json() #pprint (data) #print type(data) # dict usage['cpu'] = data['results']['cpu'][0]['current'] usage['mem'] = data['results']['mem'][0]['current'] usage['disk'] = data['results']['disk'][0]['current'] usage['session'] = data['results']['session'][0]['current'] #print '+1+++++++++++++++++++++' #print vnf, usage, type(usage) TOTAL_VNF_USAGE[vnf] = {} TOTAL_VNF_USAGE[vnf].update(usage) # dictionary not work #print '+2+++++++++++++++++++++' #print TOTAL_VNF_USAGE #pprint (TOTAL_VNF_USAGE) # dict JSON_VNF_USAGE = json.dumps(TOTAL_VNF_USAGE) #pprint (JSON_VNF_USAGE) #pprint (type(JSON_VNF_USAGE)) return JSON_VNF_USAGE
def get_vnf_network_kpi(FOS_INFO, ACC_INFO): usage={} for vnf in FOS_INFO.keys(): #print vnf, type(vnf) ''' using dedicated-passwd print FOS_INFO[vnf]['ip'], FOS_INFO[vnf]['pw'], type(FOS_INFO[vnf]['ip']), type(FOS_INFO[vnf]['pw']) print ACC_INFO['domain'],ACC_INFO['id'], type(ACC_INFO['domain']), type(ACC_INFO['id']) ''' #vnf_conn = FortigateApi.Fortigate(FOS_INFO[vnf]['ip'], ACC_INFO['domain'], ACC_INFO['id'], ACC_INFO['pw']) vnf_conn = FortigateApi.Fortigate(FOS_INFO[vnf]['ip'], ACC_INFO['domain'], ACC_INFO['id'], FOS_INFO[vnf]['pw']) Response = vnf_conn.ApiGet('monitor/system/interface') #print '3=',Response.status_code,'==' print '-logout-' print FortigateApi.Fortigate.Logout(vnf_conn) if Response.status_code != 200: ''' abnormal process ''' #print 'Response.status_code : [',Response.status_code,']' #print "Not valid connect to forti-os. Check the connection to [",vnf,"], please.." usage['timestamp'] = str(time.time()) usage['message'] = 'Invalid connect to forti-os' else: ''' normal process ''' data = Response.json() #print vnf, data timestamp = data['revision'] usage = data['results'] usage['timestamp'] = timestamp TOTAL_VNF_USAGE[vnf] = usage #pprint (TOTAL_VNF_USAGE) # dict JSON_VNF_USAGE = json.dumps(TOTAL_VNF_USAGE) #pprint (JSON_VNF_USAGE) #pprint (type(JSON_VNF_USAGE)) return JSON_VNF_USAGE
#!/bin/python import FortigateApi import json from pprint import pprint #fg-manager = FortigateApi.Fortigate('172.30.219.68', 'root', 'admin', 'admin') fg_fortios_01 = FortigateApi.Fortigate('172.30.219.72', 'root', 'admin', 'admin') #fg_fortios_02 = FortigateApi.Fortigate('172.30.219.73', 'root', 'admin', 'admin') fg_fortios_02 = FortigateApi.Fortigate('172.30.219.73', 'root', 'admin', '') #print (fg-manager, type(fg-manager)) #print (fg_fortios_01, type(fg_fortios_01)) #print type(fg_fortios_02) print '---A---------------' Response_1 = fg_fortios_01.ApiGet('monitor/system/interface') data_1 = Response_1.json() #print data, type(data) time = data_1['revision'] print "########", time usage = data_1['results'] pprint(usage) print '---B---------------' Response_2 = fg_fortios_02.ApiGet('monitor/system/interface')
'ip': '172.30.219.72' } } #print FOS_INFO, type(FOS_INFO) ACC_INFO = {'domain': 'root', 'id': 'admin', 'pw': 'admin'} #print ACC_INFO, type(ACC_INFO) TOTAL_VNF_USAGE = {} for vnf in FOS_INFO.keys(): #print vnf, type(vnf) #print FOS_INFO[vnf]['ip'], type(FOS_INFO[vnf]['ip']) #print ACC_INFO['domain'],ACC_INFO['id'],ACC_INFO['pw'], type(ACC_INFO['domain']), type(ACC_INFO['id']), type(ACC_INFO['pw']) vnf_conn = FortigateApi.Fortigate(FOS_INFO[vnf]['ip'], ACC_INFO['domain'], ACC_INFO['id'], ACC_INFO['pw']) Response = vnf_conn.ApiGet('monitor/system/resources/') #Response = vnf_conn.ApiGet('monitor/firewall/session/') data = Response.json() pprint(data) pprint(type(data)) #time = data['revision'] #print "########",time #usage = data['results'] #pprint (usage) #pprint (type(usage)) #usage['timestamp'] = time
import FortigateApi fgt = FortigateApi.Fortigate('192.168.123.120', 'root', 'admin', '') fgt.AddFwAddress('NEW1', '192.121.1.1/32', '', '')
import getpass import FortigateApi ip = input('enter IP: ') vdom = input('Enter VDOM: ') user = input('Enter Username: '******'Enter password: '******'-source'), member_list=source_ips[i]) else: pass dest_ip_keys = [i for i in dest_ips.keys()] for i in dest_ip_keys: for entry in dest_ips[i]: f.AddFwAddress(entry, entry) for i in dest_ip_keys: if len(dest_ips[i]) > 0: f.SetFwAddressGroup(name=(i + '-dest'), member_list=dest_ips[i]) else: