Zabbix MonitWhoring

I’ve played with quite a few monitoring solutions.. some commercial, majority Open Source.. tools such as Spiceworks, Nagios, OpenNMS, MRTG, PRTG, Cacti..  They’re all great.. they just seem to lack something.. either a polished (G)UI.. or a lightweight platform that doesn’t require a DWAVE box to operate.

I’ve just got started with Zabbix and i’ll be honest, I’m impressed.

Active/Passive monitoring, SLA alerting, Proprietary agent + SNMP, Nice front end – feature packed but responsive, Traffic/Resource plotting, Incident management to name but a few.

Rolling it out has been a little troublesome. Mainly because of the arsehole that deployed the servers in this network (me). I’ve got a mix of OpenSUSE, Centos, Ubuntu LTS and FreeBSD based systems.. that’s not even starting on the Windows XP Terminal Server, the 2008 AD server and the various Windows 7 testing machines we have.

Thought I’d better create some notes for when I have a breakdown and need to remember what the fuck I’m doing!

This isn’t a complete writeup, nor is it supposed to be. I blog for me, if anyone else benefits then great.


Ubuntu/Debian

Same as each other. Start script is the same. Make sure binaries are in ‘/usr/local/sbin/‘ and that config file is within ‘/etc/zabbix/‘..

Start script for ‘/etc/init.d/zabbix_agentd’

#!/bin/sh
#
# Zabbix agent start/stop script.
#
# Copyright (C) 2001-2014 Zabbix SIA

NAME=zabbix_agentd
DAEMON=/usr/local/sbin/${NAME}
DESC=”Zabbix agent daemon”
PID=/tmp/$NAME.pid

test -f $DAEMON || echo 0

case “$1” in
start)
echo “Starting $DESC: $NAME”
start-stop-daemon –start –oknodo –pidfile $PID –exec $DAEMON
;;
stop)
echo “Stopping $DESC: $NAME”
start-stop-daemon –stop –quiet –pidfile $PID –retry=TERM/10/KILL/5 && exit 0
start-stop-daemon –stop –oknodo –exec $DAEMON –name $NAME –retry=TERM/10/KILL/5
;;
restart|force-reload)
$0 stop
$0 start
;;
*)
N=/etc/init.d/$NAME
echo “Usage: $N {start|stop|restart|force-reload}” >&2
exit 1
;;
esac

exit 0

 

 


 

CentOS

Simple here, same rules as other OS. Unpack binary to ‘/usr/local/sbin/’ and make sure config file can be found at ‘/etc/zabbix_agentd.conf’, unless you plan to override the default location using ‘-c’.

/etc/int.d/zabbix_agentd;

#!/bin/bash
#
# chkconfig: – 90 10
# description: Starts and stops Zabbix Agent using chkconfig
# Tested on Fedora Core 2 – 5
# Should work on all Fedora Core versions
#
# @name: zabbix_agentd
# @author: Alexander Hagenah <hagenah@topconcepts.com>
# @created: 18.04.2006
#
# Modified for Zabbix 2.0.0
# May 2012, Zabbix SIA
#
# Source function library.
. /etc/init.d/functions

# Variables
# Edit these to match your system settings

# Zabbix-Directory
BASEDIR=/usr/local

# Binary File
BINARY_NAME=zabbix_agentd

# Full Binary File Call
FULLPATH=$BASEDIR/sbin/$BINARY_NAME

# PID file
PIDFILE=/tmp/$BINARY_NAME.pid

# Establish args
ERROR=0
STOPPING=0

#
# No need to edit the things below
#

# application checking status
if [ -f $PIDFILE ] && [ -s $PIDFILE ]
then
PID=`cat $PIDFILE`

if [ “x$PID” != “x” ] && kill -0 $PID 2>/dev/null && [ $BINARY_NAME == `ps -e | grep $PID | awk ‘{print $4}’` ]
then
STATUS=”$BINARY_NAME (pid `pidof $APP`) running..”
RUNNING=1
else
rm -f $PIDFILE
STATUS=”$BINARY_NAME (pid file existed ($PID) and now removed) not running..”
RUNNING=0
fi
else
if [ `ps -e | grep $BINARY_NAME | head -1 | awk ‘{ print $1 }’` ]
then
STATUS=”$BINARY_NAME (pid `pidof $APP`, but no pid file) running..”
else
STATUS=”$BINARY_NAME (no pid file) not running”
fi
RUNNING=0
fi

# functions
start() {
if [ $RUNNING -eq 1 ]
then
echo “$0 $ARG: $BINARY_NAME (pid $PID) already running”
else
action $”Starting $BINARY_NAME: ” $FULLPATH
touch /var/lock/subsys/$BINARY_NAME
fi
}

stop() {
echo -n $”Shutting down $BINARY_NAME: “
killproc $BINARY_NAME
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$BINARY_NAME
RUNNING=0
}
# logic
case “$1” in
start)
start
;;
stop)
stop
;;
status)
status $BINARY_NAME
;;
restart)
stop
sleep 10
start
;;
help|*)
echo $”Usage: $0 {start|stop|status|restart|help}”
cat <<EOF

start – start $BINARY_NAME
stop – stop $BINARY_NAME
status – show current status of $BINARY_NAME
restart – restart $BINARY_NAME if running by sending a SIGHUP or start if not running
help – this screen

EOF
exit 1
;;
esac

exit 0

Make it start at boot up;

chkconfig –add zabbix_agentd
chkconfig –levels 2345 zabbix_agentd on


 

OpenSUSE

Installation of the Zabbix Agent on OpenSUSE is relatively straight forward. Zabbix provide recompiled binaries for the operating system, and compilation notes can be found from Zabbix.

