Flussonic Media Server documentation

Events API

Events in Flussonic Anchor Anchor x2

Flussonic has a system of internal events with routing and handling, and convenient and flexible tools to configure it.

Events are initiated in different parts of the system and can be used in different scenarios.

To configure event-related settings, add into the Flussonic configuration file a directive notify and the option sink where you define the receiver of events:

  • To use your custom handler, specify the path to the handler in sink.
  • To write event to a log file, specify the path to the file in sink.

Then use various options to filter events before they come to a handler or log.

On this page:

Configuring event logging Anchor Anchor x2

In addition to the main log, Flussonic allows you to create as many log files as you need and to log events according to your filtering settings.

To write events to a custom file, add the notify directive and use the sink log:// option to specify the file, for example:

notify log_name {
    sink log://log/crash.log;
    verbose debug;


  • log_name — just the setting's name. It's good to give it a meaningful name.
  • sink — the file where event information is logged.
  • verbose — the level of logging according to event importance. Can be debug (the most detailed logging), info, or alert (only serious events).

Excluding events from logs

To exclude some types of events, use the except option. For example, the following configuration will not write to the log all events concerning streams (and write other events, such as Flussonic server events):

notify log_name {
    sink log://log/crash.log;
    except media=*;
    verbose debug;

Configuring event handlers Anchor Anchor x2

Each event handler can be declared in config:

notify handler_name {
    sink http://backend.local/notify.php;

Such configuration creates an event handler with the name handler_name and it sends ALL events to HTTP URL http://backend.local/notify.php.

In this configuration all Flussonic events will be send in JSON format as a list of objects. On a high loaded system it can generate enormous amount of events most of which are not required.

We can reduce event traffic by better configuration:

notify handler_name {
    sink http://backend.local/notify.php;
    only event=stream_started,stream_stopped,source_ready,source_lost;

This configuration will send only four specific events to this handler.

Event handler calls are synchronous: an event will not be sent to the handler if the handler hasn't handled the previous event batch.

The event configuration block supports the following configuration options:

The specification of the handler. It can be http://URL, https://URL, path_to_lua_script.lua
The white list of limitations. You can specify several key=value or key=value1,value2 options on each only line. You can filter events by their event field, by media field or any other like country or ip. Usually it is event and media. You should read more explicit explanation of this only behaviour.
The black list of limitations. Events matched by any of except fields will not be passed to handler.
You can use false to imitate the old behaviour of pre-4.6.14 versions. But we don't recommend using it.

All other configuration options in this block will be passed to the specified sink handler. In a LUA script they can be accessed via the args table. When using HTTP backend you pass them along with other parameters.

Here goes some extra configuration options:

You can specify signature key for HTTP event sink. When Flussonic will prepare HTTP POST with JSON body, it will add this secret key to then end of body, make SHA1 hash from it and add it in hex form as a header X-Signature. This can be used for verifying that it is a Flussonic posting events.

Event filtering Anchor Anchor x2

You can pre-filter events before passing them to handlers. It is very important mechanism, try to use it, because it reduce load on your event handler. Each event is prefiltered in the emitter thread before being passed to handler.

Here goes rules for filtering:

  • if ANY except directive fully matches event, it is dropped and not sent to handler;
  • if there are no only directives, events are sent to handler;
  • if there are only directive then event is passed to handler if ANY directive fully matches the event.

Full match of event and directive means that ALL key=value pairs in directive are equal to values in event. If directive has key=value1,value2,value3 pair, then it means that event MUST have ANY of these values to match this directive.


  • only event=stream_started; matches {event: "stream_started", media: "cbc"}
  • only event=stream_started,stream_stopped; matches {event: "stream_started", media: "cbc"}
  • only event=stream_started,stream_stopped media=tnt; NOT matches {event: "stream_started", media: "cbc"}
  • only event=stream_started media=cbc group=news; NOT matches {event: "stream_started", media: "cbc"}

The list of available events Anchor Anchor x2

Here is a list of known events:

sent when server has started
flussonic is listening on some port for protocol
flussonic has failed to listen on port
config has reloaded
session was opened
session was closed
file was opened
file was closed
stream has started
stream is told to stop via API
stream has stopped
stream has reloaded configuration
motion event has appeared on stream (for IP cameras)
motion event has been closed on stream
stream source has received first frames
stream media info has changed
stream source considered to be lost and needs restarting
stream source has been switched to another
A stream's source has stopped sending frames (but it is not restarted yet)
A stream's source has resumed sending frames
backup file started playing while source is lost
publishing to stream has started
publishing to stream has finished and you can get lot of valuable information from this event
stream has started pusher to another source
new jpeg thumbnail has been generated
new DVR fragment has been recorded on disk
old fragments has been deleted from DVR
new hour blob has been opened for recording video to DVR
error in stream: invalid timestamps are coming or too low FPS
stream had to resync timestamps. May be indication of stream errors if happens too often.
stream is refusing to read from current source and decided to completely restart
DVR replication started
DVR replicating hour
DVR hour done
DVR replication in progress
DVR replication done

Examples of configuring email notifications Anchor Anchor x2

Let's learn what you can do with events system. For example, let's receive email notifications if a stream is down.

The simplest configuration will be:

notify no_video {
    only event=stream_stopped,source_lost;
    sink /etc/flussonic/no_video.lua;
    from flussonic@streamer1.my.cdn;
    to admin@my.cdn;
    via smtp://;

This configuration is enough unless you want to filter streams here.

What no_video.lua can do:

body = "Source lost on following streams: \n"

for _, event in pairs(events) do
    body = body.."  "..event.media.."\n"

mail.send({from = args.from, to = args.to, subject = "Source lost", body = body})

You need to install the Sendmail utility to send mail correctly:

apt-get install sendmail

Make sure that Sendmail listens on the port specified in the configuration file:

netstat -lntp
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name          
tcp        0      0 *               LISTEN      3507/sendmail

Specify REAL domain name as the hostname of the server: