lady:factory:zax

Zabbix Addons

These are some developments or setups I made arround zabbix monitoring system.

A part from the scripts or setups I developed, this page also serves as reference for other setups or configurations not made by me.

Note that I'm currently using Zabbix 3.2, so some templates make require that version or above

Monitoring

These are some setups, scripts or configurations to allow monitoring of different services.
There is some crucial difference to keep in mind with some of this agents: Passive and Active.

Active Agents are the ones which collect data and they push the data into the zabbix server Passive Agents sit there waiting for Zabbix server ask them to supply data.

Other interesting setups can be found on: https://www.zabbix.org/wiki/User_parameter_one-liners#Update_stats_file

Kernel random entropy gives a measure of the random quality of numbers used for cryptography. The suggested value is above 200 and maximum is 4096, so I set a trigger below 200 and I graph the quality percent.

Simply show the contents of the file thru Zabbix Agent:

UserParameter=kernel.entropy,cat /proc/sys/kernel/random/entropy_avail

Really not a script, a simple recipe I found somewhere on how to use the new xml-channel statistics offered by Bind9 to feed Zabbix Items on DNS server status.

  • curl
  • xml2

You can download the Bind9 Zabbix Template, which using that setup allows us to monitor:

  • Memory usage
  • Cached queries
  • Queries IN
  • Queries OUT

First configure bind9 server to enable statistics-channel, putting this on bind configuration:

statistics-channels {
  inet * port 8053 allow { 127.0.0.0/8; };
};

Then configure zabbix agent putting this on the zabbix agent configuration: (be ware, lines quite long)

# Added echo 0 failback to avoid unsupported (not seen) records
UserParameter=bind.queries.in[*],curl http://localhost:8053/ 2>/dev/null | xml2 | (grep -A1 "/isc/bind/statistics/server/queries-in/rdtype/name=$1$" || echo 0) | tail -1 | cut -d= -f2
UserParameter=bind.queries.out[*],curl http://localhost:8053/ 2>/dev/null | xml2 | (grep -A1 "/isc/bind/statistics/views/view/rdtype/name=$1$" || echo 0) | tail -1 | cut -d= -f2
UserParameter=bind.memory[*],curl http://localhost:8053/ 2>/dev/null | xml2 | grep "/isc/bind/statistics/memory/summary/$1" | cut -d= -f2
UserParameter=bind.cache[*],curl http://localhost:8053/ 2>/dev/null | xml2 | (grep -A1 "/isc/bind/statistics/views/view/cache/rrset/name=$1$" || echo 0) | tail -1 | cut -d= -f2
UserParameter=bind.nsstat[*],curl http://localhost:8053/ 2>/dev/null | xml2 | grep -A1 "/isc/bind/statistics/server/nsstat/name=$1$" | tail -1 | cut -d= -f2
UserParameter=bind.zonestat[*],curl http://localhost:8053/ 2>/dev/null | xml2 | grep -A1 "/isc/bind/statistics/server/zonestat/name=$1$" | tail -1 | cut -d= -f2

It checks UPS status (using NUT tools) and reports back to Zabbix UPS status, load, remaining battery, …,

Simple onliner (You should change 'Battery' by your UPS Name):

UserParameter=nut.clients,/bin/upsc -c Battery 2>/dev/null | wc -l
UserParameter=nut[*],/bin/upsc Battery $1 2>/dev/null || echo "NOCOMM"
UserParameter=nfs4[*], nfsstat -4 -l | grep "$1:" | awk '{print $$5}'
UserParameter=nfs3[*], nfsstat -3 -l | grep "$1:" | awk '{print $$5}'
  • <todo #mark:2016-10-05>Check RFC3530</todo>RFC3530

It parses/track mail log file and through It requires pflogsumm, reports mail delivery counters.

UserParameter=postfix.pfmailq,mailq | grep -v "Mail queue is empty" | grep -c '^[0-9A-Z]'
UserParameter=postfix[*],/usr/local/lib/zabbix/agent/postfix.sh $1

With OpenSSL we can easily create a script/param to fetch the x509 certificate used on a SSL/TLS secured service and monitor the expiry date. As this can be checked remotely from Zabbix server itself, we created a script to be copied/linked below zabbix-script directory and be used as an external check.

You must put the script inside the zabbix external script directory, check for ExternalScripts parameter in the zabbix server configuration, by default /usr/lib/zabbix/externalscripts

Create a new item of type ExternalCheck, Numeric, Decimal, and call the external check script using it as key:

ssl-cert.sh[$HOSTNAME,$PORT [, $SERVICE]]

The script basicaly returns expiry certificate expiry date in UNIX time. I provide no template for its use as this highly depends on your service configuration, but bellow there are some example for common services (what you have to use as key on the zabbix item):

ssl-cert.sh["webserver","443"]
ssl-cert.sh["smtp.example.com",25,smtp]
ssl-cert.sh["imap.example.com",143,imap]
ssl-cert.sh["imaps.example.com",993]

Note the subtle difference on last ones, for IMAP (plain) service which support STARTTLS command to secure the connection we specify the TCP port and 'imap' as the service, if you are using IMAPS encrypted channel on port 993 there is no need of STARTTLS command an only SSL port is needed.

Then you can create a trigger expression to warn when near expiry date, something like:

ssl-cert.sh["webserver","443"].last() - ssl-cert.sh["webserver","443"].now() < 60*60*24/7

Basically monitors Apache statistics, making use of the Apache's module mod_status. So for that work you need to ammend your Apache configuration to load that module and make it accessible via /server-status URL. You can use another URL, but then should review the config and script to make sure the agent can accesss it.

UserParameter=apache[*],/usr/local/lib/zabbix/agent/apache.sh localhost \$1

Note thay you can pass the server name to the script it should not be difficult to adapt it.

This is an active check (so it pushes the data into zabbix server).

Actions

These are scripts to be used as action triggers. They need to be deployed in zabbix-server script directory and configured as an Alert Action (Script media) in order to be able to use them.

This simple script allows you to log on the system log the events raised by Zabbix. Very simple, use the autodocumented variables to set the log facility and priority and the template message (which only logs the subject of the alert)

Although Zabbix features a SMS media action, this requires direct access to the GSM device. A part from incompatibilities or hardware support issues, this implies that zabbix will be the only one with access to the GSM device which you may need or use for other services. That's why I'm developing a separate script to interface with a SMS gateway using Gammu.

<todo>Voice Alarm notification</todo>

Others

Again, I took ideas from some forum post, and developed a PHP script which fetches the last trigerrs to generate a basic RSS feed.

For security reasons, the script tries to fetch configuration from a separated file zabbix-rss.conf.php to set some values as well as DataBase credentials. Is recommended to create a separated user for this with the minimum access rights to the Zabbix Database:

You should create a zabbix-rss.conf.php file with the following configuration:

<?php
define('DBSERVER',"db.l3jane.net");
define('DBNAME',"zabbix");
define('DBUSER',"");
define('DBPASS',"");

# How much time too look back (secs)
define('HISTORY',1800);

define('ZAX_NAME',"Lady 3Jane NOC");
define('ZAX_URL',"https://www.l3jane.net/zabbix/");
  • lady/factory/zax.txt
  • Last modified: 2023/06/26 15:13
  • by 10.24.231.248