SlideShare a Scribd company logo
3
Most read
7
Most read
9
Most read
Writing external output plugins
for rsyslog
Rainer Gerhards
Output plugins in rsyslog
• Output plugins permit to connect to a variety of log
destinations
• Pre-v8, plugins needed to be internal modules
▫ Loaded into rsyslog process space
▫ Must be written in C (or link to it)
▫ Deeply tied into rsyslog infrastructure

• with v8, we officially support external plugins
▫ Written in any language (Python, Perl, Java, ...)
▫ Have their own process
▫ Relatively de-coupled
Rainer Gerhards, http://blog.gerhards.net
Interface Overview
process border

Internal plugin
rsyslog
core
engine

perl plugin
external plugin
connector
python plugin

Rainer Gerhards, http://blog.gerhards.net
External Interface Design Goals
• Keep it stupid simple
▫ Must support almost any language
▫ Dumb easy to use even for novice programmer
▫ Do not require explicit threading

• Speed is NOT the most important goal
▫ Don't make it unnecessarily slow
▫ Many real-world log destinations are slow in any case
(like when you connect via http...)
▫ Focus on “enable to build solution”
▫ If necessary, conversion to internal module can be
done later
Rainer Gerhards, http://blog.gerhards.net
Interface Details: communication
• use pipes
• stdin
▫ one message per line
▫ format can be customized via rsyslog templates
▫ multi-line messags via JSON

• stdout/stderr
▫ Must NOT be written in initial version
▫ Will later convey back state information via plain text
(e.g. “ERR”, “ERRMSG:xxx”, ...)

• JSON as input format is recommended
Rainer Gerhards, http://blog.gerhards.net
Interface Details: Threading
• Do NOT care about threading
• Write app according to single-thread paradigm
• rsyslog will spawn multiple instances of your plugin
if there is need to do so
▫
▫
▫
▫

Happens based on config in busy cases
Works well in most cases (e.g. http connects)
Can be disabled if necessary
If your program can run in multiple ter-minal
sessions concurrently, it can also be run as
multiple rsyslog action instances.
Rainer Gerhards, http://blog.gerhards.net
Startup & Termination
•
•
•
•
•
•

rsyslog will startup the plugin automatically
Plugin needs to read stdin until EOF
Do NOT terminate before EOF is reached
On EOF, cleanup and terminate
If the plugin dies, rsyslog restarts a new instance
Some signals (like sigint) are blocked and should
remain so

Rainer Gerhards, http://blog.gerhards.net
Skeletons
• The rsyslog project provides sample plugin
skeletons
• Available in ./plugins/external/skeletons
• These contain
▫ the necessary plumbing
▫ often a kind of abstraction layer to make writing
plugins even easier
▫ often performance-enhancement features

• Can simply be copied to create your own plugins,
don't care about the (minimal) plumbing!
Rainer Gerhards, http://blog.gerhards.net
Example: Python Skeleton

• Handles all interface plumbing
• Uses “eventHandlers” to call the acutal app coding
• Is used as a basis, for example, for the Solr output
plugin
• Available at
https://github.com/rsyslog/rsyslog/blob/master/plugin

Rainer Gerhards, http://blog.gerhards.net
onInit() Handler
• Called when the plugin is initially loaded
• Ready outbound connections, files, etc...

def onInit():
""" Do everything that is needed to initialize processing
(e.g. open files, create handles, connect to systems...)
"""
global outfile
outfile = open("/tmp/logfile", "w")

Rainer Gerhards, http://blog.gerhards.net
onReceive()
• Called when new messages arrive
• Receives one or more message via Python list object
--> e.g. place them into one transaction, HTTP
request, ...
def onReceive(msgs):
"""This is the entry point where actual work needs to be done. It receives
a list with all messages pulled from rsyslog. The list is of variable
length, but contains all messages that are currently available. It is
suggest NOT to use any further buffering, as we do not know when the
next message will arrive. It may be in a nanosecond from now, but it
may also be in three hours...

"""
global outfile
for msg in msgs:
outfile.write(msg)
Rainer Gerhards, http://blog.gerhards.net
onExit()
• Called immediately before the plugin terminates
• Gurantees that no more messages arrive
• Used to cleanup connections, write some final
records, ...

def onExit():
""" Do everything that is needed to finish processing (e.g.
close files, handles, disconnect from systems...). This is
being called immediately before exiting.
"""
global outfile
outfile.close()
Rainer Gerhards, http://blog.gerhards.net
Call to Action
• If you need to send logs to a destination that is not
yet supported, you can quickly write an external
plugin – in any language you know!
• Writing rsyslog plugins is easy
▫ If there is already a skeleton for your language, copy it
and add your app-specific code
▫ If not ... no problem, the interface is dumb easy

If you can write a script that reads stdin and does
something useful with it, you can also write a
rsyslog plugin!
Rainer Gerhards, http://blog.gerhards.net

More Related Content

