Flussonic Media Server documentation

Events API

What are the events? Anchor Anchor x2

Flussonic has a convenient and flexible system of internal event system with routing and handling. Also, we have added a powerful configuration of event routing and handling.

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

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 previous event batch.

Event configuration block supports the following configuration options:

Specification of handler. It may be http://URL, https://URL, path_to_lua_script.lua
White list of guards. 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.
Blacklist of guards. Events matched by any of except fields will not be passed to handler.
You can use value false to immitate old behaviour of pre-4.6.14 version. Better don't use it.

All other configuration options in this block will be passed to underlying sink handler. In a LUA script they can be accessed via the args table. When using http backend they passed 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"}

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

Examples with sending mail 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: