{"id":628,"date":"2017-11-12T20:46:07","date_gmt":"2017-11-12T20:46:07","guid":{"rendered":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=628"},"modified":"2017-12-08T10:50:29","modified_gmt":"2017-12-08T10:50:29","slug":"the-generic-module","status":"publish","type":"page","link":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=628","title":{"rendered":"The generic module"},"content":{"rendered":"<p>The <code>generic<\/code> module is a <a title=\"Dissection modules\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=131\">dissection module<\/a>: its purpose is to take an Orchids event, parse one of its text fields and return a refined Orchids events, with additional fields. Typically, the <code>generic<\/code> module is meant to dissect text coming from the <a title=\"The textfile module\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=157\"><code>syslog<\/code><\/a> module.<\/p>\n<p>The <code>generic<\/code> module is however very special.\u00a0 In a sense, it is a <em>meta<\/em>-module, one that allows you to define new, so-called <em>virtual<\/em> modules, whose parsing methods are defined by regular expressions.<\/p>\n<p>We explain how that works on an example.\u00a0 The <a title=\"The textfile module\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=157\"><code>syslog<\/code><\/a> module may have to dissect messages such as:<\/p>\n<pre>Jan 27 11:32:06 laramie dhclient: DHCPREQUEST on eth0 to 192.168.30.1 port 67\r\n<\/pre>\n<p>In that case, it will produce a last field <code>.syslog.msg<\/code> equal to the block of text <code>\"DHCPREQUEST on eth0 to 192.168.30.1 port 67\"<\/code>. We would like to dissect that further.<br \/>\nThe <code>generic<\/code> module allows you to do that, based on regular expressions.<\/p>\n<p>First, one should plug the <code>generic<\/code> module so that it dissects that kind of message. \u00a0 The <code>generic<\/code> module defines a so-called <em>virtual module<\/em> called\u00a0<code>dhclient<\/code> and which does just that. \u00a0We shall describe it below. \u00a0The plugging is done by\u00a0the following line in\u00a0<a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=145\"><code>$OCONF\/orchids-inputs.conf<\/code><\/a>, instructing Orchids to let the\u00a0<code>dhclient<\/code> virtual module parse the last field,\u00a0<code>.syslog.msg<\/code> (in the example, <code>\"DHCPREQUEST on eth0 to 192.168.30.1 port 67\"<\/code>), provided by the\u00a0<code>syslog<\/code>\u00a0module, on the condition that\u00a0its next-to-last field,\u00a0<code>.syslog.prog<\/code>, is equal to <code>\"dhclient\"<\/code> (which is the case in our example).<\/p>\n<pre>DISSECT dhclient syslog \"dhclient\"<\/pre>\n<p>&nbsp;<\/p>\n<h3>Configuration options<\/h3>\n<p><code>&lt;module generic&gt;<\/code><\/p>\n<p>contains a list of declarations of <em>virtual modules<\/em>.\u00a0 Virtual modules work exactly like actual modules, except you do not need to load any shared library at start-up time to start them.\u00a0 Instead, virtual modules work by parsing sets of regular expressions.<\/p>\n<p>We describe the standard <code>dhclient<\/code> virtual module, which is part of the standard configuration file for the <code>generic<\/code> module, <code>$OCONF\/conf.d\/12_mod_generic.conf<\/code>.<\/p>\n<p>That module is meant to parse the <code>syslog<\/code>\u00a0messages produced by the\u00a0<code>dhclient<\/code>\u00a0program. \u00a0That means that you should see<\/p>\n<pre>    &lt;vmod dhclient&gt;\r\n<\/pre>\n<p>This declares a new virtual module with name <code>dhclient<\/code>. Every virtual module consists of a list of <code>&lt;fieldmatch \u27e8<\/code>regular-expression\u27e9<code>&gt;<\/code> &#8230; <code>&lt;\/fieldmatch&gt;<\/code> declarations.\u00a0 Here are some of them, and we start with the first one. The order is important: the first matching regular expression is the one that is considered to parse the given block of text.<\/p>\n<pre>      &lt;fieldmatch \"^(bound) to ([0-9.]+) -- renewal in ([0-9]+) seconds\\\\.\"&gt;\r\n        str_field action 1 Action\r\n        ipv4_field ip 2 Ip address\r\n        int_field renewal 3 Renewal time\r\n      &lt;\/fieldmatch&gt;\r\n<\/pre>\n<p>Here the regular expression matches any message starting with <code>\"bound to \"<\/code> followed by an IP address, followed by <code>\" -- renewal in \"<\/code> , followed by a number, followed by <code>\" seconds.\"<\/code> (and possibly other text: if we wanted to match that exactly, we woud add &#8220;<code>$\"<\/code> at the end of the regular expression, to match the end of text).<\/p>\n<p>The parenthesized subexpressions, <code>(bound)<\/code>, <code>([0-9.]+)<\/code>, and <code>([0-9]+)<\/code> are recognized as subexpressions 1, 2, and 3 respectively, and converted to types <code>str<\/code>,\u00a0 <code>ipv4<\/code>, and <code>int<\/code>, respectively.\u00a0 The possible field declarations are of the form:<\/p>\n<ul>\n<li>\u27e8<code>type<\/code>\u27e9<code>_field<\/code> \u27e8field name\u27e9 \u27e8field number\u27e9 \u27e8description\u27e9<\/li>\n<\/ul>\n<p>The \u27e8field name\u27e9 is any valid Orchids identifier, the \u27e8field number\u27e9 is any non-negative integer, and the \u27e8description\u27e9 consists of the whole remainder of the line.\u00a0 The allowed \u27e8<code>type<\/code>\u27e9s are the basic types <code>str<\/code>,\u00a0 <code>bstr<\/code>, <code>int<\/code>, <code>uint<\/code>, <code>ipv4<\/code>,\u00a0 <code>ipv6<\/code>,\u00a0 <code>float<\/code>,\u00a0 <code>ctime<\/code>,\u00a0 <code>timeval<\/code>,\u00a0 <code>snmpoid<\/code><code><\/code>.\u00a0 For each, the <code>generic<\/code> module will automatically do the required conversion.\u00a0 Hence, the above <code>&lt;fieldmatch<\/code><code>&gt;<\/code> declaration will declare the following Orchids fields:<\/p>\n<table style=\"border: solid 1px black;\">\n<tbody>\n<tr style=\"background-color: lightsteelblue;\">\n<th>Field<\/th>\n<th><a title=\"Types\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">Type<\/a><\/th>\n<th><a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=719\">Mono<\/a>?<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/tbody>\n<tbody>\n<tr style=\"background-color: lightgrey;\">\n<td><code>.dhclient.action<\/code><\/td>\n<td><code>str<\/code><\/td>\n<td><\/td>\n<td>Action<\/td>\n<\/tr>\n<tr style=\"background-color: white;\">\n<td><code>.dhclient.ip<\/code><\/td>\n<td><code>ipv4<\/code><\/td>\n<td><\/td>\n<td>Ip address<\/td>\n<\/tr>\n<tr style=\"background-color: lightgrey;\">\n<td><code>.dhclient.renewal<\/code><\/td>\n<td><code>int<\/code><\/td>\n<td><\/td>\n<td>Renewal time<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>(No, there is no way to specify any monotony in virtual modules yet, sorry.)<\/p>\n<p>You will have noticed that this first regular expression does not match the block of text of our example, <code>\"DHCPREQUEST on eth0 to 192.168.30.1 port 67\"<\/code>.\u00a0 That is matched by the 5th <code>&lt;fieldmatch<\/code><code>&gt;<\/code> declaration (among 6) in the virtual module:<\/p>\n<pre>      &lt;fieldmatch \"^(DHCPREQUEST) on ([^ ]+) to ([0-9.]+) port ([0-9]+)$\"&gt;\r\n        str_field method 1\r\n        str_field interface 2\r\n        ipv4_field dst_ip 3\u00a0 Destination IP address\r\n        int_field port 4\r\n      &lt;\/fieldmatch&gt;\r\n<\/pre>\n<p>That declaration declares the following fields:<\/p>\n<table style=\"border: solid 1px black;\">\n<tbody>\n<tr style=\"background-color: lightsteelblue;\">\n<th>Field<\/th>\n<th><a title=\"Types\" href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=98\">Type<\/a><\/th>\n<th><a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=719\">Mono<\/a>?<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/tbody>\n<tbody>\n<tr style=\"background-color: lightgrey;\">\n<td><code>.dhclient.method<\/code><\/td>\n<td><code>str<\/code><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr style=\"background-color: white;\">\n<td><code>.dhclient.interface<\/code><\/td>\n<td><code>str<\/code><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr style=\"background-color: lightgrey;\">\n<td><code>.dhclient.dst_ip<\/code><\/td>\n<td><code>ipv4<\/code><\/td>\n<td><\/td>\n<td>Destination IP address<\/td>\n<\/tr>\n<tr style=\"background-color: white;\">\n<td><code>.dhclient.port<\/code><\/td>\n<td><code>int<\/code><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>so that, on our example, we will obtain:<\/p>\n<ul>\n<li><code>.dhclient.method<\/code> = <code>\"DHCPREQUEST\"<\/code><\/li>\n<li><code>.dhclient.interface<\/code> = <code>\"eth0\"<\/code><\/li>\n<li><code>.dhclient.dst_ip<\/code> = <code>192.168.30.1<\/code> (as an ipv4 address)<\/li>\n<li><code>.dhclient.port<\/code> = <code>67<\/code><\/li>\n<\/ul>\n<p>After all those <code>&lt;fieldmatch<\/code><code>&gt;<\/code> declarations, we end with:<\/p>\n<p><code>\u00a0\u00a0\u00a0 &lt;\/vmod&gt;<\/code><\/p>\n<p>to end the declaration of the virtual module. That finishes the declaration of our example virtual module <code>dhclient<\/code>. There are many others in\u00a0<code>$OCONF\/conf.d\/12_mod_generic.conf<\/code>.<\/p>\n<p><code>&lt;\/module&gt;<\/code><\/p>\n<h3>Fields<\/h3>\n<p>Varying.\u00a0 See <code>$OCONF\/conf.d\/12_mod_generic.conf<\/code>, and the previous section for examples.\u00a0 The virtual modules are all declared dissectable, in case one would want to further dissect one of the fields they produce.<\/p>\n<h2>Obsolescent features<\/h2>\n<p>In previous versions of Orchids, one could see all declarations of virtual modules enclosed in <code>&lt;hook&gt;<\/code> &#8230; <code>&lt;\/hook&gt;<\/code> declarations, for example:<\/p>\n<pre>\u00a0 &lt;hook syslog \"dhclient\"&gt;\r\n<\/pre>\n<p>The <code>hook<\/code> command said that any event produced by the <code>syslog<\/code> module whose next-to-last field <code>.syslog.prog<\/code> field is equal to <code>\"dhclient\"<\/code> (as in our example) should be parsed by the following virtual module.<\/p>\n<p>This still works, for the time being, but contradicts the principle that all the plumbing of sources and dissectors should be described in the sole file <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=145\"><code>orchids-inputs.conf<\/code><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The generic module is a dissection module: its purpose is to take an Orchids event, parse one of its text fields and return a refined Orchids events, with additional fields. Typically, the generic module is meant to dissect text coming from the syslog module. The generic module is however very special.\u00a0 In a sense, it &hellip; <a href=\"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/?page_id=628\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">The generic module<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-628","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=628"}],"version-history":[{"count":9,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/628\/revisions"}],"predecessor-version":[{"id":727,"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=\/wp\/v2\/pages\/628\/revisions\/727"}],"wp:attachment":[{"href":"https:\/\/projects.lsv.ens-paris-saclay.fr\/orchidsdoc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}