SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Beyond the Loadable Modules
Extending a Zabbix Agent for fun and profit
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Agenda
What is the Zabbix Loadable Module ?
The Problem. Why the loadable module is not
for everyone.
The Solution. Next step beyond the Loadable
Module.
How it is implemented ?
What you can do with it ?
The Requirements.
Performance and convenience.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Zabbix Loadable Module, is a simple and
elegant way to extend your agent and a
server.


Unlike running an external script, this is a
shared library, which is loaded by Zabbix
component during startup and become a
part of such component, operating inside
it’s address space.
So, this is not only about running a custom
code from an Agent or the Server, but
doing it with performance in mind.
What is the Zabbix loadable module.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
At some point, you are realized, that the
performance of the UserParameter isn't
great.
Although, Zabbix Loadable Module and
correct “C” code is very powerful, it is not
for everyone. Because…
let's face the truth ….
The Problem.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
The Problem.
Most of us nowadays are not “C” developers.
Which is one of the pre-requirement for
developing a Zabbix Loadable Module.
Even if we do know how and can develop using “C”,
oftentimes we do not have a time to develop
and “own” a piece of the “C” code.
Even if we do know “C”, and can afford an
expense to “owning” a “C” code, oftentimes we do
need to develop something fast, using already
existing high-level modules
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Developing you Metrics collection code
using language other than “C”.
The Solution.
Embed this language into the Zabbix Agent
by using Loadable Modules.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
The Requirements.
The solution is to use any RAD(1) language. Try to pick
the one, which do have the following:
(1) RAD stands for “Rapid Application Development”
Rich data types. OOP capabilities is a plus
Embeddable with simple API
Rich library of the modules, which shall allow you
fast implementation of custom metrics acquisition.
It is a accepted in your company by it's lead Architect
ZABBIX
www.zabbix.comBeyond the Loadable Modules
The Requirements.
Language shall be mature, well developed and
documented and you shall have more than a
single developer around who can code in it.
It shall be approved by your local InfoSec team.
It shall be readily available for all hardware and
OS platforms you do need to cover.
For the people not exposed to this particular
language before, it shall be fairly easy to learn
It shall be fast enough for your purposes.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
The Decision.
I chose the Python(1) as my “language of choice”,
because it is matching of all my requirements and
I do have a rich library of classes and functions
which helps me to collect metrics data with ease.
(1) http://www.python.org
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Design decisions and a problems to solve:
How to startup and initialize
How to do the data types conversion
How to route Zabbix “call for the metric” to
the Python module.
How to finalize
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Setup of the development environment:
Or configure and install Python from the
sources. Look at http://www.python.org
Ether install python-devel (or similar)
package provided by your OS vendor
If you can compile any Python extension
module, you are fine.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Python API you do need to know for the data conversion:
PyLongAsLong(), PyFloat_AsDouble(), PyArg_Parse()

Converting Python objects into a “C” types
PyString_FromString(…)

Creating Python string object from “C” char*
PyTuple_SET_ITEM(…)

Set value in the tuple.
PyTuple_New(…)

Creating a new tuple. That’s how you pass parameters.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Zabbix API you do need to know for the data conversion:
SET_MSG_RESULT(...)

Passing a message from “C” module back to Zabbix
SET_UI64_RESULT(…)/SET_DBL_RESULT(…)/SET_STR_RESULT(...)

Set Unsigned Integer/Double/String as a result
get_rparam(…)

Returning parameter from AGENT_REQUEST*
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Python API you do need to know for Initialization and
Finalization:
Py_Initialize()

Initialize Python environment
Py_SetProgramName(…) 

Set program name for an embedded Python
Py_Finalize()

Uninitialize Python environment
Py_IsInitialized()

Check if Python environment initialized
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Zabbix API you do need to know for Initialization and
Finalization:
int zbx_module_init()