PPTX
Windows Registry Forensics - Artifacts
PPT
Ch 3 event driven programming
PPTX
ACTIVE SERVER PAGES BY SAIKIRAN PANJALA
PPTX
Introduction to php
PPT
ODP
Android security in depth
PDF
WEB I - 01 - Introduction to Web Development
PPTX
Operators php
Windows Registry Forensics - Artifacts
Ch 3 event driven programming
ACTIVE SERVER PAGES BY SAIKIRAN PANJALA
Introduction to php
Android security in depth
WEB I - 01 - Introduction to Web Development
Operators php

What's hot (20)

PPTX
Basic syntax : Algorithm,Flow chart
PPT
Presentation on telnet
PDF
Ruby on Rails Presentation
PPT
Configuration DHCP
PPTX
Python final presentation kirti ppt1
PPT
Introduction to PHP
PDF
Fundamentals of c language
PPT
Intro To Programming Concepts
PPTX
Introduction to java
PPT
JDBC Tutorial
PPT
Introduction to JavaScript (1).ppt
PPTX
System Analysis And Design
PPTX
Boolean logic
PDF
Basic Crud In Django
PPT
PPT
Web servers
PPTX
Python in 30 minutes!
PPTX
Sessions in php
Basic syntax : Algorithm,Flow chart
Presentation on telnet
Ruby on Rails Presentation
Configuration DHCP
Python final presentation kirti ppt1
Introduction to PHP
Fundamentals of c language
Intro To Programming Concepts
Introduction to java
JDBC Tutorial
Introduction to JavaScript (1).ppt
System Analysis And Design
Boolean logic
Basic Crud In Django
Web servers
Python in 30 minutes!
Sessions in php
Ad

Similar to Writing External Rsyslog Plugins (20)

ODP
RSYSLOG v8 improvements and how to write plugins in any language.
ODP
Fedora Developer's Conference 2014 Talk
ODP
rsyslog meets docker
PPTX
introduction to node.js
PDF
Ansible - A 'crowd' introduction
PDF
linux_internals_2.3 (1).pdf àaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
PDF
My "Perfect" Toolchain Setup for Grails Projects
PDF
Techtalks: taking docker to production
PDF
JOSA TechTalk: Taking Docker to Production
ODP
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
ODP
IT Operations for Web Developers
PDF
Demo 0.9.4
ODP
Rsyslog log normalization
PDF
Deep Postgres Extensions in Rust | PGCon 2019 | Jeff Davis
PPT
Logstash
PPTX
Warden @ Meet magento Romania 2021
PPTX
concept of server-side JavaScript / JS Framework: NODEJS
PDF
Node.js 101 with Rami Sayar
PDF
Fluentd v1.0 in a nutshell
PPTX
Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015
RSYSLOG v8 improvements and how to write plugins in any language.
Fedora Developer's Conference 2014 Talk
rsyslog meets docker
introduction to node.js
Ansible - A 'crowd' introduction
linux_internals_2.3 (1).pdf àaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
My "Perfect" Toolchain Setup for Grails Projects
Techtalks: taking docker to production
JOSA TechTalk: Taking Docker to Production
Nagios Conference 2014 - Spenser Reinhardt - Detecting Security Breaches With...
IT Operations for Web Developers
Demo 0.9.4
Rsyslog log normalization
Deep Postgres Extensions in Rust | PGCon 2019 | Jeff Davis
Logstash
Warden @ Meet magento Romania 2021
concept of server-side JavaScript / JS Framework: NODEJS
Node.js 101 with Rami Sayar
Fluentd v1.0 in a nutshell
Devoops: DoJ Annual Cybersecurity Training Symposium Edition 2015
Ad

More from Rainer Gerhards (11)