Once the binaries are in the right place (/usr/local/sbin/) it’s just a case of start scripts.

Make sure the config file is stored within ‘/etc/zabbix/’

Paste into ‘/etc/init.d’ as ‘zabbix_agentd’;

#! /bin/sh
# Copyright (c) 07/2004 A.Tophofen, Germany
# Modified for Zabbix 1.1alpha7 and SuSE Linux 9.2
# April 2005, A. Kiepe, Switzerland
# Modified for Zabbix 2.0.0
# May 2012, Zabbix SIA
#
# init.d/zabbix_agentd
#
### BEGIN INIT INFO
# Provides: zabbix_agentd
# Required-Start: $network $remote_fs $syslog
# Required-Stop:
# Default-Start: 3
# Default-Stop:
# Description: Starts Zabbix_Agentd
### END INIT INFO

. /etc/rc.status
rc_reset
NAME=”zabbix_agentd”

ZABBIX_BIN=”/usr/local/sbin/zabbix_agentd”
ZABBIX_PID=”/tmp/zabbix_agentd.pid”

if [ ! -x ${ZABBIX_BIN} ] ; then
echo -n “${ZABBIX_BIN} not installed! “
# Tell the user this has skipped
rc_status -s
exit 5
fi

export PATH=$PATH:/usr/local/sbin

case “$1” in
start)
echo -n “Starting ${NAME} “
checkproc -p ${ZABBIX_PID} ${ZABBIX_BIN}
case $? in
0) echo -n “- Warning: ${NAME} already running! ” ;;
1) echo -n “- Warning: ${ZABBIX_PID} exists! ” ;;
esac

startproc -p ${ZABBIX_PID} -u zabbix ${ZABBIX_BIN}
rc_status -v
;;
stop)
echo -n “Shutting down ${NAME}”
checkproc -p ${ZABBIX_PID} ${ZABBIX_BIN} || echo -n “- Warning: ${NAME} not running! “
killproc -p ${ZABBIX_PID} -TERM ${ZABBIX_BIN}
rc_status -v
;;
restart)
$0 stop
sleep 10
$0 start
rc_status
;;
*)
echo “Usage: $0 {start|stop|restart}”
exit 1
;;
esac
rc_exit

If wanting systemd control then the following script is also required within ‘/usr/lib/systemd/system/zabbix-agentd.service’;

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

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
RemainAfterExit=yes
PIDFile=/var/run/zabbix/zabbix_agentd.pid

[Install]
WantedBy=multi-user.target

Check the new unit file is being listed;

machine:/usr/lib/systemd/system # systemctl list-unit-files | grep zab
zabbix-agentd.service disabled

Enable the service;

sabre:/usr/lib/systemd/system # systemctl enable zabbix-agentd.service
ln -s ‘/usr/lib/systemd/system/zabbix-agentd.service’ ‘/etc/systemd/system/multi-user.target.wants/zabbix-agentd.service’

Check it’s enabled;

machine:/usr/lib/systemd/system # systemctl list-unit-files | grep zab
zabbix-agentd.service enabled

Start it;

machine:/usr/lib/systemd/system # systemctl start zabbix_agentd

Check it’s started by looking for a network bind (personal preference);

machine:/usr/lib/systemd/system # netstat -lptn | grep zab
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 21030/zabbix_agentd


FreeNAS

Had to be fettled with a little bit here to make it all work. FreeNAS likes to revert to a factory (database driven) settings base on restart. Prevents against system changes being persistent in case of error.

Creates a bit of an issue when wanting to install things like the Zabbix_agentd as nothing is held.. to get around it.. Create a ‘zabbix’ user through the UI, and then use its home directory to store the required files.

Firstly configure the ‘zabbix_agentd.conf’ file with the ‘Server’ and ‘ActiveServer’ being set to the Zabbix Server address. Define the HostName setting within the file or allow the process to inherit from the system. Zabbix server must be configured with the same hostname so the agent matches the server profile.

‘zabbix_agentd’ rc.d script;

#!/bin/bash

# REQUIRE: DAEMON
# PROVIDE: zabbix_agentd

. /etc/rc.subr

CONFLINK=”/usr/local/etc/zabbix_agentd.conf”
CONFFILE=”/mnt/Backups/homes/zabbix/usr/local/etc/zabbix_agentd.conf”

if [ ! -L $CONFLINK ]; then
ln -s $CONFFILE $CONFLINK
fi

echo ‘zabbix_agentd_enable=”YES”‘ >> /etc/rc.conf

name=”zabbix_agentd”
rcvar=`set_rcvar`
#command=”${prefix:-“/mnt/Backups/homes/zabbix/usr/local”}/sbin/${name}”
command=”/mnt/Backups/homes/zabbix/usr/local/sbin/zabbix_agentd”

load_rc_config ${name}
run_rc_command “$1”

This script above does three things;

  1. Creates a Symbolic link from the zabbix_agentd.conf within the Zabbix home directory, to the default location that zabbix_agentd expects to find the file within the system (/usr/local/etc/) so that it will start.
  2. Ensures that ‘zabbix_agentd_enable=”YES”‘ is within ‘/etc/rc.conf’ so that the process will start.
  3. Proves Start/Stop/Status control for the process

It is then required to add a PostInit command to the FreeNAS GUI (System, INIT/Shutdown scripts).

Type: Command
Command: /mnt/Backups/homes/zabbix/usr/local/etc/rc.d/zabbix_agentd start
Type: Post Init

This should be enough to get the zabbix_agentd running after a reboot, and connecting to your Zabbix Monitoring server.