Loadable module initialization function. Executed when
module loads. Returns ZBX_MODULE_OK if module
loaded succedsfully, or ZBX_MODULE_FAIL otherwise.
During Startup, we are calling Python function
“main(...)” from module ZBX_startup.py
int zbx_module_uninit()
Loadable Module finalization function. Executed when
Zabbix Agent goes into shutdown. Returns
ZBX_MODULE_OK if module loaded succedsfully, or
ZBX_MODULE_FAIL otherwise. During shutdown, we
are calling Python function “main(...)” from the module
ZBX_finish.py
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Python API you do need to know for proper handling of the
PyObject*:
Python uses reference-based garbage collector.
Py_DECREF(…)

Decrease reference count for a Python object
Py_INCREF(…)

Increase reference count for a Python object
Py_REFCNT(…)

Return the number of the reference counts
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Python API you do need to know for working with
Modules and executing Python “code objects”:
PyObject_GetAttrString(…)

Lookup an attribute or an object in the Python
module. Returns a reference to the attribute if found.
PyImport_ImportModule(…)

Importing a Python module. Returns a reference to a
module.
PyEval_CallObject(…)

Execute a Python “code object”.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Zabbix API call returning list of the supported metrics:
ZBX_METRIC *zbx_module_item_list()
Returns a list of the metric keys
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Metrics exported from Python module to Zabbix :
python.ping[]
Returns “1” if module is properly initialized, otherwise
“0”
python.version[]
Returns text representatikon of the version of the
Python interpreter.
py[…]
Pass the call from Zabbix to Python
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
How to define metrics in Zabbix Loadable Module :
You shall define NULL-terminated array of ZBX_METRIC structures, as
static ZBX_METRIC keys[]
Each metric structure describes a single metric as:

Name
Name of the metric
Flag
Pass “0” if no parameters required or CF_HAVEPARAMS
if parameters are expected
Function
Reference to a metric function
Test parameters
Test parameters to a metric function
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Example:
static ZBX_METRIC keys[] =
{
{"python.ping", 0, zbx_module_python_ping, NULL},
{"python.version", 0, zbx_module_python_version, NULL},
{"py", CF_HAVEPARAMS, zbx_module_python_call_wrap, ""},
{NULL}
};
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Passing call from Zabbix to Python in “C”:
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Routing call from Zabbix to Python through ZBX_call/main:
ZABBIX
www.zabbix.comBeyond the Loadable Modules
What you can do with it.
Create metric collection. It could be something as
simple as this:
And after you place this module in pymodules
directory, you can query this metric like this:
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Or full-blown Python
application with classes,
objects and everything ...
ZABBIX
www.zabbix.comBeyond the Loadable Modules
How it is implemented.
Previous example will allow you to query the metric, which
returns the number of specific processes which command lines
are matching a user-defined pattern. For example, that how we
can query the number of sshd processes attached to pts pseudo-
terminals.
zabbix_get -s localhost –k py["AF_ps","sshd: (.*)pts/(.*)","sshd"]
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Performance and Convenience
Let's talk about performance:
I my test, I am requesting a series of metrics from a
passive Agent, using zabbix_get
Let's test just the effectiveness of the call. Our metric
will be very simple and return UNIX timestamp
I am setting up the same module, which will be called
from Loadable Module and UserParameters
UserParameter=python.time,/usr/bin/python /usr/local/etc/pymodules/ZBX_time.py
In the same /usr/local/etc/zabbix_agentd.conf
vs
LoadModulePath=/usr/local/etc
LoadModule=python.so
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Performance and Convenience
Required time:
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Performance and Convenience
Seconds per request:
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Performance and Convenience
You are using RAD language to create a
custom Metric collection
You can use any Python features. No
restrictions. But your metric collection code
shall be efficient and quick.
The test shows increase in performance.
Embedded Python which loaded through
Zabbix Loadable Module provides about 5.7
times faster response time while executing
the same code. But your results may vary ...
Your metric collection is as fast, as your host
can compute and efficient your code.
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Conclusion
Author: Vladimir Ulogov
e-mail: vladimir.ulogov@zabbix.com
https://github.com/vulogov/zlm-python
ZABBIX
www.zabbix.comBeyond the Loadable Modules
Conclusion
Q/A ?

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Zabbix 3.0 and beyond - FISL 2015
Zabbix 3.0 and beyond - FISL 2015Zabbix 3.0 and beyond - FISL 2015
Zabbix 3.0 and beyond - FISL 2015
 
