示例#1
0
# for exporters we need to create internal and external templates

session.add_internal_template(template_id=999, template=tmpl)
session.add_external_template(template_id=999, template=tmpl)
session.add_internal_template(template_id=1000, template=sub_tmpl)
session.add_external_template(template_id=1000, template=sub_tmpl)
session.add_internal_template(template_id=1001, template=stl_tmpl)
session.add_external_template(template_id=1001, template=stl_tmpl)

# create the record to fill to export
# we can just give it the template since we don't have duplicate elements
rec = pyfixbuf.Record(infomodel, tmpl)

#create the buffer for exporter
buf = pyfixbuf.Buffer(rec)

# make the buffer an export buffer
buf.init_export(session, exporter)

# set the internal template on the buffer
buf.set_internal_template(999)

# export the templates to the file
session.export_templates()

# now set the export template
buf.set_export_template(999)

# create a rec for our sub template multilist
# we use 2 basicLists so add elements separately
# add the appropriate templates to each session
session.add_internal_template(tmpl, template_id=876)

session.add_internal_template(statstmpl, template_id=900)

exsession.add_template(exportertmpl, template_id=987)

# create the input record from the input template since there are no duplicate elements
rec = pyfixbuf.Record(infomodel, tmpl)

# we can create the export rec from the export template since there are no duplicate elements
exportrec = pyfixbuf.Record(infomodel, exportertmpl)

# create buffers for input and export
buf = pyfixbuf.Buffer(rec)
buf.init_collection(session, collector)

exbuf = pyfixbuf.Buffer(exportrec)
exbuf.init_export(exsession, exporter)

# set the internal template on the input buffer
buf.set_internal_template(876)

# export the templates
exsession.export_templates()

# set the internal and external templates on the export buffer
exbuf.set_internal_template(987)
exbuf.set_export_template(987)
# Create a session

session = p.Session(infomodel)

# Add your template to the session

session.add_internal_template(tmpl, 999)

# create a Record for each template or subtemplate to give the buffer

rec = p.Record(infomodel, tmpl)

# Create a buffer to read from

buf = p.Buffer(rec)

# Add the session and collector the buffer

buf.init_collection(session, collector)

# Set your internal template to the data template

buf.set_internal_template(999)

# open our output file

outFile = open(sys.argv[2], "w")

flowcount = 0
示例#4
0
# Add your template to the session

session.add_internal_template(tmpl, 999)

# Add the Stats Template

session.add_internal_template(stats_tmpl, 911)

# create a Record for the main template and stats template

rec = p.Record(infomodel, tmpl)

statsrec = p.Record(infomodel, stats_tmpl)

# Create a buffer to read from
buf = p.Buffer()

# Add the session and collector the buffer

buf.init_collection(session, collector)

# Set your internal template to the data template

buf.set_internal_template(999)

# open our output file

outFile = open(sys.argv[2], "w")

flowcount = 0
# add YAF's HTTP IPFIX elements for a sub template
infomodel.add_element_list(pyfixbuf.YAF_HTTP_LIST)

# create the collector
collector = pyfixbuf.Collector()

#create the IPFIX file to read from
collector.init_file(sys.argv[1])

#create the session
session = pyfixbuf.Session(infomodel)

#create the buffer for the collector, set auto to True to
#automatically generate templates
buf = pyfixbuf.Buffer(auto=True)

# make the buffer an export buffer
buf.init_collection(session, collector)

# set auto insert on buffer in case we receive any Info Element Options Recs
buf.auto_insert()

if (len(sys.argv) > 2):
    outFile = open(sys.argv[2], "w")
else:
    outFile = sys.stdout

flowcount = 0

dontprintlist = ["subTemplateMultiList", "subTemplateList", "paddingOctets"]