SlideShare a Scribd company logo
ZABBIX
www.zabbix.com
Building your first Python module for ZLM-Cython
Using zlm-cython with ease...
ZABBIX
www.zabbix.com
AGENDA
What you shall know before you begin.
Locations
Building a module
Testing a module
Using a module
What's next ?
ZABBIX
www.zabbix.com
What you shall know before you begin.
Apparently, you shall know the Python. You shall know it well enough, to be
able to write a short and fast snippets of the code. You shall be proficient with
all libraries tools and protocols involved in your project. For example: if you
are monitoring REDIS(1) storage, you shall be familiar not only with Python
itself, but with Python module which you will use to access REDIS, and with
REDIS itself.
(1) REDIS – high-performance in-memory data structure store, used as database,
cache and message broker. http://redis.io
While you beginning to developing you module, you shall be also familiar
with all “common-sense” Python performance programming techniques. I am
recommending to look at the book “High Performance Python” by Ian
Ozsvald.
You shall be also proficient in the area of System Administration and
Systems Management well enough, so you can understand the impact of
the execution of your code to the target hosts and applications. You must
be comfortable when dealing with such hosts, operating systems and all
applications involved.
ZABBIX
www.zabbix.com
What you shall know before you begin.
And of course, you must have “hands-on” experience on how to use OS shell
and OS commands, how to edit text files, how to use source-code version
control tools used by developers in your organization, how your code will be
integrating with configuration management, build and deployment tools.
And this is not the end. You shall be able to create “secure” code. This
means, that you code must pass check, performed by your security team.
You must be familiar with all local guidelines and requirements related to
application security.
Systems and Application Architect shall know about your software development
and deployment activities.
You must know how to document your code. And actually do that
Documentation
And the last, but not least. You shall know how to test your code for a bugs and
a performance issues.
ZABBIX
www.zabbix.com
What you shall know before you begin.
Well … You are not just in IT-monitoring anymore. You are becoming
Software Developer and must think and act like one.
ZABBIX
www.zabbix.com
Locations
Open your Zabbix configuration file (1) and locate variable LoadModulePath
Verify, that you are loading zlm_python.so module is loaded. Look for variable
LoadModule=zlm_python.so
Your module files and all other directory and files will be relative
to the location, defined by this variable.
Please locate directory pymodules, which shall be subdirectory of the
directory defined in LoadModulePath .
Verify location of your log files as defined by LogFile.
(1) zabbix_server.conf or zabbix_agentd.conf.
If this directory do not exists, please create it and assign ownersyhip to user
cefined in variable User. It is probably a good idea to set user sticky bit for this
directory.
ZABBIX
www.zabbix.com
Building a module
With text editor of your
choice, please create file
called ZBX_test.py and
define three simple
functions.
Please note:
Default function of the module
Is main()
This function return Integer
This function return Float
This function return String
ZABBIX
www.zabbix.com
Building a module
We support only those three data types: Integer, String and a Float. ZLM-
Python will automatically convert Python value to a Zabbix value.
What you return from the function, will be passed directly to Zabbix
All exceptions will be properly handled. We will talk about exceptions in a
little while.
You can refer individual functions inside the module from the Zabbix as:
Module name.Function name. Default function name is “main”
The first parameter, passed to a function by ZLM-Python is “context”, usually
referred by variable name “ctx”. This object is used to pass data between
different process and will be explained in more details later on.
ZABBIX
www.zabbix.com
Testing a module
Before you will try to query the metric through Zabbix Agent or Zabbix Server, you shall
Test a metric through zabbix_agentd -t <metric name>
Testing this metric
ZLM-Python initializing
ZLM-Python loading
configuration
ZLM-Python pre-load
our test module
ZBX_test.this_is_int() returns 42.
It is “unsigned Integer”. SUCCESS !
ZABBIX
www.zabbix.com
Testing a module
What if something goes wrong ? What yo will see from zabbix_agentd -t <metric name> ?
Let's create a metric collection function, which will do nothing, but throw
a Python exception.
When called, this function will throw an AttributeError exception and pass the
parameter string.
Raise an Exception
AttributeError
… and here is parameter
ZABBIX
www.zabbix.com
Testing a module
What if something goes wrong ? What yo will see from zabbix_agentd -t <metric name> ?
Call that metric
Looks okay, so far
Oy ! Our metric threw
a traceback and become
NOTSUPPORTED
And here goes Python traceback, to help us
to troubleshoot the problem.
ZABBIX
www.zabbix.com
Testing a module
When you metric functions exit successfully and generate proper
output, you can move to the next test: collecting data through
zabbix_agentd (if your metric collector designed to run from
zabbix_agentd)
If your zabbix_agentd -t <metricname> is core-dumped,
CONGRATULATIONS ! You've found a bug in ZLM-python.
Yes, there are bugs and I will try to fix them as soon as I can.
Please report this bug to
https://github.com/vulogov/zlm-cython/issues
Please include as much information as possible.
ZABBIX
www.zabbix.com
Testing a module
Try to query your new metric keys (if you are loading the module
inside Zabbix Agent)
Here, we are calling
default function
Calling function which
returns Integer, getting
Integer
Calling function which
returns Float, getting
Float
Calling function which
returns String, getting
String
ZABBIX
www.zabbix.com
Testing a module
The previous attempt was successful, but what if we get an error ? Collect this metric
Item will become a
NOTSUPPORTED
And here goes Python traceback, to help us
to troubleshoot the problem.
ZABBIX
www.zabbix.com
Using a module
Now, let's create a Zabbix Item, for the
function that returns Integer
Name for the metric
Collecting from zabbix_agendCalling ZLM-python
Module: ZBX_test
Function: this_is_int()
Type of the Zabbix Item shall
match to the type of the data
returned from metric function
ZABBIX
www.zabbix.com
Using a module
Now, let's create a Zabbix Item, for the
function that returns float
Name for the metric
Collecting from zabbix_agendCalling ZLM-python
Module: ZBX_test
Function: this_is_float()
Type of the Zabbix Item shall
match to the type of the data
returned from metric function
ZABBIX
www.zabbix.com
Using a module
Now, let's create a Zabbix Item, for the
function that returns string
Name for the metric
Collecting from zabbix_agendCalling ZLM-python
Module: ZBX_test
Function: this_is_float()
Type of the Zabbix Item shall
match to the type of the data
returned from metric function
ZABBIX
www.zabbix.com
Using a module
Now, let's create a Zabbix Item, for the
function that returns float and ZLM-Python
is executed on Zabbix Server
Name for the metric
Collecting on zabbix_server
Calling ZLM-python
Module: ZBX_test
Function: this_is_float()
Type of the Zabbix Item shall
match to the type of the data
returned from metric function
ZABBIX
www.zabbix.com
Using a module
ZLM-python will help you to troubleshoot you metric collectors by properly passing
information about exceptions back to Zabbix. If your metric throw an exception, the
Item will become “Not supported” and you can get the information about traceback
right from the frontend by clicking on the red icon.
Display the information
about an exception
ZABBIX
www.zabbix.com
What's next ?
Passing parameters from Zabbix to Python functions
Non-positional parameters
You can use ether positional or non-positional parameters.
Please note, all parameters are passed as strings. You shall
do the proper type sanitation and conversion inside your
module.
ZABBIX
www.zabbix.com
What's next ?
Using the ZLM-python Context object
Proxy for the context object
of the ZLM-Cython core
ZLM-python context object allow you to save some data to the
global dictionary and pass it between Zabbix threads. If you
assign some variable to the context in one thread, like
ctx.name = “Value”, you can refer to it later on using this
notation: ctx.name . Context is global and we do support all
Python picklable data types.
ZABBIX
www.zabbix.com
Q/A ?
Вопросы ?
質問
Jautāt ?
Fragen ?
Interroger ?