Florian Koch - Monitoring CoreOS with Zabbix
Florian Koch - Monitoring CoreOS with ZabbixFlorian Koch - Monitoring CoreOS with Zabbix
Florian Koch - Monitoring CoreOS with Zabbix
 
Dev objective2015 lets git together
Dev objective2015 lets git togetherDev objective2015 lets git together
Dev objective2015 lets git together
 
Oded Coster - Stack Overflow behind the scenes - how it's made - Codemotion M...
Oded Coster - Stack Overflow behind the scenes - how it's made - Codemotion M...Oded Coster - Stack Overflow behind the scenes - how it's made - Codemotion M...
Oded Coster - Stack Overflow behind the scenes - how it's made - Codemotion M...
 
Command box
Command boxCommand box
Command box
 
Enterprise Integration Patterns with Apache Camel
Enterprise Integration Patterns with Apache CamelEnterprise Integration Patterns with Apache Camel
Enterprise Integration Patterns with Apache Camel
 
Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017Full stack development with node and NoSQL - All Things Open - October 2017
Full stack development with node and NoSQL - All Things Open - October 2017
 
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
NCUG 2019: Spring forward: an introduction to Spring boot and Thymeleaf for (...
 
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
Webinar - Matteo Manchi: Dal web al nativo: Introduzione a React Native
 
Scripts that automate OWASP ZAP as part of a continuous delivery pipeline
Scripts that automate OWASP ZAP as part of a continuous delivery pipelineScripts that automate OWASP ZAP as part of a continuous delivery pipeline
Scripts that automate OWASP ZAP as part of a continuous delivery pipeline
 
2017 Codemotion OWASP ZAP in CI/CD
2017 Codemotion OWASP ZAP in CI/CD2017 Codemotion OWASP ZAP in CI/CD
2017 Codemotion OWASP ZAP in CI/CD
 
zas-agent-0.1.1
zas-agent-0.1.1zas-agent-0.1.1
zas-agent-0.1.1
 
Java-Jersey 到 Python-Flask 服務不中斷重構之旅
Java-Jersey 到 Python-Flask 服務不中斷重構之旅Java-Jersey 到 Python-Flask 服務不中斷重構之旅
Java-Jersey 到 Python-Flask 服務不中斷重構之旅
 
Serverless architecture: introduction & first steps
Serverless architecture: introduction & first stepsServerless architecture: introduction & first steps
Serverless architecture: introduction & first steps
 
PyCon India 2012: Celery Talk
PyCon India 2012: Celery TalkPyCon India 2012: Celery Talk
PyCon India 2012: Celery Talk
 
2020 ADDO Spring Break OWASP ZAP Automation
2020 ADDO Spring Break OWASP ZAP Automation2020 ADDO Spring Break OWASP ZAP Automation
2020 ADDO Spring Break OWASP ZAP Automation
 
The ELK Stack - Get to Know Logs
The ELK Stack - Get to Know LogsThe ELK Stack - Get to Know Logs
The ELK Stack - Get to Know Logs
 
Javantura v4 - Java or Scala – Web development with Playframework 2.5.x - Kre...
Javantura v4 - Java or Scala – Web development with Playframework 2.5.x - Kre...Javantura v4 - Java or Scala – Web development with Playframework 2.5.x - Kre...
Javantura v4 - Java or Scala – Web development with Playframework 2.5.x - Kre...
 
ruxc0n 2012
ruxc0n 2012ruxc0n 2012
ruxc0n 2012
 
2021 ZAP Automation in CI/CD
2021 ZAP Automation in CI/CD2021 ZAP Automation in CI/CD
2021 ZAP Automation in CI/CD
 

Similar a Vladimir Ulogov - Beyond the Loadable Module

ZLM-Cython Build you first module
ZLM-Cython Build you first moduleZLM-Cython Build you first module
ZLM-Cython Build you first module
Vladimir Ulogov
 
OpenERP Technical Memento
OpenERP Technical MementoOpenERP Technical Memento
OpenERP Technical Memento
Odoo
 
Rifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotRifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobot
Tsai Tsung-Yi
 
The Basic Concept Of IOC
The Basic Concept Of IOCThe Basic Concept Of IOC
The Basic Concept Of IOC
Carl Lu
 
Using advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint developmentUsing advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint development
sadomovalex
 

Similar a Vladimir Ulogov - Beyond the Loadable Module (20)

ZLM-Cython Build you first module
ZLM-Cython Build you first moduleZLM-Cython Build you first module
ZLM-Cython Build you first module
 
OpenERP Technical Memento
OpenERP Technical MementoOpenERP Technical Memento
OpenERP Technical Memento
 
Open erp technical_memento_v0.6.3_a4
Open erp technical_memento_v0.6.3_a4Open erp technical_memento_v0.6.3_a4
Open erp technical_memento_v0.6.3_a4
 
Rifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobotRifartek Robot Training Course - How to use ClientRobot
Rifartek Robot Training Course - How to use ClientRobot
 
OpenWhisk by Example - Auto Retweeting Example in Python
OpenWhisk by Example - Auto Retweeting Example in PythonOpenWhisk by Example - Auto Retweeting Example in Python
OpenWhisk by Example - Auto Retweeting Example in Python
 
3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf3 Ways to Get Started with a React App in 2024.pdf
3 Ways to Get Started with a React App in 2024.pdf
 
The Basic Concept Of IOC
The Basic Concept Of IOCThe Basic Concept Of IOC
The Basic Concept Of IOC
 
Building A Sensor Network Controller
Building A Sensor Network ControllerBuilding A Sensor Network Controller
Building A Sensor Network Controller
 
Robot framework
Robot frameworkRobot framework
Robot framework
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
Introduction of Pharo 5.0
Introduction of Pharo 5.0Introduction of Pharo 5.0
Introduction of Pharo 5.0
 
Cocoapods and Most common used library in Swift
Cocoapods and Most common used library in SwiftCocoapods and Most common used library in Swift
Cocoapods and Most common used library in Swift
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deployment
 
Vhdl design flow
Vhdl design flowVhdl design flow
Vhdl design flow
 
Using advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint developmentUsing advanced C# features in Sharepoint development
Using advanced C# features in Sharepoint development
 
Gitlab and Lingvokot
Gitlab and LingvokotGitlab and Lingvokot
Gitlab and Lingvokot
 
Building a chatbot – step by step
Building a chatbot – step by stepBuilding a chatbot – step by step
Building a chatbot – step by step
 
slides.pptx
slides.pptxslides.pptx
slides.pptx
 
Bapi jco
Bapi jcoBapi jco
Bapi jco
 
Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]
Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]
Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]
 

