Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit 31370ec

Browse files
committed
Merge remote-tracking branch 'origin/topic/awelzel/updates-for-7.1'
* origin/topic/awelzel/updates-for-7.1: broker/cluster: Changes for auto_publish() deprecation ldap: Note about StartTLS postgresql: Some notes about the PostgreSQL analyzer signatures: Add end_of_match parameter documentation telemetry: Cleanup custom configuration hunk telemetry: Add prometheus sd_config example telemetry: Telemetry::hook() invoked on demand
2 parents 9c8b992 + 2a8c7da commit 31370ec

File tree

10 files changed

+214
-61
lines changed

10 files changed

+214
-61
lines changed

frameworks/broker.rst

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -276,19 +276,11 @@ define any event handlers for events that peers will send.
276276
:linenos:
277277
:tab-width: 4
278278

279-
There are two different ways to send events.
280-
281-
The first is to call the :zeek:see:`Broker::publish` function which you can
279+
To send an event, call the :zeek:see:`Broker::publish` function which you can
282280
supply directly with the event and its arguments or give it the return value of
283281
:zeek:see:`Broker::make_event` in case you need to send the same event/args
284282
multiple times. When publishing events like this, local event handlers for
285-
the event are not called.
286-
287-
The second option is to call the :zeek:see:`Broker::auto_publish` function where
288-
you specify a particular event that will be automatically sent to peers
289-
whenever the event is called locally via the normal event invocation syntax.
290-
When auto-publishing events, local event handlers for the event are called
291-
in addition to sending the event to any subscribed peers.
283+
the event are not called, even if a matching subscription exists.
292284

293285
.. literalinclude:: broker/events-connector.zeek
294286
:caption: events-connector.zeek
@@ -301,6 +293,20 @@ to the ``zeek/events`` topic prefix you would receive events that are published
301293
to topic names ``zeek/events/foo`` and ``zeek/events/bar`` but not
302294
``zeek/misc``.
303295

296+
297+
.. note::
298+
299+
In prior Zeek versions, :zeek:see:`Broker::auto_publish` was available to
300+
automatically send events to peers whenever the events were called locally via
301+
the normal event invocation syntax. When auto-publishing events, local
302+
event handlers for the event were called in addition to sending the
303+
event to any subscribed peers.
304+
305+
:zeek:see:`Broker::auto_publish` has been deprecated due to its
306+
`implicit nature <https://github.com/zeek/zeek/discussions/3637>`_.
307+
308+
.. deprecated:: 7.1
309+
304310
Remote Logging
305311
--------------
306312

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
redef exit_only_after_terminate = T;
22
global my_event: event(msg: string, c: count);
3-
global my_auto_event: event(msg: string, c: count);
43

54
event zeek_init()
65
{
76
Broker::peer("127.0.0.1");
8-
Broker::auto_publish("zeek/event/my_auto_event", my_auto_event);
97
}
108

119
event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string)
1210
{
1311
print "peer added", endpoint;
1412
Broker::publish("zeek/event/my_event", my_event, "hi", 0);
15-
event my_auto_event("stuff", 88);
1613
Broker::publish("zeek/event/my_event", my_event, "...", 1);
17-
event my_auto_event("more stuff", 51);
1814
local e = Broker::make_event(my_event, "bye", 2);
1915
Broker::publish("zeek/event/my_event", e);
2016
}
@@ -28,8 +24,3 @@ event my_event(msg: string, c: count)
2824
{
2925
print "got my_event", msg, c;
3026
}
31-
32-
event my_auto_event(msg: string, c: count)
33-
{
34-
print "got my_auto_event", msg, c;
35-
}

frameworks/broker/events-listener.zeek

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,3 @@ event my_event(msg: string, c: count)
2222
if ( msg_count == 5 )
2323
terminate();
2424
}
25-
26-
event my_auto_event(msg: string, c: count)
27-
{
28-
++msg_count;
29-
print "got my_auto_event", msg, c;
30-
31-
if ( msg_count == 5 )
32-
terminate();
33-
}

frameworks/cluster.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,6 @@ function to publish events, including:
334334
- Standard function to send an event to all nodes subscribed to a given
335335
topic
336336

337-
* - :zeek:see:`Broker::auto_publish`
338-
- Automatically send an otherwise generated Zeek event to any interested
339-
peers whenever it is locally dispatched.
340-
- Avoid, since it is somewhat “magical”, unless you’ve got code
341-
compartmentalization running with ``@ifdef`` directives.
342-
343337
* - :zeek:see:`Cluster::publish_hrw`
344338
- Publishes an event to a node within a pool according to
345339
Highest Random Weight (HRW) hashing strategy; see details below

frameworks/signatures.rst

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ triggered the match, ``msg`` is the string specified by the
3939
signature's event statement (``Found root!``), and data is the last
4040
piece of payload which triggered the pattern match.
4141

42+
.. versionadded:: 7.1
43+
44+
An alternative form of :zeek:id:`signature_match` has an additional ``end_of_match`` parameter.
45+
46+
.. code-block:: zeek
47+
48+
event signature_match(state: signature_state, msg: string, data: string, end_of_match: count)
49+
50+
The ``end_of_match`` parameter represents the offset into ``data`` where
51+
the match ended, or said differently, the length of the matching data within ``data``.
52+
If a signature matches across packet boundaries, ``data`` contains just the
53+
payload of the packet where a signature match triggered.
54+
4255
To turn such :zeek:id:`signature_match` events into actual alarms, you can
4356
load Zeek's :doc:`/scripts/base/frameworks/signatures/main.zeek` script.
4457
This script contains a default event handler that raises
@@ -270,17 +283,20 @@ Actions define what to do if a signature matches. Currently, there are
270283
two actions defined, ``event`` and ``enable``.
271284

272285
``event <string>``
273-
Raises a :zeek:id:`signature_match` event. The event handler has the
274-
following type:
286+
Raises a :zeek:id:`signature_match` event. The event handler has either
287+
of the following types:
275288

276289
.. code-block:: zeek
277290
278291
event signature_match(state: signature_state, msg: string, data: string)
279292
293+
event signature_match(state: signature_state, msg: string, data: string, end_of_match: count)
294+
280295
The given string is passed in as ``msg``, and data is the current
281296
part of the payload that has eventually lead to the signature
282297
match (this may be empty for signatures without content
283-
conditions).
298+
conditions). The ``end_of_match`` parameter represents the length of
299+
the matching payload in ``data``.
284300

285301
``event event_name [string]``
286302

@@ -305,6 +321,13 @@ two actions defined, ``event`` and ``enable``.
305321
306322
event found_root(state: signature_state, data: string)
307323
324+
Like the :zeek:id:`signature_match` event, custom events can have an additional
325+
``end_of_match`` parameter.
326+
327+
.. code-block:: zeek
328+
329+
event found_root(state: signature_state, data: string, end_of_match: count)
330+
308331
.. note::
309332

310333
Matches for signatures that use custom events do not appear

frameworks/telemetry.rst

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,24 @@ node's metrics port::
164164
...
165165

166166
To simplify telemetry collection from all nodes in a cluster, Zeek supports
167-
`Prometheus HTTP Service Discovery`_ on the manager node. In this approach, the
167+
`Prometheus HTTP Service Discovery`_ on the manager node. Using this approach, the
168168
endpoint ``http://<manager>:<manager-metrics-port>/services.json`` returns a
169169
JSON data structure that itemizes all metrics endpoints in the
170170
cluster. Prometheus scrapers supporting service discovery then proceed to
171-
collect telemetry from the listed endpoints in turn. See the `Prometheus Getting
172-
Started Guide`_ for additional information.
171+
collect telemetry from the listed endpoints in turn.
172+
173+
The following is an example service discovery scrape config entry within
174+
Prometheus server's ``prometheus.yml`` configuration file::
175+
176+
...
177+
scrape_configs:
178+
- job_name: zeek-discovery
179+
scrape_interval: 5s
180+
http_sd_configs:
181+
- url: http://localhost:9991/services.json
182+
refresh_interval: 10s
183+
184+
See the `Prometheus Getting Started Guide`_ for additional information.
173185

174186
.. note::
175187

@@ -184,8 +196,8 @@ Started Guide`_ for additional information.
184196

185197
If these setups aren't right for your environment, there's the possibility to
186198
redefine the options in ``local.zeek`` to something more suitable. For example,
187-
the following snippet opens an individual Prometheus port for each Zeek process
188-
(relative to the port used in ``cluster-layout.zeek``)::
199+
the following snippet selects the metrics port of each Zeek process relative
200+
to the cluster port used in ``cluster-layout.zeek``::
189201

190202
@load base/frameworks/cluster
191203

@@ -194,15 +206,6 @@ the following snippet opens an individual Prometheus port for each Zeek process
194206

195207
redef Telemetry::metrics_port = my_metrics_port;
196208

197-
As a different example, to only change the port from 9911 to 1234 on the manager
198-
process, but keep the export and import of metrics enabled, use the following snippet::
199-
200-
@load base/frameworks/cluster
201-
202-
@ifdef ( Cluster::local_node_type() == Cluster::MANAGER )
203-
redef Telemetry::metrics_port = 1234/tcp;
204-
@endif
205-
206209

207210
Examples of Metrics Application
208211
===============================
@@ -276,7 +279,7 @@ directly.
276279
:tab-width: 4
277280

278281

279-
For metrics without labels, the metric instances can also be *cached* as global
282+
For metrics without labels, the metric instances can also be cached as global
280283
variables directly. The following example counts the number of http requests.
281284

282285
.. literalinclude:: telemetry/global-http-counter.zeek
@@ -290,23 +293,39 @@ Sync
290293
^^^^
291294

292295
In case the scripting overhead of the previous approach is still too high,
293-
individual writes (or events) can be tracked in a table and then
294-
synchronized / mirrored during execution of the :zeek:see:`Telemetry::sync`
295-
hook.
296+
individual writes (or events) can be tracked in a table or global variable
297+
and then synchronized / mirrored to concrete counter and gauge instances
298+
during execution of the :zeek:see:`Telemetry::sync` hook.
296299

297300
.. literalinclude:: telemetry/log-writes-sync.zeek
298301
:caption: log-writes-sync.zeek
299302
:language: zeek
300303
:linenos:
301304
:tab-width: 4
302305

303-
For the use-case of tracking log writes, this is unlikely to be required, but
304-
for updating metrics within high frequency events that otherwise have very
305-
low processing overhead it's a valuable approach. Note, metrics will be stale
306-
up to the next :zeek:see:`Telemetry::sync_interval` using this method.
306+
For tracking log writes, this is unlikely to be required (and Zeek exposes
307+
various logging natively through the framework already), but for updating
308+
metrics within high frequency events that otherwise have low script processing
309+
overhead, it's a valuable approach.
310+
311+
312+
.. versionchanged:: 7.1
313+
314+
The :zeek:see:`Telemetry::sync` hook is invoked on-demand only. Either when
315+
one of the :zeek:see:`Telemetry::collect_metrics`
316+
or :zeek:see:`Telemetry::collect_histogram_metrics` functions is invoked, or
317+
when querying Prometheus endpoint. It's an error to call either of the
318+
collection BiFs within the :zeek:see:`Telemetry::sync` hook and results
319+
in a reporter warning.
320+
321+
322+
.. note::
307323

324+
In versions before Zeek 7.1, :zeek:see:`Telemetry::sync` was invoked on a
325+
fixed schedule, potentially resulting in stale metrics at collection time,
326+
as well as generating small runtime overhead when metrics are not collected.
308327

309-
Table sizes
328+
Table Sizes
310329
-----------
311330

312331
It can be useful to expose the size of tables as metrics, as they often

frameworks/telemetry/log-writes-sync.zeek

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ hook Log::log_stream_policy(rec: any, id: Log::ID)
1212
{
1313
++log_writes[id];
1414
}
15+
1516
hook Telemetry::sync()
1617
{
1718
for ( id, v in log_writes )

logs/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ Zeek Logs
1919
ntp
2020
smb
2121
irc
22-
rdp
2322
ldap
23+
postgresql
2424
quic
25+
rdp
2526
traceroute
2627
tunnel
2728
dpd

logs/ldap.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,36 @@ from the log.
103103
}
104104

105105

106+
StartTLS
107+
========
108+
109+
.. versionadded:: 7.0
110+
111+
Zeek's LDAP analyzer supports the
112+
`extended StartTLS <https://datatracker.ietf.org/doc/html/rfc4511#section-4.14>`_
113+
operation, handing off analysis to Zeek's TLS analyzer. The following shows an
114+
example :file:`ldap.log` entry for the StartTLS request.
115+
116+
.. code-block:: console
117+
118+
$ zeek -C LogAscii::use_json=T -r ldap-starttls.pcap
119+
$ jq < ldap.log
120+
{
121+
"ts": 1721218680.158341,
122+
"uid": "CW0qzo9A3QsrCWL4k",
123+
"id.orig_h": "127.0.0.1",
124+
"id.orig_p": 45936,
125+
"id.resp_h": "127.0.1.1",
126+
"id.resp_p": 389,
127+
"message_id": 1,
128+
"opcode": "extended",
129+
"result": "success",
130+
"object": "1.3.6.1.4.1.1466.20037 (StartTLS)"
131+
}
132+
133+
The :file:`conn.log`'s history field will contain ``ssl`` and ``ldap`` in
134+
the ``service`` field.
135+
106136
Conclusion
107137
==========
108138

0 commit comments

Comments
 (0)