More Related Content

PDF
zlm-cython
KEY
Pinto+Stratopan+Love
PPTX
PDF
Securing Legacy CFML Code
PDF
How do I Write Testable Javascript so I can Test my CF API on Server and Client
PDF
Console Apps: php artisan forthe:win
KEY
Speedy TDD with Rails
KEY
Dependency Management With Pinto
zlm-cython
Pinto+Stratopan+Love
Securing Legacy CFML Code
How do I Write Testable Javascript so I can Test my CF API on Server and Client
Console Apps: php artisan forthe:win
Speedy TDD with Rails
Dependency Management With Pinto

What's hot (20)

PPTX
Performance tips for Symfony2 & PHP
PDF
eZ Publish Platform 5.4 public webinar
PDF
What's new on Laravel 5.5
PDF
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
PPT
Rapid scaling in_the_cloud_with_puppet
PDF
Continuous Integration Testing in Django
PDF
Fighting Fear-Driven-Development With PHPUnit
PDF
2021laravelconftwslides6
PDF
PHP-VCR Lightningtalk
PDF
PHP-VCR behat case study
PDF
DevOps with Serverless
PDF
Beyond AEM Curl Commands
PDF
Quick flask an intro to flask
PDF
Laravel Forge: Hello World to Hello Production
PDF
Php Dependency Management with Composer ZendCon 2016
PDF
Swagger AEM - An OpenAPI Specification for AEM
PPTX
10 Laravel packages everyone should know
PPTX
Phalcon 2 - PHP Brazil Conference
PPT
Sauce Labs Beta Program Overview
PDF
Java fx smart code econ
Performance tips for Symfony2 & PHP
eZ Publish Platform 5.4 public webinar
What's new on Laravel 5.5
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
Rapid scaling in_the_cloud_with_puppet
Continuous Integration Testing in Django
Fighting Fear-Driven-Development With PHPUnit
2021laravelconftwslides6
PHP-VCR Lightningtalk
PHP-VCR behat case study
DevOps with Serverless
Beyond AEM Curl Commands
Quick flask an intro to flask
Laravel Forge: Hello World to Hello Production
Php Dependency Management with Composer ZendCon 2016
Swagger AEM - An OpenAPI Specification for AEM
10 Laravel packages everyone should know
Phalcon 2 - PHP Brazil Conference
Sauce Labs Beta Program Overview
Java fx smart code econ
Ad

