Book Image

Zabbix 1.8 Network Monitoring

By : Rihards Olups
Book Image

Zabbix 1.8 Network Monitoring

By: Rihards Olups

Overview of this book

Imagine you're celebrating the start of the weekend with Friday-night drinks with a few friends. And then suddenly your phone rings -- one of the servers you administer has gone down, and it needs to be back up before tomorrow morning. So you drag yourself back to the office, only to discover that some log files have been growing more than usual over the past few weeks and have filled up the hard drive. While the scenario above is very simplistic, something similar has happened to most IT workers at one or another point in their careers. To avoid such situations this book will teach you to monitor your network hardware, servers, and web performance using Zabbix- an open source system monitoring and reporting solution.The versatility of Zabbix allows monitoring virtually anything, but getting started with the new concepts can take some time. This book will take you through the most common tasks in a hands-on, step by step manner.Zabbix is a very flexible IT monitoring suite, but not every part of it is immediately clear to new users. Following the instructions in this book should allow you to set up monitoring of various metrics on various devices, including Linux and Windows machines, SNMP devices, IPMI enabled server,s and other network attached equipment. You will learn to define conditions – such a temperature being too high or service being down – and act upon them by notifying user by email, SMS, or even restarting service. You will learn to visualize the gathered data with graphs and the various tips and tricks that are provided will help to use Zabbix more efficiently and avoid common pitfalls.This book covers setting up Zabbix from the scratch and gradually introduces basic components of Zabbix, moving to more advanced topics later. Book's scope is based on the author's experience of working with Zabbix for many years, as well as on the questions users have asked on the Zabbix IRC channel and forums.
Table of Contents (22 chapters)
Zabbix 1.8 Network Monitoring
Credits
About the Author
About the Reviewers
Preface
6
Acting Upon Monitored Conditions

SUSE Linux Enterprise Server


The Zabbix package provides example startup scripts, but they are somewhat outdated. Here are init scripts for Zabbix server and agent daemons, based on the SUSE Linux Enterprise Server 10 SP2 skeleton file. It should be possible to use these files on most other distributions that have SysV-style init scripts. For Zabbix server, place the following in the /etc/init.d/zabbix_server file:

#! /bin/sh
#
# Original skeleton file from SLES10 Sp2 - # Copyright (C) 1995--2005 Kurt Garloff, SUSE / Novell Inc.
# Zabbix specifics - # Copyright (C) 2008--2009 Richlv
# This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; # either version 2.1 of the License, or (at your option) # any later version.
# This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the # Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307, USA.
# /etc/init.d/zabbix_server
# and its symbolic link
# /usr/sbin/rczabbix_server
#
### BEGIN INIT INFO
# Provides: zabbix_server
# Required-Start: $network $remote_fs $local_fs
# Should-Start: mysql postgresql
# Required-Stop: $network $remote_fs $local_fs
# Should-Stop: mysql postgresql
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Zabbix monitoring server daemon
# Description: This is a server daemon for the monitoring system Zabbix
# For more information see http://www.zabbix.com
### END INIT INFO
ZABBIX_CONFIG="/etc/zabbix/zabbix_server.conf"
test -r $ZABBIX_CONFIG || { echo "$ZABBIX_CONFIG missing";
if [ "$1" = "stop" ]; then exit 0;
else exit 6; fi; }
SUSE Linux Enterprise Serverstratup scriptsZABBIX_BIN="/usr/local/sbin/zabbix_server"
test -x $ZABBIX_BIN || { echo "$ZABBIX_BIN not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
. /etc/rc.status
# Reset status of this service
rc_reset
NAME="Zabbix server daemon"
ZABBIX_PID=/var/tmp/zabbix_server.pid
case "$1" in
start)
echo -n "Starting $NAME "
## Start daemon with startproc(8). If this fails
## the return value is set appropriately by startproc.
/sbin/startproc -t 1 -p $ZABBIX_PID $ZABBIX_BIN
# Remember status and be verbose
rc_status -v
;;
stop)
echo -n "Shutting down $NAME "
## Stop daemon with killproc(8) and if this fails
## killproc sets the return value according to LSB.
/sbin/killproc -TERM $ZABBIX_BIN
# Remember status and be verbose
rc_status -v
;;
try-restart|condrestart)
## Do a restart only if the service was active before.
## Note: try-restart is now part of LSB (as of 1.9).
## RH has a similar command named condrestart.
if test "$1" = "condrestart"; then
echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
fi
$0 status
if test $? = 0; then
$0 restart
SUSE Linux Enterprise Serverstratup scriptselse
rc_reset # Not running is not a failure.
fi
# Remember status and be quiet
rc_status
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
$0 start
# Remember status and be quiet
rc_status
;;
force-reload)
## Zabbix server daemon does not support configuration reloading, thus it is restarted, if running.
echo -n "Reload service $NAME "
$0 try-restart
rc_status
;;
reload)
## Zabbix server daemon does not support configuration reloading, thus reload fails
rc_failed 3
rc_status -v
;;
status)
echo -n "Checking for service $NAME "
## Check status with checkproc(8), if process is running
## checkproc will return with exit status 0.
# Return value is slightly different for the status command:
# 0 - service up and running
# 1 - service dead, but pid file exists
# 2 - service dead, but /var/lock/ lock file exists
# 3 - service not running (unused)
# 4 - service status unknown :-(
# 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
# NOTE: checkproc returns LSB compliant status values.
/sbin/checkproc -p $ZABBIX_PID $ZABBIX_BIN
# NOTE: rc_status knows that we called this init script with
# "status" option and adapts its messages accordingly.
rc_status -v
SUSE Linux Enterprise Serverstratup scripts;;
probe)
## Optional: Probe for the necessity of a reload, print out the
## argument to this init script which is required for a reload.
## Note: probe is not (yet) part of LSB (as of 1.9)
test $ZABBIX_CONFIG -nt $ZABBIX_PID && echo reload
;;
*)
echo "Usage: $0 {start|stop|status|try-restart|restart|force- reload|reload|probe}"
exit 1
;;
esac
rc_exit

For the Zabbix agent daemon, create /etc/init.d/zabbix_agentd with the following contents:

#! /bin/sh
#
# Original skeleton file from SLES10 Sp2 - # Copyright (C) 1995--2005 Kurt Garloff, SUSE / Novell Inc.
# Zabbix specifics - # Copyright (C) 2008--2009 Richlv
#
# This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any # later version.
#
# This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the # Free Software Foundation, Inc., 59 Temple Place, Suite 330, # Boston, MA 02111-1307, USA.
SUSE Linux Enterprise Serverstratup scripts#
# /etc/init.d/zabbix_agentd
# and its symbolic link
# /usr/sbin/rczabbix_agentd
#
### BEGIN INIT INFO
# Provides: zabbix_agentd
# Required-Start: $network $remote_fs $local_fs
# Required-Stop: $network $remote_fs $local_fs
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Zabbix monitoring agent daemon
# Description: This is a client daemon for the monitoring system Zabbix
# For more information see http://www.zabbix.com
### END INIT INFO
ZABBIX_CONFIG="/etc/zabbix/zabbix_agentd.conf"
test -r $ZABBIX_CONFIG || { echo "$ZABBIX_CONFIG missing";
if [ "$1" = "stop" ]; then exit 0;
else exit 6; fi; }
ZABBIX_BIN="/usr/local/sbin/zabbix_agentd"
test -x $ZABBIX_BIN || { echo "$ZABBIX_BIN not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
. /etc/rc.status
# Reset status of this service
rc_reset
NAME="Zabbix agent daemon"
ZABBIX_PID=/var/tmp/zabbix_agentd.pid
case "$1" in
start)
echo -n "Starting $NAME "
## Start daemon with startproc(8). If this fails
## the return value is set appropriately by startproc.
/sbin/startproc -t 1 -p $ZABBIX_PID $ZABBIX_BIN
# Remember status and be verbose
rc_status -v
;;
stop)
echo -n "Shutting down $NAME "
## Stop daemon with killproc(8) and if this fails
## killproc sets the return value according to LSB.
/sbin/killproc -TERM $ZABBIX_BIN
# Remember status and be verbose
rc_status -v
SUSE Linux Enterprise Serverstratup scripts;;
try-restart|condrestart)
## Do a restart only if the service was active before.
## Note: try-restart is now part of LSB (as of 1.9).
## RH has a similar command named condrestart.
if test "$1" = "condrestart"; then
echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
fi
$0 status
if test $? = 0; then
$0 restart
else
rc_reset # Not running is not a failure.
fi
# Remember status and be quiet
rc_status
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
$0 start
# Remember status and be quiet
rc_status
;;
force-reload)
## Zabbix agent daemon does not support configuration reloading, thus it is restarted,
## if running.
echo -n "Reload service $NAME "
$0 try-restart
rc_status
;;
reload)
## Zabbix agent daemon does not support configuration reloading, thus reload fails
rc_failed 3
rc_status -v
;;
status)
echo -n "Checking for service $NAME "
## Check status with checkproc(8), if process is running
## checkproc will return with exit status 0.
SUSE Linux Enterprise Serverstratup scripts# Return value is slightly different for the status command:
# 0 - service up and running
# 1 - service dead, but pid file exists
# 2 - service dead, but /var/lock/ lock file exists
# 3 - service not running (unused)
# 4 - service status unknown :-(
# 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.)
# NOTE: checkproc returns LSB compliant status values.
/sbin/checkproc -p $ZABBIX_PID $ZABBIX_BIN
# NOTE: rc_status knows that we called this init script with
# "status" option and adapts its messages accordingly.
rc_status -v
;;
probe)
## Optional: Probe for the necessity of a reload, print out the
## argument to this init script which is required for a reload.
## Note: probe is not (yet) part of LSB (as of 1.9)
test $ZABBIX_CONFIG -nt $ZABBIX_PID && echo reload
;;
*)
echo "Usage: $0 {start|stop|status|try-restart|restart|force- reload|reload|probe}"
exit 1
;;
esac
rc_exit

