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

Slackware


The Slackware Linux distribution (http://www.slackware.com/) uses a simpler startup script system. Here's an example of a script to start and stop the Zabbix server and agent daemon on Slackware systems. This script is dependant on bash, but it shouldn't be too hard to rewrite for sh compatibility, if so desired. Create script /etc/rc.d/rc.zabbix with the following content:

#!/bin/bash
# Init script to start/stop Zabbix server and agent daemon
BINLOCATION=/usr/local/sbin
AGENTPID=/var/tmp/zabbix_agentd.pid
SERVERPID=/var/tmp/zabbix_server.pid
TERMINATEWAIT=5
processcheck() {
[[ "$(ps -C $1 -o pid=)" ]] || return 1
}
# Check for stray pidfiles and remove them
processcheck zabbix_agentd || {
[ -f $AGENTPID ] && ( echo "Removing stray $AGENTPID file"; rm $AGENTPID )
}
processcheck zabbix_server || {
[ -f $SERVERPID ] && ( echo "Removing stray $SERVERPID file"; rm $SERVERPID )
}
killprocess() {
processcheck $2 || {
echo "No process $2 running"
Slackwarescript, creatingreturn
}
if [ -f $1 ]; then
kill -15 $(cat $1)
else
echo "pidfile $1 not found"
processcheck $2 && killall -15 $2
fi
echo -n "Waiting for $2 to terminate"
for i in $(seq 1 $TERMINATEWAIT); do
processcheck $2 || break
sleep 1
echo -n "."
done
processcheck $2 && echo "Warning! $2 did not terminate in $TERMINATEWAIT seconds"
}
zagent_start() {
if [ -x $BINLOCATION/zabbix_agentd ]; then
if processcheck zabbix_agentd; then
echo "Zabbix agent daemon already running"
else
echo "Starting zabbix agent daemon: $BINLOCATION/zabbix_agentd"
$BINLOCATION/zabbix_agentd
fi
else
echo "Executable $BINLOCATION/zabbix_agentd not present"
fi
}
zserver_start() {
if [ -x $BINLOCATION/zabbix_server ]; then
if processcheck zabbix_server; then
echo "Zabbix server already running"
else
echo "Starting zabbix server: $BINLOCATION/zabbix_server"
$BINLOCATION/zabbix_server
fi
else
echo "Executable $BINLOCATION/zabbix_server not present"
fi
}
zagent_stop() {
Slackwarescript, creatingecho "Stopping Zabbix agent daemon"
killprocess $AGENTPID zabbix_agentd
}
zserver_stop() {
echo "Stopping zabbix server"
killprocess $SERVERPID zabbix_server
}
zagent_restart() {
zagent_stop
zagent_start
}
zserver_restart() {
zserver_stop
zserver_start
}
case "$1" in
'start')
case "$2" in
'agent')
zagent_start
;;
'server')
zserver_start
;;
*)
zagent_start
zserver_start
;;
esac
;;
'stop')
case "$2" in
'agent')
zagent_stop
;;
'server')
zserver_stop
;;
*)
zagent_stop
zserver_stop
;;
esac
;;
'restart')
case "$2" in
'agent')
zagent_restart
Slackwarescript, creating;;
'server')
zserver_restart
;;
*)
zagent_restart
zserver_restart
;;
esac
;;
*)
echo "Usage: $0 start|stop|restart [agent|server]"
;;
esac

This script combines agent and server controlling. To start both, execute the following as root:

# /etc/rc.d/rc.zabbix start

To control the server or agent only, pass its name as a second argument. For example:

# /etc/rc.d/rc.zabbix restart server

Adding a script to the system's startup sequence is quite trivial. It's invocation has to be added to the /etc/rc.d/rc.local as follows:

# echo /etc/rc.d/rc.zabbix start >> /etc/rc.d/rc.local

Verifying the service's state

While the init script method is a nice way to check a service's state for some distributions, it's not available everywhere and isn't always enough. Sometimes you might want to check whether the Zabbix server or agent is running with other methods.

  • Checking running processes:

    The most common method to check whether a particular process is running is by looking at running processes. You can verify if Zabbix agent daemon processes are actually running by using the following:

    $ ps -C zabbix_agentd
    
  • netstat output:

    Sometimes, an agent daemon might start up, but fail to bind to the port, or the port might be used by some other process. You can verify whether some other process is listening on the Zabbix port, or whether Zabbix agent daemon is listening on the correct port by issuing:

    $ netstat -ntpl
    
  • Note that process names won't be printed for other users' processes unless you are root. In the output, look for a line looking similar to:

    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 19843/zabbix_agentd
    
  • This indicates that the process zabbix_agentd is running and listening on all addresses, on port 10050, just what we need.

  • Telnetting to the port

    Even when a service starts up and successfully binds to a port, there might be some connectivity issues; perhaps due to a local firewall. To quickly check connectivity to the desired port, you can try:

    $ telnet localhost 10050
    
  • This command should open a connection to the Zabbix agent daemon, and the daemon should not close the connection immediately.