Viewers also liked (7)

PPTX
An Introduction To Python - Modules & Solving Real World Problems
PDF
Python的module机制与最佳实践
PDF
Python typing module
PPT
python.ppt
PDF
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
PDF
Functions and modules in python
PDF
Learn 90% of Python in 90 Minutes
An Introduction To Python - Modules & Solving Real World Problems
Python的module机制与最佳实践
Python typing module
python.ppt
Pivotal Data Labs - Technology and Tools in our Data Scientist's Arsenal
Functions and modules in python
Learn 90% of Python in 90 Minutes
Ad

Similar to ZLM-Cython Build you first module (20)

PDF
Vladimir Ulogov - Beyond the Loadable Module
PDF
Beyond the Loadable Module
PDF
Vladimir Ulogov - Large Scale Simulation | ZabConf2016 Lightning Talk
PDF
zas-agent-0.1.1
PDF
The Basic Concept Of IOC
PPTX
A brief overview of java frameworks
PPT
Rifartek Robot Training Course - How to use ClientRobot
PDF
Open erp technical_memento_v0.6.3_a4
PDF
PVS-Studio vs Chromium. 3-rd Check
PPTX
Adding a modern twist to legacy web applications
PDF
Educating your app – adding ML edge to your apps - Maoz Tamir
PDF
JavaScript Miller Columns
PPTX
Safe Wrappers and Sane Policies for Self Protecting JavaScript
PDF
Agentic AI Use Cases using GenAI LLM models
PDF
Building a chatbot – step by step
PDF
Flask jwt authentication tutorial
KEY
Building A Sensor Network Controller
PDF
How to Test Asynchronous Code (v2)
PPT
Jdk Tools For Performance Diagnostics
ODP
WebNano - Ideas for Web Frameworks
Vladimir Ulogov - Beyond the Loadable Module
Beyond the Loadable Module
Vladimir Ulogov - Large Scale Simulation | ZabConf2016 Lightning Talk
zas-agent-0.1.1
The Basic Concept Of IOC
A brief overview of java frameworks
Rifartek Robot Training Course - How to use ClientRobot
Open erp technical_memento_v0.6.3_a4
PVS-Studio vs Chromium. 3-rd Check
Adding a modern twist to legacy web applications
Educating your app – adding ML edge to your apps - Maoz Tamir
JavaScript Miller Columns
Safe Wrappers and Sane Policies for Self Protecting JavaScript
Agentic AI Use Cases using GenAI LLM models
Building a chatbot – step by step
Flask jwt authentication tutorial
Building A Sensor Network Controller
How to Test Asynchronous Code (v2)
Jdk Tools For Performance Diagnostics
WebNano - Ideas for Web Frameworks