To use these scripts, place them in /etc/init.d and create appropriate symlinks in /usr/sbin as root:

# ln -s /etc/init.d/zabbix_server /usr/sbin/rczabbix_server
# ln -s /etc/init.d/zabbix_agentd /usr/sbin/rczabbix_agentd


Now let's try to start our newly created services. Again, as root execute:

# service zabbix_agentd start

Starting zabbix agent daemon done
# service zabbix_server start

Starting zabbix server daemon done

That should get the agent and server started, although there should be no additional output. Note: you can also use other syntax remember those symlinks we just created? You can also use them as:

# rczabbix_agentd start
# rczabbix_server start

Feel free to experiment with other parameters, like stop and restart it should be obvious what those two do.

You can verify whether services are running with the status parameter. For a service that is not running, you would get:

# service zabbix_server status

Checking for service Zabbix server daemon unused

A running service would yield:

# service zabbix_agentd status

Checking for service Zabbix agent daemon running

There's also another parameter called probe. This will check whether the corresponding service has been restarted since the last configuration file changes. If it has been restarted, no output will be produced. If the service has not been restarted (thus possibly missing some configuration changes), the string reload will be output.

Now that's nice, but we started all this with the goal of adding Zabbix services to system startup. Surely the previous actions didn't help with that? To reach our goal when using SysV-style init systems input the following as root:

# chkconfig -s zabbix_server 35
# chkconfig -s zabbix_agentd 35

This will add both services to be started at runlevels 3 and 5, which are used for multiuser and networked environments (though some distributions might use runlevel 4 instead of 5 for a graphical environment; consult your distribution's documentation when in doubt). There's usually no need to start Zabbix in single user or non-networked runlevels (1 and 2), as data gathering requires network connectivity.

To be fair, with the init scripts we created earlier it is even simpler than that:

# chkconfig -a zabbix_server zabbix_agentd

This will add both services as specified in the corresponding init scripts, which in our case is runlevels 3 and 5, configured by parameter Default-Start. If the command succeeds, you'll see the following output:

zabbix_server 0:off 1:off 2:off 3:on 4:off 5:on 6:off
zabbix_agentd 0:off 1:off 2:off 3:on 4:off 5:on 6:off