Python f-String Formatting Codes

Here is my short list about the common f-string formatting codes in Python: >>> score = 123.728 >>> f”{score}” ‘123.728’ Minimum field length: >>> f”{score:>10}” ‘ 123.728’ >>> f”{score:<10}” ‘123.728 ‘ >>> f”{score:^10}” ‘ 123.728 ‘ Number of decimals: >>> f”{score:.2f}” ‘123.73’ >>> f”{score:10.2f}” ‘ 123.73’ >>> f”{score:<10.2f}” ‘123.73 ‘ Padded with a character: >>> […]

Zabbix Active Agent Autoregistration

Let’s see how the Zabbix active agent autoregistration works in the communication. I have configured the Zabbix agent (version 6.2.3) on the Linux host at 192.168.7.17 with this configuration: ServerActive=192.168.7.15 Hostname=Test-agent After restarting the agent, the Zabbix server (version 6.2.3) at 192.168.7.15 logged immediately in /var/log/zabbix/zabbix_server.log: cannot send list of active checks to “192.168.7.17”: host […]

Configuring Logging in NetBox

Creating the log file and setting the permissions: $ sudo mkdir /var/log/netbox $ sudo touch /var/log/netbox/netbox.log $ sudo chown -R netbox.netbox /var/log/netbox $ Configuring NetBox (in /opt/netbox/netbox/netbox/configuration.py): You can set the level for the loggers as needed, in this setup the file handler accepts DEBUG and higher but the actual loggers (“django” and “netbox”) only […]

Basic Mocking with Pytest

Since I always seem to search for these examples over and over again, here it is, basic mocking with pytest. My example code is this (testmodule.py): It can be run: $ python3 testmodule.py In testfunc, sleeping $ Not surprisingly, running it takes about five seconds. The time.sleep() call simulates some long-running operation in the code. […]

Tag Guidelines in Zabbix

This is a tag-specific summary from the official Zabbix guidelines documentation, based on the situation as of Zabbix 6.0 LTS. Note: “Please note that this model might become enforced in the future Zabbix releases. Templates that do not follow specified rules will need to be updated.“ Tag name and value format lowercase only allowed characters: […]

Saving Gzip Files in Python

I have various Python applications that run periodically and deal with data in lists and dictionaries, and they save the processed and/or discovered data as JSON in text files for logging purposes or other later use. Typically the files are quite large and take up substantial amount of disk space. Since the applications run on […]