More from Vladimir Ulogov (7)

PPTX
Introduction to the core.ns application framework
PPTX
Generating test data for Statistical and ML models
PPTX
Short presentation of the Bitmasher private-key encryption
PPTX
Krabbe - messaging in loose groups
PPTX
"the Bund" language. A PEG grammar.
PPTX
The Bund language
PDF
Vladimir_Ulogov_Resume
Introduction to the core.ns application framework
Generating test data for Statistical and ML models
Short presentation of the Bitmasher private-key encryption
Krabbe - messaging in loose groups
"the Bund" language. A PEG grammar.
The Bund language
Vladimir_Ulogov_Resume

ZLM-Cython Build you first module

  • 1. ZABBIX www.zabbix.com Building your first Python module for ZLM-Cython Using zlm-cython with ease...
  • 2. ZABBIX www.zabbix.com AGENDA What you shall know before you begin. Locations Building a module Testing a module Using a module What's next ?
  • 3. ZABBIX www.zabbix.com What you shall know before you begin. Apparently, you shall know the Python. You shall know it well enough, to be able to write a short and fast snippets of the code. You shall be proficient with all libraries tools and protocols involved in your project. For example: if you are monitoring REDIS(1) storage, you shall be familiar not only with Python itself, but with Python module which you will use to access REDIS, and with REDIS itself. (1) REDIS – high-performance in-memory data structure store, used as database, cache and message broker. http://redis.io While you beginning to developing you module, you shall be also familiar with all “common-sense” Python performance programming techniques. I am recommending to look at the book “High Performance Python” by Ian Ozsvald. You shall be also proficient in the area of System Administration and Systems Management well enough, so you can understand the impact of the execution of your code to the target hosts and applications. You must be comfortable when dealing with such hosts, operating systems and all applications involved.
  • 4. ZABBIX www.zabbix.com What you shall know before you begin. And of course, you must have “hands-on” experience on how to use OS shell and OS commands, how to edit text files, how to use source-code version control tools used by developers in your organization, how your code will be integrating with configuration management, build and deployment tools. And this is not the end. You shall be able to create “secure” code. This means, that you code must pass check, performed by your security team. You must be familiar with all local guidelines and requirements related to application security. Systems and Application Architect shall know about your software development and deployment activities. You must know how to document your code. And actually do that Documentation And the last, but not least. You shall know how to test your code for a bugs and a performance issues.
  • 5. ZABBIX www.zabbix.com What you shall know before you begin. Well … You are not just in IT-monitoring anymore. You are becoming Software Developer and must think and act like one.
  • 6. ZABBIX www.zabbix.com Locations Open your Zabbix configuration file (1) and locate variable LoadModulePath Verify, that you are loading zlm_python.so module is loaded. Look for variable LoadModule=zlm_python.so Your module files and all other directory and files will be relative to the location, defined by this variable. Please locate directory pymodules, which shall be subdirectory of the directory defined in LoadModulePath . Verify location of your log files as defined by LogFile. (1) zabbix_server.conf or zabbix_agentd.conf. If this directory do not exists, please create it and assign ownersyhip to user cefined in variable User. It is probably a good idea to set user sticky bit for this directory.
  • 7. ZABBIX www.zabbix.com Building a module With text editor of your choice, please create file called ZBX_test.py and define three simple functions. Please note: Default function of the module Is main() This function return Integer This function return Float This function return String
  • 8. ZABBIX www.zabbix.com Building a module We support only those three data types: Integer, String and a Float. ZLM- Python will automatically convert Python value to a Zabbix value. What you return from the function, will be passed directly to Zabbix All exceptions will be properly handled. We will talk about exceptions in a little while. You can refer individual functions inside the module from the Zabbix as: Module name.Function name. Default function name is “main” The first parameter, passed to a function by ZLM-Python is “context”, usually referred by variable name “ctx”. This object is used to pass data between different process and will be explained in more details later on.
  • 9. ZABBIX www.zabbix.com Testing a module Before you will try to query the metric through Zabbix Agent or Zabbix Server, you shall Test a metric through zabbix_agentd -t <metric name> Testing this metric ZLM-Python initializing ZLM-Python loading configuration ZLM-Python pre-load our test module ZBX_test.this_is_int() returns 42. It is “unsigned Integer”. SUCCESS !
  • 10. ZABBIX www.zabbix.com Testing a module What if something goes wrong ? What yo will see from zabbix_agentd -t <metric name> ? Let's create a metric collection function, which will do nothing, but throw a Python exception. When called, this function will throw an AttributeError exception and pass the parameter string. Raise an Exception AttributeError … and here is parameter
  • 11. ZABBIX www.zabbix.com Testing a module What if something goes wrong ? What yo will see from zabbix_agentd -t <metric name> ? Call that metric Looks okay, so far Oy ! Our metric threw a traceback and become NOTSUPPORTED And here goes Python traceback, to help us to troubleshoot the problem.
  • 12. ZABBIX www.zabbix.com Testing a module When you metric functions exit successfully and generate proper output, you can move to the next test: collecting data through zabbix_agentd (if your metric collector designed to run from zabbix_agentd) If your zabbix_agentd -t <metricname> is core-dumped, CONGRATULATIONS ! You've found a bug in ZLM-python. Yes, there are bugs and I will try to fix them as soon as I can. Please report this bug to https://github.com/vulogov/zlm-cython/issues Please include as much information as possible.
  • 13. ZABBIX www.zabbix.com Testing a module Try to query your new metric keys (if you are loading the module inside Zabbix Agent) Here, we are calling default function Calling function which returns Integer, getting Integer Calling function which returns Float, getting Float Calling function which returns String, getting String
  • 14. ZABBIX www.zabbix.com Testing a module The previous attempt was successful, but what if we get an error ? Collect this metric Item will become a NOTSUPPORTED And here goes Python traceback, to help us to troubleshoot the problem.
  • 15. ZABBIX www.zabbix.com Using a module Now, let's create a Zabbix Item, for the function that returns Integer Name for the metric Collecting from zabbix_agendCalling ZLM-python Module: ZBX_test Function: this_is_int() Type of the Zabbix Item shall match to the type of the data returned from metric function
  • 16. ZABBIX www.zabbix.com Using a module Now, let's create a Zabbix Item, for the function that returns float Name for the metric Collecting from zabbix_agendCalling ZLM-python Module: ZBX_test Function: this_is_float() Type of the Zabbix Item shall match to the type of the data returned from metric function
  • 17. ZABBIX www.zabbix.com Using a module Now, let's create a Zabbix Item, for the function that returns string Name for the metric Collecting from zabbix_agendCalling ZLM-python Module: ZBX_test Function: this_is_float() Type of the Zabbix Item shall match to the type of the data returned from metric function
  • 18. ZABBIX www.zabbix.com Using a module Now, let's create a Zabbix Item, for the function that returns float and ZLM-Python is executed on Zabbix Server Name for the metric Collecting on zabbix_server Calling ZLM-python Module: ZBX_test Function: this_is_float() Type of the Zabbix Item shall match to the type of the data returned from metric function
  • 19. ZABBIX www.zabbix.com Using a module ZLM-python will help you to troubleshoot you metric collectors by properly passing information about exceptions back to Zabbix. If your metric throw an exception, the Item will become “Not supported” and you can get the information about traceback right from the frontend by clicking on the red icon. Display the information about an exception
  • 20. ZABBIX www.zabbix.com What's next ? Passing parameters from Zabbix to Python functions Non-positional parameters You can use ether positional or non-positional parameters. Please note, all parameters are passed as strings. You shall do the proper type sanitation and conversion inside your module.
  • 21. ZABBIX www.zabbix.com What's next ? Using the ZLM-python Context object Proxy for the context object of the ZLM-Cython core ZLM-python context object allow you to save some data to the global dictionary and pass it between Zabbix threads. If you assign some variable to the context in one thread, like ctx.name = “Value”, you can refer to it later on using this notation: ctx.name . Context is global and we do support all Python picklable data types.