Más de Zabbix

Más de Zabbix (20)

Zabbix Conference LatAm 2016 - Jessian Ferreira - Wireless with Zabbix
Zabbix Conference LatAm 2016 - Jessian Ferreira - Wireless with ZabbixZabbix Conference LatAm 2016 - Jessian Ferreira - Wireless with Zabbix
Zabbix Conference LatAm 2016 - Jessian Ferreira - Wireless with Zabbix
 
Zabbix Conference LatAm 2016 - Andre Deo - Zabbix Brazil Community
Zabbix Conference LatAm 2016 - Andre Deo - Zabbix Brazil CommunityZabbix Conference LatAm 2016 - Andre Deo - Zabbix Brazil Community
Zabbix Conference LatAm 2016 - Andre Deo - Zabbix Brazil Community
 
Zabbix Conference LatAm 2016 - Jorge Pretel - Low Level Discovery for ODBC an...
Zabbix Conference LatAm 2016 - Jorge Pretel - Low Level Discovery for ODBC an...Zabbix Conference LatAm 2016 - Jorge Pretel - Low Level Discovery for ODBC an...
Zabbix Conference LatAm 2016 - Jorge Pretel - Low Level Discovery for ODBC an...
 
Zabbix Conference LatAm 2016 - Andre Deo - SNMP and Zabbix
Zabbix Conference LatAm 2016 - Andre Deo - SNMP and ZabbixZabbix Conference LatAm 2016 - Andre Deo - SNMP and Zabbix
Zabbix Conference LatAm 2016 - Andre Deo - SNMP and Zabbix
 
