![]() |
![]()
| ![]() |
![]()
NAMErwbagbuild - Create a binary Bag from non-flow data SYNOPSISrwbagbuild { --set-input=SETFILE | --bag-input=TEXTFILE } [--delimiter=C] [--proto-port-delimiter=C] [--default-count=DEFAULTCOUNT] [--key-type=FIELD_TYPE] [--counter-type=FIELD_TYPE] [{ --pmap-file=PATH | --pmap-file=MAPNAME:PATH }] [--note-add=TEXT] [--note-file-add=FILE] [--invocation-strip] [--compression-method=COMP_METHOD] [--output-path=PATH] rwbagbuild --help rwbagbuild --version DESCRIPTIONrwbagbuild builds a binary Bag file from an IPset file or from textual input. A Bag is a set of keys where each key is associated with a counter. Usually the key is some aspect of a flow record (an IP address, a port, the protocol, et cetera), and the counter is a volume (such as the number of flow records or the sum or bytes or packets) for the flow records that match that key. Either --set-input or --bag-input must be provided to specify the type and the location of the input file. To read from the standard input, specify "stdin" or "-" as the argument to the switch. Each occurrence of a unique key adds a counter value to the Bag file for that key, where the counter is the value specified by --default-count, a value specified on a line in the textual input, or a fallback value of 1. If the addition causes an overflow of the maximum counter value (18446744073709551614), the counter is set to the maximum. A message is printed to the standard error the first time an overflow condition is detected. SET INPUTWhen creating a Bag from an IPset, the count associated with each IP address is the value specified by the --default-count switch or 1 if the switch is not provided. If the --key-type is "sip-country", "dip-country", or "any-country", each IP address is mapped to its country code using the country code mapping file (see "FILES") and that key is added to the Bag file with the --default-count value. If the --key-type is "sip-pmap", "dip-pmap", or "any-ip-pmap", each IP address is mapped to a value found in the prefix map file specified in --pmap-file and that value is added to the Bag file with the --default-count value. BAG (TEXTUAL) INPUTThe textual input read from the argument to the --bag-input switch is processed a line at a time. Comments begin with a '"#"'-character and continue to the end of the line; they are stripped from each line. Any line that is blank or contains only whitespace is ignored. All other lines must contain a valid key or key-counter pair; whitespace around the key and counter is ignored. The key and counter are separated by a one-character delimiter. The default delimiter is vertical bar ('|'); use --delimiter to specify a different delimiter. Each line that is not ignored must begin with a key. The accepted formats of the key are described below. When the --default-count switch is given, rwbagtool only parses the key and ignores everything on a line to the right of the first delimiter. To re-iterate, the --default-count switch overrides any counter present on the line. If the delimiter is not present on a line, rwbagtool parses the key and adds the --default-count value (or the fallback value of 1) to the Bag for that key. When --default-count is not given, any text between the first delimiter and optional second delimiter on a line is treated as the counter. If the counter contains only whitespace, the counter for the key is incremented by 1; otherwise, the counter must be a (decimal) number from 0 to 18446744073709551614 inclusive. If a second delimiter is present, it and any text that follows it is ignored. rwbagbuild prints an error and exits when a key or counter cannot be parsed. Format of the counter The counter is any non-negative (decimal) integer value from 0 to 18446744073709551614 inclusive (the maximum is one less than the maximum unsigned 64-bit value). When writing the Bag file, keys whose counter is zero are not written to the file. Format of the Key The key is a 32-bit integer, an IP address, a CIDR block, a SiLK IPWildcard, or a pair of numbers when the key-type is a protocol-port prefix map file. For key-types that use fewer than 32-bits, rwbagbuild does not verify the validity of the key. For example, it is possible to have 257 as a key in Bag whose key-type is protocol. rwbagbuild parses specific key-types as follows:
An IP address or integer key must be expressed in one of the following formats. rwbagbuild complains if the key field contains a mixture of IPv6 addresses and integer values.
OPTIONSOption names may be abbreviated if the abbreviation is unique or is an exact match for an option. A parameter to an option may be specified as --arg=param or --arg param, though the first form is required for options that take optional parameters. The first two switches control the type of input; exactly one must be provided:
EXAMPLESIn the following examples, the dollar sign ("$") represents the shell prompt. The text after the dollar sign represents the command line. Lines have been wrapped for improved readability, and the back slash ("\") is used to indicate a wrapped line. Create a bag with IP addresses as keys from a text fileAssume the file mybag.txt contains the following lines, where each line contains an IP address, a comma as a delimiter, a count, and ends with a newline. 192.168.0.1,5 192.168.0.2,500 192.168.0.3,3 192.168.0.4,14 192.168.0.5,5 To build a bag with it: $ rwbagbuild --bag-input=mybag.txt --delimiter=, > mybag.bag Use rwbagcat(1) to view its contents: $ rwbagcat mybag.bag 192.168.0.1| 5| 192.168.0.2| 500| 192.168.0.3| 3| 192.168.0.4| 14| 192.168.0.5| 5| Create a bag with protocols as keys from a text fileTo create a Bag of protocol data from the text file myproto.txt: 1| 4| 6| 138| 17| 131| use $ rwbagbuild --key-type=proto --bag-input=myproto.txt > myproto.bag $ rwbagcat myproto.bag 1| 4| 6| 138| 17| 131| When the --key-type switch is specified, rwbagcat knows the keys should be printed as integers, and rwfileinfo(1) shows the type of the key: $ rwfileinfo --fields=bag myproto.bag myproto.bag: bag key: protocol @ 4 octets; counter: custom @ 8 octets Without the --key-type switch, rwbagbuild assumes the integers in myproto.txt represent IP addresses: $ rwbagbuild --bag-input=myproto.txt | rwbagcat 0.0.0.1| 4| 0.0.0.6| 138| 0.0.0.17| 131| Although the --key-format switch on rwbagcat may be used to choose how the keys are displayed, it is generally better to use the --key-type switch when creating the bag. $ rwbagbuild --bag-input=myproto.txt | rwbagcat
--key-format=decimal
Create a bag and override the existing counterTo ignore the counts that exist in myproto.txt and set the counts for each protocol to 1, use the --default-count switch which overrides the existing value: $ rwbagbuild --key-type=protocol --bag-input=myproto.txt \ --default-count=1 --output-path=myproto1.bag $ rwbagcat myproto1.bag 1| 1| 6| 1| 17| 1| Create a bag from multiple text filesTo create a bag from multiple text files (X.txt, Y.txt, and Z.txt), use the UNIX cat(1) utility to concatenate the files and have rwbagbuild read the combined input. To avoid creating a temporary file, feed the output of cat as the standard input to rwbagbuild. $ cat X.txt Y.txt Z.txt \ | rwbagbuild --bag-input=- --output-path=xyz.bag For each key that appears in multiple input files, rwbagbuild sums the counters for the key. Create a bag with IP addresses as keys from an IPset fileGiven the IP set myset.set, create a bag where every entry in the bag has a count of 3: $ rwbagbuild --set-input=myset.set --default-count=3 \ --out=mybag2.bag Create a bag from multiple IPset filesSuppose we have three IPset files, A.set, B.set, and C.set: $ rwsetcat A.set 10.0.0.1 10.0.0.2 $ rwsetcat B.set 10.0.0.2 10.0.0.3 $ rwsetcat C.set 10.0.0.1 10.0.0.2 10.0.0.4 We want to create a bag file from these IPset files where the count for each IP address is the number of files that IP appears in. rwbagbuild accepts a single file as an argument, so we cannot do the following: $ rwbagbuild --set-input=A.set --set-input=B.set ... # WRONG! (Even if we could repeat the --set-input switch, specifying it multiple times would be annoying if we had 300 files instead of only 3.) Since IPset files are (mathematical) sets, joining them together first with rwsettool(1) and then running rwbagbuild causes each IP address to get a count of 1: $ rwsettool --union A.set B.set C.set \ | rwbagbuild --set-input=- \ | rwbagcat 10.0.0.1| 1| 10.0.0.2| 1| 10.0.0.3| 1| 10.0.0.4| 1| When rwbagbuild is processing textual input, it sums the counters for keys that appear in the input multiple times. We can use rwsetcat(1) to convert each IPset file to text and feed that as single textual stream to rwbagbuild. Use the --cidr-blocks switch on rwsetcat to reduce the amount of input that rwbagbuild must process. This is probably the best approach to the problem: $ rwsetcat --cidr-block *.set | rwbagbuild --bag-input=- > total1.bag $ rwbagcat total1.bag 10.0.0.1| 2| 10.0.0.2| 3| 10.0.0.3| 1| 10.0.0.4| 1| A less efficient solution is to convert each IPset to a bag and then use rwbagtool(1) to add the bags together: $ for i in *.set ; do rwbagbuild --set-input=$i --output-path=/tmp/$i.bag ; done $ rwbagtool --add /tmp/*.set.bag > total2.bag $ rm /tmp/*.set.bag There is no need to create a bag file for each IPset; we can get by with only two bag files, the final bag file, total3.bag, and a temporary file, tmp.bag. We initialize total3.bag to an empty bag. As we loop over each IPset, rwbagbuild converts the IPset to a bag on its standard output, rwbagtool creates tmp.bag by adding its standard input to total3.bag, and we rename tmp.bag to total3.bag: $ rwbagbuild --bag-input=/dev/null --output-path=total3.bag $ for i in *.set ; do rwbagbuild --set-input=$i \ | rwbagtool --output-path=tmp.bag --add total3.bag stdin ; /bin/mv tmp.bag total3.bag ; done $ rwbagcat total3.bag 10.0.0.1| 2| 10.0.0.2| 3| 10.0.0.3| 1| 10.0.0.4| 1| Create a bag where the key is the country codeAs of SiLK 3.12.0, a Bag file may contain a country code as its key. In rwbagbuild, specify the --key-type as "sip-country", "dip-country", or "any-country". That key-type works with either textual input or IPset input. The form of the textual input when mapping an IP address to a country code is identical to that when building an ordinary bag. $ rwbagbuild --bag-input=mybag.txt --delimiter=, \ --key-type=any-country --output-path=scc1.bag $ rwbagcat scc1.bag --| 527| $ rwbagbuild --set-input=A.set --key-type=any-country \ --output-path=scc2.bag $ rwbagcat scc2.bag --| 2| Create a bag using a prefix map value as the keyrwbagbuild and rwbag(1) can use a prefix map file as the key in a Bag file as of SiLK 3.12.0. Use the --pmap-file switch to specify the prefix map file, and specify the --key-type using one of the types that end in "-pmap". For a prefix map that maps by IP addresses, use a key-type of "sip-pmap", "dip-pmap", or "any-ip-pmap". The input may be an IPset or text. The form of the textual input is the same as for a normal bag file. $ rwbagbuild --set-input=A.set --key-type=sip-pmap \ --pmap-file=ip-map.pmap --output=test1.bag $ rwbagbuild --bag-input=mybag.txt --delimiter=, \ --key-type=sip-pmap --pmap-file=ip-map.pmap \ --output-path=test2.bag The prefix map file is not stored as part of the Bag, so you must provide the name of the prefix map when running rwbagcat(1). $ rwbagcat --pmap-file=ip-map.pmap test2.bag internal| 527| For a prefix map file that maps by protocol-port pairs, the textual input must contain either three column (protocol, port, counter) or two columns (protocol and port) which uses the --default-counter. $ cat proto-port-count.txt 6| 25| 800| 6| 80| 5642| 6| 22 $ rwbagbuild --key-type=sport-pmap \ --bag-input=proto-port-count.txt \ --pmap-file=proto-port-map.pmap \ --output-path=service.bag $ rwbagcat --pmap-file=port-map.pmap service.bag TCP/SSH| 1| TCP/SMTP| 800| TCP/HTTP| 5642| Delimiter examplesA single value followed by an optional delimiter is treated as a key. The counter for those keys is set to 1. A delimiter may follow the count, and any text after that delimiter is ignored. When the counter is 0, the key is not inserted into the Bag. $ cat sport.txt 0 1| 2|3 4|5| 6|7|8| 9|10||||| 11|0 $ rwbagbuild --bag-input=sport.txt --key-type=sport \ | rwbagcat 0| 1| 1| 1| 2| 3| 4| 5| 6| 7| 9| 10| The --default-counter switch overrides the count. $ rwbagbuild --bag-input=sport.txt --key-type=sport --default-count=1 \ | rwbagcat 0| 1| 1| 1| 2| 1| 4| 1| 6| 1| 9| 1| 11| 1| In fact, the --default-counter switch causes rwbagbuild to ignore all text after the delimiter that follows the key. $ echo '12|13 14' | rwbagbuild --bag-input=- --output=/dev/null rwbagbuild: Error parsing line 1: Extra text after count rwbagbuild: Error creating bag from text bag $ echo '12|13 14' | rwbagbuild --bag-input=- --default-count=1 \ | rwbagcat --key-format=decimal 12| 1| ENVIRONMENT
FILES
SEE ALSOrwbag(1), rwbagcat(1), rwbagtool(1), rwfileinfo(1), rwpmapbuild(1), rwset(1), rwsetbuild(1), rwsetcat(1), rwsettool(1), ccfilter(3), silk(7), zlib(3), cat(1) BUGSrwbagbuild should verify the key's value is within the allowed range for the specified --key-type. rwbagbuild should accept non-numeric values for some fields, such as times and TCP flags. The --default-count switch is poorly named.
|