Zabbix
Zabbix is an open source tool that allows companies to monitor their IT infrastructure. In industrial companies, we might wish to monitor our networks, the servers that run our SCADA sytem or other supporting sytems.
In this guide, we'll walk you through a basic setup using Python to extract metrics from Zabbix and writing it to Clarify.
This guide was written for and tested against Zabbix 6.0. For a complete documentation of the Zabbix APIs for this version, see their API documentation.
Pre-requisites
To reduce the amount of boilerplate code needed, we are going to use the py-zabbix and pyclarify modules to work with Zabbix and Clarify. In addition, we will be using pandas to perform some transformation of the data.
You will also need the url
of your Zabbix server, a user that has access to the data and an integration with Credentials in Clarify. If you haven't already created an integration, see the guide here for instructions and make sure you choose OAuth 2.0 as the credential type. Note that you will need the credentials file in the code-example below, so make sure you save it to your computer.
Zabbix and Clarify both uses the term item
, but there are some slight differences between the concepts. In Clarify, we say that the raw time-series data and meta-data from the source system is a signal
while the object that exposes that data and information to the end-user is called an item
.
For an explanation of the various concepts you'll encounter in Clarify, check out the concept section in our developer quickstart guide.
Code
Now let's get our first data transferred. The code-example below contains in-line comments explaining each step. There are two main concepts that you should pay attention to; how to query Zabbix for metrics, and how to transform it to a format that can be sent to Clarify.
# pip install py-zabbix pyclarify
from pyzabbix.api import ZabbixAPI
from pyclarify import APIClient, DataFrame
import pandas as pd
# Instantiate the API clients for talking with Zabbix and Clarify.
# You will need to insert a valid API URL, username and password for Zabbix here.
zabbix = ZabbixAPI(url=ZABBIX_API_URL, user=UNAME, password=PWORD)
# Make sure the clarify-credentials.json file is placed in the same directory as
# your Python code, or change the path to match. This is the file you downloaded
# when setting up credentials for the integration earlier, if you don't have a
# credentials file at this point, see the Pre-requisites section above.
clarify = APIClient("./clarify-credentials.json")
# Grab the historical data for the item we want.
result = zabbix.do_request('history.get',
{
'itemids': ITEM,
'output': 'extend',
'history': 0
})
# The response is a json-rpc 2.0 response object with the timestamp and
# measurement data for the item we requested.
# {
# 'jsonrpc': '2.0',
# 'result': [
# {
# 'itemid': '23273',
# 'clock': '1645456313',
# 'value': '44.44732666015625',
# 'ns': '855538103'
# },
# {
# 'itemid': '23273',
# 'clock': '1645456373',
# 'value': '44.573020935058594',
# 'ns': '894700066'
# }
# ...
# ]
# }
# Use pandas to create a pandas.DataFrame from the response
df = pd.DataFrame.from_dict(result['result'])
# Convert the two separate fields that contain the seconds and nanosecond portion
# of the timestamp, and use both to create a datetime which is what Clarify expects.
times = pd.to_datetime(df['clock'].astype(float)+df['ns'].astype(float)/1e9,unit='s')
# This field contains the values that we want to send to Clarify.
data = df['value']
# Make a clarify.DataFrame that holds the timestamps and the item data.
output = DataFrame(
series = {ITEM: data.to_list()},
times = times.to_list(),
)
# Insert the data into Clarify.
clarify.insert(output)
Now that we've gotten this far, we should have a signal
in Clarify that contains the data that we read from Zabbix. Open up the admin panel to see the list of signals belonging to your integration.
And that concludes this guide. If you want to extend the functionality, you could add more meta-data to the signals in Clarify with the save_signals
method in Clarify, or use the item.get
method in Zabbix to query a range of items.
If you found any errors, ambiguities or have any suggestions on how to make this guide better, please contact us via chat or send an email to hello@clarify.io 🙌
Disclaimer By using our guides you agree to the following disclaimer.