PDF
Sicherheit im Internet - Wie kann man sich schützen?
PPTX
Rsyslog version naming (v8.6.0+)
PPTX
Using Wildcards with rsyslog's File Monitor imfile
ODP
The rsyslog v8 engine (developer's view)
PPT
Wetterbeobachtung - Ein Vortrag für die Grundschule
ODP
Rsyslog vs Systemd Journal Presentation
PDF
Rsyslog vs Systemd Journal (Paper)
PDF
CEE Log Integrity and the "Counterpane Paper"
SXW
State of syslog (2005)
PDF
Status of syslog as of 2005
PPT
LogFile Auswertung (log analysis)
Sicherheit im Internet - Wie kann man sich schützen?
Rsyslog version naming (v8.6.0+)
Using Wildcards with rsyslog's File Monitor imfile
The rsyslog v8 engine (developer's view)
Wetterbeobachtung - Ein Vortrag für die Grundschule
Rsyslog vs Systemd Journal Presentation
Rsyslog vs Systemd Journal (Paper)
CEE Log Integrity and the "Counterpane Paper"
State of syslog (2005)
Status of syslog as of 2005
LogFile Auswertung (log analysis)

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Approach and Philosophy of On baking technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Big Data Technologies - Introduction.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
“AI and Expert System Decision Support & Business Intelligence Systems”
Digital-Transformation-Roadmap-for-Companies.pptx
Approach and Philosophy of On baking technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Per capita expenditure prediction using model stacking based on satellite ima...
Reach Out and Touch Someone: Haptics and Empathic Computing
MYSQL Presentation for SQL database connectivity
20250228 LYD VKU AI Blended-Learning.pptx
Unlocking AI with Model Context Protocol (MCP)
Building Integrated photovoltaic BIPV_UPV.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Understanding_Digital_Forensics_Presentation.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Empathic Computing: Creating Shared Understanding
Big Data Technologies - Introduction.pptx
Encapsulation theory and applications.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Writing External Rsyslog Plugins

  • 1. Writing external output plugins for rsyslog Rainer Gerhards
  • 2. Output plugins in rsyslog • Output plugins permit to connect to a variety of log destinations • Pre-v8, plugins needed to be internal modules ▫ Loaded into rsyslog process space ▫ Must be written in C (or link to it) ▫ Deeply tied into rsyslog infrastructure • with v8, we officially support external plugins ▫ Written in any language (Python, Perl, Java, ...) ▫ Have their own process ▫ Relatively de-coupled Rainer Gerhards, http://blog.gerhards.net
  • 3. Interface Overview process border Internal plugin rsyslog core engine perl plugin external plugin connector python plugin Rainer Gerhards, http://blog.gerhards.net
  • 4. External Interface Design Goals • Keep it stupid simple ▫ Must support almost any language ▫ Dumb easy to use even for novice programmer ▫ Do not require explicit threading • Speed is NOT the most important goal ▫ Don't make it unnecessarily slow ▫ Many real-world log destinations are slow in any case (like when you connect via http...) ▫ Focus on “enable to build solution” ▫ If necessary, conversion to internal module can be done later Rainer Gerhards, http://blog.gerhards.net
  • 5. Interface Details: communication • use pipes • stdin ▫ one message per line ▫ format can be customized via rsyslog templates ▫ multi-line messags via JSON • stdout/stderr ▫ Must NOT be written in initial version ▫ Will later convey back state information via plain text (e.g. “ERR”, “ERRMSG:xxx”, ...) • JSON as input format is recommended Rainer Gerhards, http://blog.gerhards.net
  • 6. Interface Details: Threading • Do NOT care about threading • Write app according to single-thread paradigm • rsyslog will spawn multiple instances of your plugin if there is need to do so ▫ ▫ ▫ ▫ Happens based on config in busy cases Works well in most cases (e.g. http connects) Can be disabled if necessary If your program can run in multiple ter-minal sessions concurrently, it can also be run as multiple rsyslog action instances. Rainer Gerhards, http://blog.gerhards.net
  • 7. Startup & Termination • • • • • • rsyslog will startup the plugin automatically Plugin needs to read stdin until EOF Do NOT terminate before EOF is reached On EOF, cleanup and terminate If the plugin dies, rsyslog restarts a new instance Some signals (like sigint) are blocked and should remain so Rainer Gerhards, http://blog.gerhards.net
  • 8. Skeletons • The rsyslog project provides sample plugin skeletons • Available in ./plugins/external/skeletons • These contain ▫ the necessary plumbing ▫ often a kind of abstraction layer to make writing plugins even easier ▫ often performance-enhancement features • Can simply be copied to create your own plugins, don't care about the (minimal) plumbing! Rainer Gerhards, http://blog.gerhards.net
  • 9. Example: Python Skeleton • Handles all interface plumbing • Uses “eventHandlers” to call the acutal app coding • Is used as a basis, for example, for the Solr output plugin • Available at https://github.com/rsyslog/rsyslog/blob/master/plugin Rainer Gerhards, http://blog.gerhards.net
  • 10. onInit() Handler • Called when the plugin is initially loaded • Ready outbound connections, files, etc... def onInit(): """ Do everything that is needed to initialize processing (e.g. open files, create handles, connect to systems...) """ global outfile outfile = open("/tmp/logfile", "w") Rainer Gerhards, http://blog.gerhards.net
  • 11. onReceive() • Called when new messages arrive • Receives one or more message via Python list object --> e.g. place them into one transaction, HTTP request, ... def onReceive(msgs): """This is the entry point where actual work needs to be done. It receives a list with all messages pulled from rsyslog. The list is of variable length, but contains all messages that are currently available. It is suggest NOT to use any further buffering, as we do not know when the next message will arrive. It may be in a nanosecond from now, but it may also be in three hours... """ global outfile for msg in msgs: outfile.write(msg) Rainer Gerhards, http://blog.gerhards.net
  • 12. onExit() • Called immediately before the plugin terminates • Gurantees that no more messages arrive • Used to cleanup connections, write some final records, ... def onExit(): """ Do everything that is needed to finish processing (e.g. close files, handles, disconnect from systems...). This is being called immediately before exiting. """ global outfile outfile.close() Rainer Gerhards, http://blog.gerhards.net
  • 13. Call to Action • If you need to send logs to a destination that is not yet supported, you can quickly write an external plugin – in any language you know! • Writing rsyslog plugins is easy ▫ If there is already a skeleton for your language, copy it and add your app-specific code ▫ If not ... no problem, the interface is dumb easy If you can write a script that reads stdin and does something useful with it, you can also write a rsyslog plugin! Rainer Gerhards, http://blog.gerhards.net