Zabbix Conference LatAm 2016 - Rodrigo Mohr - Challenges on Large Env with Or...
Zabbix Conference LatAm 2016 - Rodrigo Mohr - Challenges on Large Env with Or...Zabbix Conference LatAm 2016 - Rodrigo Mohr - Challenges on Large Env with Or...
Zabbix Conference LatAm 2016 - Rodrigo Mohr - Challenges on Large Env with Or...
 
Zabbix Conference LatAm 2016 - Marcio Prop - Monitoring Complex Environments ...
Zabbix Conference LatAm 2016 - Marcio Prop - Monitoring Complex Environments ...Zabbix Conference LatAm 2016 - Marcio Prop - Monitoring Complex Environments ...
Zabbix Conference LatAm 2016 - Marcio Prop - Monitoring Complex Environments ...
 
Zabbix Conference LatAm 2016 - Daniel Nasiloski - Extending Zabbix - Interact...
Zabbix Conference LatAm 2016 - Daniel Nasiloski - Extending Zabbix - Interact...Zabbix Conference LatAm 2016 - Daniel Nasiloski - Extending Zabbix - Interact...
Zabbix Conference LatAm 2016 - Daniel Nasiloski - Extending Zabbix - Interact...
 
Zabbix Conference LatAm 2016 - Filipe Paternot - Zbx@Globo Automation+Integra...
Zabbix Conference LatAm 2016 - Filipe Paternot - Zbx@Globo Automation+Integra...Zabbix Conference LatAm 2016 - Filipe Paternot - Zbx@Globo Automation+Integra...
Zabbix Conference LatAm 2016 - Filipe Paternot - Zbx@Globo Automation+Integra...
 
Zabbix Conference LatAm 2016 - Douglas Esteves - Zabbix at UNICAMP
Zabbix Conference LatAm 2016 - Douglas Esteves - Zabbix at UNICAMPZabbix Conference LatAm 2016 - Douglas Esteves - Zabbix at UNICAMP
Zabbix Conference LatAm 2016 - Douglas Esteves - Zabbix at UNICAMP
 
Ryan Armstrong - Monitoring More Than 6000 Devices in Zabbix | ZabConf2016
Ryan Armstrong - Monitoring More Than 6000 Devices in Zabbix | ZabConf2016Ryan Armstrong - Monitoring More Than 6000 Devices in Zabbix | ZabConf2016
Ryan Armstrong - Monitoring More Than 6000 Devices in Zabbix | ZabConf2016
 
Rafael Martinez Guerrero - Zabbix at the University of Oslo | ZabConf2016
Rafael Martinez Guerrero - Zabbix at the University of Oslo | ZabConf2016Rafael Martinez Guerrero - Zabbix at the University of Oslo | ZabConf2016
Rafael Martinez Guerrero - Zabbix at the University of Oslo | ZabConf2016
 
