Le Blog Utux

Parce qu'il n'y a pas que Linkedin pour se faire mousser avec des articles techniques

OpenBSD: get rid of Comic sans ms in httpd error messages

Rédigé par uTux

I have been playing with OpenBSD and httpd lately. It's a really simple and fun webserver to use, despite suffering huge limitations, but I quickly stumble across this horror:

No joke. httpd will serve all errors messages with the infamous Comic sans ms font. It's probably a troll from the maintainers, at least I hope so. Comic sans ms sucks, I don't want that on my server. Fortunately, there is a simple way to disable it.

Add this line into your /etc/httpd.conf:

errdocs "/errdocs"

Then create the file /var/www/errdocs/err.html with the following content:

                                                                                                           
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>$RESPONSE_CODE $HTTP_ERROR</title>
<style type="text/css"><!--
body { background-color: white; color: black; }
hr { border: 0; border-bottom: 1px dashed; }
@media (prefers-color-scheme: dark) {
body { background-color: #1E1F21; color: #EEEFF1; }
a { color: #BAD7FF; }
}
--></style>
</head>
<body>
<h1>$RESPONSE_CODE $HTTP_ERROR</h1>
<hr>
<address>$SERVER_SOFTWARE</address>
</body>
</html>

Then restart httpd:

rcctl restart httpd

Explanation: httpd manage says:


A custom error document may contain the following macros that will be expanded at runtime:

$HTTP_ERROR
    The error message text.
$RESPONSE_CODE
    The 3-digit HTTP response code sent to the client.
$SERVER_SOFTWARE
    The server software name of httpd(8).

So I just took the source code of a 404 error page, removed the Comic sans ms part in the CSS and replaced the values (error code, message, server identity) by the proper variables. Now all errors messages should be generated with this new template, with a fallback font.

Build Zabbix-Agent2 under Ubuntu 16.04

Rédigé par uTux

If you need to install Zabbix-Agent2 on Ubuntu 16.04, you will find out that there is no available packages in Zabbix repository (unlinke Zabbix-Agent). You can try to use packages for other Linux systems, even RPMs, but you will always end up with library or ABI issues. The only way to make it work is compilation.

Install requirements:

apt install -y libpcre++-dev build-essential zlib1g-dev libssl-dev

Get Zabbix source code:

wget https://cdn.zabbix.com/zabbix/sources/stable/6.2/zabbix-6.2.4.tar.gz
tar xf zabbix-6.2.4.tar.gz

You need at least Go 1.17 (for Zabbix 6.2.4):

wget https://go.dev/dl/go1.19.3.linux-amd64.tar.gz
tar xf go1.19.3.linux-amd64.tar.gz
export PATH=$PATH:/root/go/bin

You should now be able to build Zabbix-Agent 2. I took these options from Zabbix documentation and made some ajustements from what I found in packages in Zabbix repository:

cd zabbix-6.2.4
./configure \
--enable-agent2 \
--enable-static \
--prefix=/usr \
--sysconfdir=/etc/zabbix \
--libdir=/usr/lib/zabbix \
--with-curl \
--with-openssl

Note: According Zabbix documentation, the --enable-static flag is useful if you want to create your own package and use it on other systems.

You can now build and install:

make install

You can now remove Go if you don't need it. A few steps are required to make Zabbix-Agent 2 work:

addgroup --system --quiet zabbix
adduser --quiet --system \
--disabled-login \
--ingroup zabbix \
--home /var/lib/zabbix \
--no-create-home zabbix
mkdir -p /etc/zabbix/zabbix_agent2.d/plugins.d
mkdir /run/zabbix/
chown -R zabbix:zabbix /run/zabbix
mkdir /var/log/zabbix
chown -R zabbix:zabbix /var/log/zabbix

Create /etc/logrotate.d/zabbix_agent2:

/var/log/zabbix/zabbix_agent2.log {
    weekly
    rotate 12
    compress
    delaycompress
    missingok
    notifempty
    create 0640 zabbix zabbix
}

In the packages from Zabbix repository we have /usr/lib/tmpfiles.d/zabbix-agent2.conf:

d /run/zabbix 0755 zabbix zabbix - -

Don't forget to create a /etc/zabbix/zabbix_agent2.conf file. Here is a sample.

Finally, create a systemd unit file in /lib/systemd/system/zabbix-agent2.service:

[Unit]
Description=Zabbix Agent 2
After=syslog.target
After=network.target

[Service]
Environment="CONFFILE=/etc/zabbix/zabbix_agent2.conf"
EnvironmentFile=-/etc/default/zabbix-agent2
Type=simple
Restart=on-failure
PIDFile=/run/zabbix/zabbix_agent2.pid
KillMode=control-group
ExecStart=/usr/sbin/zabbix_agent2 -c $CONFFILE
ExecStop=/bin/sh -c '[ -n "$1" ] && kill -s TERM "$1"' -- "$MAINPID"
RestartSec=10s
User=zabbix
Group=zabbix

[Install]
WantedBy=multi-user.target

Reload, enable and start this new service:

systemctl daemon-reload
sytemctl enable --now zabbix-agent2

Check that everything works:

systemctl status zabbix-agent2
tail /var/log/zabbix/zabbix_agent2.log

Profit!