Wolfgang Alper - Zabbix Meets OPS Control / Rundeck | ZabConf2016
Wolfgang Alper - Zabbix Meets OPS Control / Rundeck | ZabConf2016Wolfgang Alper - Zabbix Meets OPS Control / Rundeck | ZabConf2016
Wolfgang Alper - Zabbix Meets OPS Control / Rundeck | ZabConf2016
 
Wolfgang Alper - Zabbix Meets OPS Control / Rundeck | ZabConf2016
Wolfgang Alper - Zabbix Meets OPS Control / Rundeck | ZabConf2016Wolfgang Alper - Zabbix Meets OPS Control / Rundeck | ZabConf2016
Wolfgang Alper - Zabbix Meets OPS Control / Rundeck | ZabConf2016
 
Sumit Goel - Monitoring Cloud Applications Using Zabbix | ZabConf2016
Sumit Goel - Monitoring Cloud Applications Using Zabbix | ZabConf2016Sumit Goel - Monitoring Cloud Applications Using Zabbix | ZabConf2016
Sumit Goel - Monitoring Cloud Applications Using Zabbix | ZabConf2016
 
Rihards Olups - Zabbix at Nokia - Case Study
Rihards Olups - Zabbix at Nokia - Case StudyRihards Olups - Zabbix at Nokia - Case Study
Rihards Olups - Zabbix at Nokia - Case Study
 
Raymond Kuiper - Zen and The Art of Zabbix Template Design | ZabConf2016
Raymond Kuiper - Zen and The Art of Zabbix Template Design | ZabConf2016Raymond Kuiper - Zen and The Art of Zabbix Template Design | ZabConf2016
Raymond Kuiper - Zen and The Art of Zabbix Template Design | ZabConf2016
 
Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...
Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...
Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...
 
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
 
Mikhail Serkov - Zabbix for HPC Cluster Support | ZabConf2016
Mikhail Serkov - Zabbix for HPC Cluster Support | ZabConf2016Mikhail Serkov - Zabbix for HPC Cluster Support | ZabConf2016
Mikhail Serkov - Zabbix for HPC Cluster Support | ZabConf2016
 
Konstantin Yakovlev - Event Analysis Toolset | ZabConf2016
Konstantin Yakovlev - Event Analysis Toolset | ZabConf2016Konstantin Yakovlev - Event Analysis Toolset | ZabConf2016
Konstantin Yakovlev - Event Analysis Toolset | ZabConf2016
 

Último

Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
JoseMangaJr1
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
amitlee9823
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
amitlee9823
 

Último (20)

CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Probability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter LessonsProbability Grade 10 Third Quarter Lessons
Probability Grade 10 Third Quarter Lessons
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Bommasandra Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Saket (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 

Vladimir Ulogov - Beyond the Loadable Module

  • 1. ZABBIX www.zabbix.comBeyond the Loadable Modules Beyond the Loadable Modules Extending a Zabbix Agent for fun and profit
  • 2. ZABBIX www.zabbix.comBeyond the Loadable Modules Agenda What is the Zabbix Loadable Module ? The Problem. Why the loadable module is not for everyone. The Solution. Next step beyond the Loadable Module. How it is implemented ? What you can do with it ? The Requirements. Performance and convenience.
  • 3. ZABBIX www.zabbix.comBeyond the Loadable Modules Zabbix Loadable Module, is a simple and elegant way to extend your agent and a server. 
 Unlike running an external script, this is a shared library, which is loaded by Zabbix component during startup and become a part of such component, operating inside it’s address space. So, this is not only about running a custom code from an Agent or the Server, but doing it with performance in mind. What is the Zabbix loadable module.
  • 4. ZABBIX www.zabbix.comBeyond the Loadable Modules At some point, you are realized, that the performance of the UserParameter isn't great. Although, Zabbix Loadable Module and correct “C” code is very powerful, it is not for everyone. Because… let's face the truth …. The Problem.
  • 5. ZABBIX www.zabbix.comBeyond the Loadable Modules The Problem. Most of us nowadays are not “C” developers. Which is one of the pre-requirement for developing a Zabbix Loadable Module. Even if we do know how and can develop using “C”, oftentimes we do not have a time to develop and “own” a piece of the “C” code. Even if we do know “C”, and can afford an expense to “owning” a “C” code, oftentimes we do need to develop something fast, using already existing high-level modules
  • 6. ZABBIX www.zabbix.comBeyond the Loadable Modules Developing you Metrics collection code using language other than “C”. The Solution. Embed this language into the Zabbix Agent by using Loadable Modules.
  • 7. ZABBIX www.zabbix.comBeyond the Loadable Modules The Requirements. The solution is to use any RAD(1) language. Try to pick the one, which do have the following: (1) RAD stands for “Rapid Application Development” Rich data types. OOP capabilities is a plus Embeddable with simple API Rich library of the modules, which shall allow you fast implementation of custom metrics acquisition. It is a accepted in your company by it's lead Architect
  • 8. ZABBIX www.zabbix.comBeyond the Loadable Modules The Requirements. Language shall be mature, well developed and documented and you shall have more than a single developer around who can code in it. It shall be approved by your local InfoSec team. It shall be readily available for all hardware and OS platforms you do need to cover. For the people not exposed to this particular language before, it shall be fairly easy to learn It shall be fast enough for your purposes.
  • 9. ZABBIX www.zabbix.comBeyond the Loadable Modules The Decision. I chose the Python(1) as my “language of choice”, because it is matching of all my requirements and I do have a rich library of classes and functions which helps me to collect metrics data with ease. (1) http://www.python.org
  • 10. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Design decisions and a problems to solve: How to startup and initialize How to do the data types conversion How to route Zabbix “call for the metric” to the Python module. How to finalize
  • 11. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Setup of the development environment: Or configure and install Python from the sources. Look at http://www.python.org Ether install python-devel (or similar) package provided by your OS vendor If you can compile any Python extension module, you are fine.
  • 12. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Python API you do need to know for the data conversion: PyLongAsLong(), PyFloat_AsDouble(), PyArg_Parse() 
Converting Python objects into a “C” types PyString_FromString(…) 
Creating Python string object from “C” char* PyTuple_SET_ITEM(…)
 Set value in the tuple. PyTuple_New(…)
 Creating a new tuple. That’s how you pass parameters.
  • 13. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Zabbix API you do need to know for the data conversion: SET_MSG_RESULT(...) 
Passing a message from “C” module back to Zabbix SET_UI64_RESULT(…)/SET_DBL_RESULT(…)/SET_STR_RESULT(...) 
Set Unsigned Integer/Double/String as a result get_rparam(…)
 Returning parameter from AGENT_REQUEST*
  • 14. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Python API you do need to know for Initialization and Finalization: Py_Initialize()
 Initialize Python environment Py_SetProgramName(…) 
 Set program name for an embedded Python Py_Finalize()
 Uninitialize Python environment Py_IsInitialized()
 Check if Python environment initialized
  • 15. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Zabbix API you do need to know for Initialization and Finalization: int zbx_module_init()
 Loadable module initialization function. Executed when module loads. Returns ZBX_MODULE_OK if module loaded succedsfully, or ZBX_MODULE_FAIL otherwise. During Startup, we are calling Python function “main(...)” from module ZBX_startup.py int zbx_module_uninit() Loadable Module finalization function. Executed when Zabbix Agent goes into shutdown. Returns ZBX_MODULE_OK if module loaded succedsfully, or ZBX_MODULE_FAIL otherwise. During shutdown, we are calling Python function “main(...)” from the module ZBX_finish.py
  • 16. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Python API you do need to know for proper handling of the PyObject*: Python uses reference-based garbage collector. Py_DECREF(…)
 Decrease reference count for a Python object Py_INCREF(…)
 Increase reference count for a Python object Py_REFCNT(…)
 Return the number of the reference counts
  • 17. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Python API you do need to know for working with Modules and executing Python “code objects”: PyObject_GetAttrString(…)
 Lookup an attribute or an object in the Python module. Returns a reference to the attribute if found. PyImport_ImportModule(…)
 Importing a Python module. Returns a reference to a module. PyEval_CallObject(…) 
Execute a Python “code object”.
  • 18. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Zabbix API call returning list of the supported metrics: ZBX_METRIC *zbx_module_item_list() Returns a list of the metric keys
  • 19. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Metrics exported from Python module to Zabbix : python.ping[] Returns “1” if module is properly initialized, otherwise “0” python.version[] Returns text representatikon of the version of the Python interpreter. py[…] Pass the call from Zabbix to Python
  • 20. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. How to define metrics in Zabbix Loadable Module : You shall define NULL-terminated array of ZBX_METRIC structures, as static ZBX_METRIC keys[] Each metric structure describes a single metric as:
 Name Name of the metric Flag Pass “0” if no parameters required or CF_HAVEPARAMS if parameters are expected Function Reference to a metric function Test parameters Test parameters to a metric function
  • 21. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Example: static ZBX_METRIC keys[] = { {"python.ping", 0, zbx_module_python_ping, NULL}, {"python.version", 0, zbx_module_python_version, NULL}, {"py", CF_HAVEPARAMS, zbx_module_python_call_wrap, ""}, {NULL} };
  • 22. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Passing call from Zabbix to Python in “C”:
  • 23. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Routing call from Zabbix to Python through ZBX_call/main:
  • 24. ZABBIX www.zabbix.comBeyond the Loadable Modules What you can do with it. Create metric collection. It could be something as simple as this: And after you place this module in pymodules directory, you can query this metric like this:
  • 25. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Or full-blown Python application with classes, objects and everything ...
  • 26. ZABBIX www.zabbix.comBeyond the Loadable Modules How it is implemented. Previous example will allow you to query the metric, which returns the number of specific processes which command lines are matching a user-defined pattern. For example, that how we can query the number of sshd processes attached to pts pseudo- terminals. zabbix_get -s localhost –k py["AF_ps","sshd: (.*)pts/(.*)","sshd"]
  • 27. ZABBIX www.zabbix.comBeyond the Loadable Modules Performance and Convenience Let's talk about performance: I my test, I am requesting a series of metrics from a passive Agent, using zabbix_get Let's test just the effectiveness of the call. Our metric will be very simple and return UNIX timestamp I am setting up the same module, which will be called from Loadable Module and UserParameters UserParameter=python.time,/usr/bin/python /usr/local/etc/pymodules/ZBX_time.py In the same /usr/local/etc/zabbix_agentd.conf vs LoadModulePath=/usr/local/etc LoadModule=python.so
  • 28. ZABBIX www.zabbix.comBeyond the Loadable Modules Performance and Convenience Required time:
  • 29. ZABBIX www.zabbix.comBeyond the Loadable Modules Performance and Convenience Seconds per request:
  • 30. ZABBIX www.zabbix.comBeyond the Loadable Modules Performance and Convenience You are using RAD language to create a custom Metric collection You can use any Python features. No restrictions. But your metric collection code shall be efficient and quick. The test shows increase in performance. Embedded Python which loaded through Zabbix Loadable Module provides about 5.7 times faster response time while executing the same code. But your results may vary ... Your metric collection is as fast, as your host can compute and efficient your code.
  • 31. ZABBIX www.zabbix.comBeyond the Loadable Modules Conclusion Author: Vladimir Ulogov e-mail: vladimir.ulogov@zabbix.com https://github.com/vulogov/zlm-python
  • 32. ZABBIX www.zabbix.comBeyond the Loadable Modules Conclusion Q/A ?