MAC OS X, Linux, Windows and other IT Tips and Tricks

13 Sep 14 Installing Shinken in Debian Wheezy

Debian Wheezy does offer the installation of the full (a bit old)shinken, BUT it doesn’t offer the Installation of the WebUI.
Here is a better way to install everything including pnp4nagios and check_mk in one go:

Install Shinken
wget -O /tmp/
cd /tmp && sh

Configure shinken
vim /usr/local/shinken/etc/shinken-specific.cfg
Change the http://YOURSERVERNAME/ in:
define module {
module_name GRAPHITE_UI
module_type graphite_webui
templates_path /usr/local/shinken/share/templates/graphite/

Because of a bug in the stop arbiter script we need to make some tiny changes:
Edit /usr/local/shinken/bin/
change the line
kill $(cat "$DIR"/../var/
kill $(cat "$DIR"/../var/

Unfortunately the process skonf doesn’t want to stop when I run the script: /usr/local/shinken/bin/
So we need to doctor the script:
vim /usr/local/shinken/bin/
Change the following:
kill $(cat "$DIR"/../var/
kill -9 $(ps aux | grep skonf.cfg | grep -v 'grep' | awk '{print $2}')

Start the whole shinken
cd /usr/local/shinken/bin


Change the password of the admin user:
cd /usr/local/shinken/etc/
htpasswd htpasswd.users admin

Now connect to the WebUI

In browser:
To Stop all the services
To de-install shinken
cd /usr/local/shinken/
./install -u

22 Aug 14 Installing Icinga2, pnp4nagios, NRPE Agent and Graphite in Debian Wheezy

Since Icinga2 is not part of the stable version of Debian Wheezy we need to install it from the wheezy-backports. Therefore the following steps are suggested:

Add the backports to the Debian repositories list:
mcedit /etc/apt/sources.list
Add the following lines:
deb wheezy-backports main contrib non-free
deb-src wheezy-backports main contrib non-free

Update the repo db.
apt-get update
Install icinga2 and Graphite from backports
apt-get install -t wheezy-backports icinga2 icinga2-classicui libapache2-mod-wsgi
During the installation the password of Icinga Admin user icingaadmin will be asked to be created.
Give this password 2 times.


(Ref: Based on:
apt-get update && apt-get install --no-install-recommends pnp4nagios rrdcached
update-rc.d rrdcached defaults

We will install PNP with “Bulk mode with NPCD”
icinga2-enable-feature perfdata
Edit the file /etc/pnp4nagios/apache.conf and change the line:
AuthUserFile /etc/nagios3/htpasswd.users
AuthuserFile /etc/icinga2/classicui/htpasswd.users
Edit the file /etc/pnp4nagios/npcd.cfg and make the changes as follows:
#perfdata_spool_dir = /var/spool/pnp4nagios/npcd/
perfdata_spool_dir = /var/spool/icinga2/perfdata

Enable the npcd daemon
Edit /etc/default/npcd and change the Run line to:
update-rc.d npcd defaults
mkdir -p /var/cache/rrdcached
chown nagios: /var/cache/rrdcached

Edit /etc/default/rrdcached and add the following line:
OPTS="-w 1800 -z 1800 -j /var/cache/rrdcached -s nagios -m 0660 -l unix:/var/run/rrdcached.sock"
Put the Apache user www-data into the nagios group
usermod -G nagios www-data
Edit the file /etc/pnp4nagios/config.php and modify these 2 variables:
#$conf['nagios_base'] = "/cgi-bin/nagios3";
$conf['nagios_base'] = "/cgi-bin/icinga";
#$conf['RRD_DAEMON_OPTS'] = '';
$conf['RRD_DAEMON_OPTS'] = 'unix:/var/run/rrdcached.sock';

Edit the file /etc/pnp4nagios/process_perfdata.cfg and change the RRD_DAEMON_OPTS to:
RRD_DAEMON_OPTS = unix:/var/run/rrdcached.sock

Edit the file /etc/icinga2/conf.d/templates.conf and
– Add the following templates at the very beginning of the file:
template Host "pnp-hst" {
action_url = "/pnp4nagios/graph?host=$HOSTNAME$' class='tips' rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=_HOST_"
template Service "pnp-svc" {
action_url = "/pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=$SERVICEDESC$"

– And add the import lines:
In the Host template:
template Host "generic-host" {
max_check_attempts = 5
check_interval = 1m
retry_interval = 30s
check_command = "hostalive"
import "pnp-hst"

In the Services template
template Service "generic-service" {
max_check_attempts = 3
check_interval = 1m
retry_interval = 30s
import "pnp-svc"

Restart All the Daemons
service rrdcached restart
service npcd restart
service icinga2 restart


Install Graphite-Carbon
apt-get install -t wheezy-backports graphite-carbon
Enable the Graphite Module
icinga2-enable-feature graphite
Enable the auto-start of Icinga2
update-rc.d icinga2 defaults
Enable the auto-start of Graphite-Carbon
Edit /etc/default/graphite-carbon
Change the line: CARBON_CACHE_ENABLED=false
Then run: update-rc.d carbon-cache defaults

Graphite WEB Interface

Although Graphite-carbon is part of Wheezy, Graphite-Web is not.
So we need to install it using pip
(Instructions based on:
Install Graphite-Web
apt-get install -y python2.6 python-pip python-cairo python-django python-django-tagging
apt-get install -y libapache2-mod-wsgi python-twisted python-memcache python-pysqlite2 python-simplejson build-essential python-dev
pip install graphite-web

Add the Apache config symlink:
cp /opt/graphite/examples/example-graphite-vhost.conf /opt/graphite/examples/graphite.conf
ln -s /opt/graphite/examples/graphite.conf /etc/apache2/sites-enabled/

Adapt the following Apache configuration to your environment
For Debian you also need to change the following Entry:
FROM: WSGISocketPrefix run/wsgi
TO: WSGISocketPrefix /var/run/apache2/wsgi
Configure Graphite
cd /opt/graphite/conf/
cp dashboard.conf.example dashboard.conf
cp graphTemplates.conf.example graphTemplates.conf
cp graphite.wsgi.example graphite.wsgi

Symlink the Debian Graphite-Carbon data directory to this Graphite-Web installation:
rmdir /opt/graphite/storage/whisper
ln -s /var/lib/graphite/whisper /opt/graphite/storage/whisper

Configure the local settings of Graphite:
cp /opt/graphite/webapp/graphite/ /opt/graphite/webapp/graphite/
Edit the file /opt/graphite/webapp/graphite/
and change the following settings:
Change the following lines FROM:


Note:Activate and adapt other values as you see appropriate. Like:
TIME_ZONE = 'Europe/Berlin'

Finish the Graphite-Web installation process
cd /opt/graphite/webapp/graphite
python syncdb

You’ll be presented with the following question:
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no):

Answer no.
Now you might get some error message but for now they should be ignored.
The administrator account will be created later.

Make the data area writable by Apache user (www-data)
chown -R www-data:www-data /opt/graphite/storage/

Configure Graphite-Carbon to receive Icinga data properly
Edit the file: /etc/carbon/storage-schemas.conf
Add the following lines:
pattern = ^icinga\..*\.(max_check_attempts|reachable|current_attempt|execution_time|latency|state|state_type)
retentions = 5m:7d
# intervals like PNP4Nagios uses them per default
pattern = ^icinga\.
retentions = 1m:2d,5m:10d,30m:90d,360m:4y

Make a fix of graphite carbon:
Otherwise the start of carbon gives the following error:
‘ImportError: cannot import name daemonize’
pip install daemonize
vim /usr/lib/python2.7/dist-packages/carbon/

And change the line:
from twisted.scripts._twistd_unix import daemonize
import daemonize

Start Graphite-Carbon daemon
service carbon-cache start
Reload Apache2 configurations
service apache2 reload

Access the Icinga admin web interface via:
Name: icingaadmin
Password: (admin password you created during installation)

Access the Graphite graphs via: Is the Name of ‘ServerName’ config in /opt/graphite/examples/graphite.conf

Configure a SuperAdmin for enabling saving Graphite graphs.
cd /opt/graphite/webapp/graphite
export LC_ALL=en_GB.UTF-8
export LANG=en_GB.UTF-8
python createsuperuser

And give the new administrator credentials.

Saving graphs in graphite:
In order to be able to save graphs in Graphite-Web you need to:
– login as administrator on the graphite-web interface with the URL:
– Create new user(s) (give access rights in thier profile)
– Login in the graphite-web as one of the users created.
– A new Disk button will appear on top left of the Graph composer window.

Using the Nagios/Icinga agent NRPE

Note: Icinga is happy to use the regular method of calling nagios scripts, in the remote monitored server, by using the SSH command. BUT in case you blocked this port, in whatever manner, I suggest using the NRPE agent which listens on port 5666 and is dedicated for monitoring only.
This installation is to be repeated in each server you wish to monitor.
apt-get install nagios-nrpe-server nagios-plugins sudo
The following package is recommended to make tests locally of the configured NRPE daemon:
apt-get install nagios-nrpe-plugin
To allow some commands that require being root, you allow the user nagios running the scripts contained in in the nagios /usr/lib/nagios/plugins/
WARNING: In some systems this might pose a security problem. So be careful when using this method.
nagios ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/
Edit the NRPE configuration file /etc/nagios/nrpe_local.cfg and add the following entry:
Note: If you have a firewall make sure the port 5666 is open, otherwise you can change the port in this same file as desired.
If your monitored server has more than one network interface, it might be wise to limit the connection to only one interface through which the connection from Icinga2 server is made,. Otherwise do not use this entry and nrpe daemon will bind to all interfaces.
This is the address of the interface NRPE should bind to.
Tip: For testing locally the nrpe commands you can:
– set the above server_address=
– restart the nrpe daemon(service nagios-nrpe-server restart)
– and use the following command format to test any nrpe command:
/usr/lib/nagios/plugins/check_nrpe -H ........
And the most important setting is to limit the NRPE connections to the Icinga server by configuring this entry.
If you have 2 or more servers that should be allowed to talk to NRPE, delimit them with a comma.

Calling NRPE

It is recommended to always add the localhost( in order to be able to test the NRPE commands locally for debug purposes.
Each command you want to call from Icinga2 has to be entered here. The command arguments can be fixed like the following:
command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200

If you want to control the WARNING, CRITICAL levels and other arguments from Icinga when calling the nrpe command, then use the following method:
In this case remember to add the following entry in the configuration file:
command[check_users]=/usr/lib/nagios/plugins/check_users -w $ARG1$ -c $ARG2$
command[check_load]=/usr/lib/nagios/plugins/check_load -w $ARG1$ -c $ARG2$
command[check_disk]=/usr/lib/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
command[check_procs]=/usr/lib/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$

Note: Take a look at the commands provided by the installed packages in the directory /usr/lib/nagios/plugins/ and enter the ones you will need for monitoring this server.
So resume, a sample of my NRPE server configuration(/etc/nagios/nrpe_local.cfg):
# Do any local nrpe configuration here
command[check_users]=/usr/lib/nagios/plugins/check_users -w $ARG1$ -c $ARG2$
command[check_load]=/usr/lib/nagios/plugins/check_load -w $ARG1$ -c $ARG2$
command[check_disk]=/usr/lib/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
command[check_procs]=/usr/lib/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
........ (a long list of commands are listed here)

In the above configuration I’m using the internal LAN to connect from the Icinga2 server ( to all of my servers to be monitored. To make temporary tests locally, the server_address needs to be changed to, restart the nrpe daemon(service nagios-nrpe-server restart) and use the /usr/lib/nagios/plugins/check_nrpe command with arguments as above to test the local nrpe daemon. When finished, revert to the proper binding address of server_address.

When finished restart NRPE:
service nagios-nrpe-server restart

Compiling NRPE from sources

If you find the distribution package of NRPE too old and want to compile your own do the following:
– Install the Debian nagios-nrpe-server and nagios-nrpe-plugin as shown above
– Compile and overwrite the Debian nrpe binaries with the following commands.
mkdir -p /usr/src/NRPE
cd /usr/src/NRPE
tar fvxz nrpe-2.15.tar.gz
cd nrpe-2.15
./configure --with-ssl-lib=$(dpkg -L libssl1.0.0 | grep libcrypto | cut -d/ -f1,2,3,4)

Installing the daemon and the check plugin:
cp src/nrpe /usr/sbin/
cp src/check_nrpe /usr/lib/nagios/plugins/

Testing the local NRPE daemon locally with an example command:
/usr/lib/nagios/plugins/check_nrpe -H -c check_disk -a 15 17 /
Example of proper Result:
DISK OK - free space: / 17576 MB (91% inode=94%);| /=1557MB;20143;20141;0;20158

Icinga server configuration for issuing remote NRPE commands

To be continued ……

Note: In order to make sure you are installing only Icinga2 etc. from backports and leave all other packages to stable version in future installations, after installation of Icinga2 just comment out the above added backport lines in /etc/apt/sources.list and update the repo. db again (apt-get update).

Happy Monitoring!!

05 May 14 Testing internet speed on Linux command line

This small script does a fairly good Upload/download speed test of your Internet connection:
Note: This is a Python script. So you’ll need first to make sure you have Python installed in your system.

Get the script:
wget -O speedtest-cli

Make it runnable
chmod +x speedtest-cli

Run it

Have fun

30 Jan 14 Benchmark your IO in Debian Servers

In order to have a better idea of what is the IO performance on an Internet server here is a small tool that would make relative good IO(disk performance) tests.
apt-get install iozone3
iozone -I -T -t 5 -r 64k -s 2G -i 0 -i 1 -i 2 -c -e

The results are easy to read.

Here is another example brought by a friend:
iozone -I -i 0 -R -l 3 -u 3 -r 16k -s 10000m -F /mnt/DATA/io1 /mnt/DATA/io2 /mnt/DATA/io3
This one I use for write Tests only. It creates 3 files around 10G each and only writes them. Record size is 16k this Time and it uses direct-io for the operation.

15 Dec 12 Installing ISTATD on Debian Squeeze/Wheezy

This HOW-TO is almost completely based on the README.txt file included in ISTATD package I included some adaptation notes.

istatd is a daemon serving statistics to your iStat iPhone application from Linux, Solaris & FreeBSD.
istatd collects data such as CPU, memory, network and disk usage and keeps the history.
Once connecting from the iPhone and entering the lock code this data will be sent to the iPhone and shown in fancy graphs.

What is iStat for iPhone?

iStat is a iPhone application developed by Bjango (
With iStat you can remotely monitor CPU, memory, disks, uptime and load averages from any Mac, Linux or Solaris computer from your iPhone.
You can find the latest version at:
You can download iStat for iPhone in iTunes App Store.

How to install
These steps assume you are logged in as root and have GNU build tools installed together with libxml2.

1) Download istatd-0.5.8.tar.gz

2) Extract tar ball
tar -xvf istatd-0.5.8.tar.gz
3) Install dependencies
istatd requires GNU build tools, libxml2 and libxml2-devel.
apt-get install libxml2-dev build-essential
4) Build istatd
cd istatd-0.5.8
Here you can configure where you want your binary and config to end up (default /usr/local).
./configure --prefix=/ --sysconfdir=/etc
# Build it
make && make install

5) Add user and configure directories
useradd istat
mkdir -p /var/{run,cache}/istat
chown istat.istat /var/{run,cache}/istat

Make a symlink to /etc/istat.conf
ln -s /usr/local/etc/istat.conf /etc/istat.conf
6) Configure your config to match your needs and system
Note: Don’t forget to change your server_code.
vim /etc/istat.conf
7) Fire it up
/usr/bin/istatd -d

7) Make sure it always starts at boot time
For this we will create an init script (/etc/init.d/istatd) and include it to most runlevels
Script suggested:

#! /bin/sh
# Provides: istatd
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Server Monitoring agent for iStat on iPhone
# Description: Uses port 5109 to monitor basic system status for the iPhone iStat app
# placed in /etc/init.d.
# Author: Michel Bisson(michelATlinuxintDOTcom)
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the script
DESC="iStat system monitoring agent for iPhone"
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
# Function that starts the daemon/service
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
# Function that stops the daemon/service
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
# Function that sends a SIGHUP to the daemon/service
do_reload() {
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
case "$1" in
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#log_daemon_msg "Reloading $DESC" "$NAME"
#log_end_msg $?
# If the "reload" option is implemented then remove the
# 'force-reload' alias
log_daemon_msg "Restarting $DESC" "$NAME"
case "$?" in
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
# Failed to stop
log_end_msg 1
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3

Make the script runnable and include it in boot sequence
chmod 755 /etc/init.d/istatd
update-rc.d istatd defaults

Start it manually for now.
(it will start automatically on reboot)
/etc/init.d/istatd start

NOTE: You can change the default port(5109) in /etc/istatd.conf, then make sure you open that port in your firewall.

24 Jun 11 Installing CACTI and Templates on Debian Lenny/Squeeze

In the area of monitoring systems using GPL software Nagios is a big player but the organization of
displaying the history graphs is not so ideal.
Zabbix is wonderful as well, it produces also good graphs but it creates them dynamically, resulting
in a long wait time when we need to display a large amount of them at once. To achieve this Cacti
is one of the best GPL History-Graphs-Only monitoring program out there.
I have put together here a step-by-step HOWTO to help setting-up some of the most important items to be monitored in a short time. Although the theme says to use ‘Lenny’ the same should apply to Squeeze with very minor modification if any.

The difficulty with the version of Cacti provided with Debian Lenny/Squeeze is that it’s outdated.
I tried to install the latest version of Cacti and somehow got into some difficulties which
I felt I didn’t want to bother solving. I knew there was a faster solution to this and didn’t have the time
to do troubleshooting.

The fast solution is to install the regular (and outdated) Debian version of Cacti
and then replace its components with the latest version(0.8.7.g).
For later versions, simply replace the version number where applied. So here is how I did it:

Install the Debian Lenny/Squeeze version

apt-get install cacti
Note: Please make sure you complete the whole installation especially concerning the creation of the Mysql Database.

Download the current Cacti version

(at the time of this article the version 0.8.7g was the latest one.)

Put the Debian Cacti files aside to leave space to the new one.

mv /usr/share/cacti /usr/share/cacti_Debian

Prepare space for the new version

mkdir -p /usr/share/cacti-0.8.7g

Install the new version with the same directory structure as with the Debian version

tar fvxz cacti-0.8.7g.tar.gz -C /usr/share/cacti-0.8.7g/
mv /usr/share/cacti-0.8.7g/cacti-0.8.7g /usr/share/cacti-0.8.7g/site
ln -s /usr/share/cacti-0.8.7g /usr/share/cacti
mv /usr/share/cacti-0.8.7g/site/rra /usr/share/cacti-0.8.7g/site/rra_orig
ln -s /var/lib/cacti/rra /usr/share/cacti-0.8.7g/site/rra
ln -s /usr/share/cacti-0.8.7g/site/resource /usr/share/cacti-0.8.7g/resource

Get a copy of the config.php from Debian version

This php file refers to the configuration file /etc/cacti/debian.php as installed by the original Debian version.
mv /usr/share/cacti/site/include/config.php /usr/share/cacti/site/include/config.php.orig
cp /usr/share/cacti_Debian/site/include/config.php /usr/share/cacti/site/include/config.php

Restart your web server

/etc/init.d/apache2 restart

Upgrade to the new cacti
and simply follow the on screen instructions to upgrade to the new version.

1) Debian Lenny/Squeeze uses the SNMP protocol Ver. 2.0 therefore make sure you do
configure the correct version in the cati web interface.

2) For better compatibility, in the /etc/snmp/snmpd.conf I used only the following configuration:
com2sec readonly default public
group MyROSystem v1 paranoid
group MyROSystem v2c paranoid
group MyROSystem usm paranoid
group MyROGroup v1 readonly
group MyROGroup v2c readonly
group MyROGroup usm readonly
group MyRWGroup v1 readwrite
group MyRWGroup v2c readwrite
group MyRWGroup usm readwrite
view all included .1 80
view system included
access MyROSystem "" any noauth exact system none none
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none
syslocation Unknown (configure /etc/snmp/snmpd.local.conf)
syscontact Root (configure /etc/snmp/snmpd.local.conf)
Restart SNMPD Daemon
/etc/init.d/snmpd restart
Testing the SNMP configuration on the monitored system
snmpwalk -Os -c public -v 1 localhost system
3) I prefer to use the UDP Ping instead of the SNMP Ping for finding out if the server is available. This way if the SNMP service dies in the monitored host I get the proper information regarding if the monitored host died or not.

4) In our case, since we are going to get all sorts in information from the system where the user snmp is not allowed, we need to run the snmpd daemon as ‘root’ instead as ‘snmp’. To do this do the following changes:
vim /etc/default/snmpd
snmpd options (use syslog, close stdin/out/err).
SNMPDOPTS='-Lsd -Lf /var/log/snmpd.log -u root -I -smux -p /var/run/,'
Note: You also need to include the IP of the interface from where the monitoring server will be making its queries. In the above SNMPDOPTS settings, both interfaces having the IPs and will accept snmp queries. If any of the connected to the internet, make sure the /etc/hosts.allow/ & /etc/hosts.deny are correctly configured as follows:

Allowing the monitoring server acccess to snmpd daemon
In /etc/hosts.allow
Making sure all other hosts are denied access
In /etc/hosts.deny
snmpd: ALL

Installing some cacti templates

Apache statistics

In the monitored hosts
Make sure that in the client host you configure Apache for extended server-status and if needed configure the access control to accept the monitoring server where cacti runs.

In the monitoring server
– Download the apache template locally in desktop from
– Import the template in Cacti interface
– Login as root:
cd /usr/share/cacti/site/scripts

Postfix queues

In the monitored host:
– download the postfix queues script in to /usr/local/bin/
cd /usr/local/bin/
chmod 755 /usr/local/bin/

Add the necessary SNMP configuration and restart
echo 'extend . mailq /usr/local/bin/' >> /etc/snmp/snmpd.conf
/etc/init.d/snmpd restart

Testing the script in the monitored host:
/usr/bin/snmpwalk -Oav -v2c -c public . | cut -d'"' -f2
You should get an output similar to this:
incoming:0 active:0 deferred:6 hold:0
In the monitoring server:
Log into the monitoring server and get the data query script
cd /usr/share/cacti/site/scripts
chmod 755 /usr/share/cacti/site/scripts/

Download and Import the template in cacti interface

Postfix statistics

In the monitored host
Download the postfix stats script in to /usr/local/bin/
cd /usr/local/bin/
chmod 755 /usr/local/bin/

Add the necessary SNMP configuration and restart
echo 'pass . /usr/local/bin/ /var/log/mail.log /var/log/mailstats.db .' >> /etc/snmp/snmpd.conf
/etc/init.d/snmpd restart

Testing the script on the monitored host:
/usr/bin/snmpwalk -Oav -v2c -c public .
You should get an output similar to this:
Output Description
============= ====================================
INTEGER: 25 Received
INTEGER: 58 Deferred (Saved and to be resent later)
INTEGER: 0 Bounced (Bounced back)
INTEGER: 293 Rejected (Total rejected mails)
INTEGER: 15 Clean
INTEGER: 188 Pspam (Possible SPAM GreyListed)
INTEGER: 287 Spam (RBL and spammassassin Blocked)
INTEGER: 0 Infected (Blocked Virus)
INTEGER: 1 Bad Header
INTEGER: 1 Banned (Banned content)

In the Monitoring server (Via cacti web interface)
Download and Import the host template in cacti interface

DISK IO statistics

In the monitored host:
Download the DISK IO stats script into /usr/local/bin/
cd /usr/local/bin/
chmod 755 /usr/local/bin/snmpdiskio

Add entries to /etc/snmp/snmpd.conf
echo 'extend . hdNum /usr/local/bin/snmpdiskio hdNum' >> /etc/snmp/snmpd.conf
echo 'extend . hdIndex /usr/local/bin/snmpdiskio hdIndex' >> /etc/snmp/snmpd.conf
echo 'extend . hdDescr /usr/local/bin/snmpdiskio hdDescr' >> /etc/snmp/snmpd.conf
echo 'extend . hdInBlocks /usr/local/bin/snmpdiskio hdInBlocks' >> /etc/snmp/snmpd.conf
echo 'extend . hdOutBlocks /usr/local/bin/snmpdiskio hdOutBlocks' >> /etc/snmp/snmpd.conf

Restart snmpd service
/etc/init.d/snmpd restart
Testing the data query on the monitored host:
/usr/bin/snmpwalk -Oav -v2c -c public .
/usr/bin/snmpwalk -Oav -v2c -c public .
/usr/bin/snmpwalk -Oav -v2c -c public .
/usr/bin/snmpwalk -Oav -v2c -c public .
/usr/bin/snmpwalk -Oav -v2c -c public .

In the Monitoring server:
Install the needed xml file
mkdir -p /usr/share/cacti/extras
cd /usr/share/cacti/site/resource/
ln -s /usr/share/cacti/site/resource/snmp_queries/partition.xml /usr/share/cacti/extras/partition.xml

Download on local desktop and import the host template using the Cacti web interface

Advanced MySQL statistics

In the monitored host:
– Create a special user for monitoring in MySQL server with the same username and password for all monitored hosts
– This user must have the SUPER_Privilege only
– Use ‘PASSWORD’ type and NOT MD5 or something else

Make sure the mysql server binds to ALL network interfaces:
Edit /etc/mysql/my.cnf
#bind-address =
bind-address =

Protect the mysql server from Internet access using a firewall or the /etc/hosts.allow & /etc/hosts.deny as follows:
Allowing the monitoring server acccess to snmpd daemon
In /etc/hosts.allow
Making sure all other hosts are denied access
In /etc/hosts.deny
mysqld: ALL
In the Monitoring server:
Download and install the php script
cd /usr/share/cacti/site/scripts/
ln -s /usr/share/cacti/site/scripts/ss_get_mysql_stats.php /usr/share/cacti/extras/

Edit the name and password in /usr/share/cacti/site/scripts/ss_get_mysql_stats.php
$mysql_user = 'monitor';
$mysql_pass = 'monitor';

Download on desktop and Import the host template using the cacti web interface

TeMySQL statistics

In the monitored host:
– Create a special user for monitoring in MySQL server with the same username and password for all monitored hosts
– This user must have the SUPER_Privilege only
– Use ‘PASSWORD’ type and nothing else

Make sure the mysql server binds to ALL network interfaces:
Edit /etc/mysql/my.cnf
#bind-address =
bind-address =

Protect the mysql server from Internet access using a firewall or the /etc/hosts.allow & /etc/hosts.deny as follows:

Allowing the monitoring server acccess to snmpd daemon
In /etc/hosts.allow
Making sure all other hosts are denied access
In /etc/hosts.deny
mysqld: ALL
In the Monitoring server:
Download and install the php scripts
cd /usr/share/cacti/site/scripts/
ln -s /usr/share/cacti/site/scripts/mysql_stats.php /usr/share/cacti/extras/

Download on desktop and Import the host template in cacti interface

During the creation of teMysql graphs in each device, enter the name and password of the mysql user configured in the monitored host for this purpose.
Name: monitor
PW: monitor

Network statistics

In the monitoring server:
Log into the monitoring server and get the data query script
cd /usr/share/cacti/site/scripts
chmod 755 /usr/share/cacti/site/scripts/
ln -s /usr/share/cacti/site/scripts/ /usr/share/cacti/extras/

Download and Import the template using the cacti web interface

Advanced Ping

In the monitoring server:
Log into the monitoring server and get the data query script:
cd /usr/share/cacti/site/scripts
ln -s /usr/share/cacti/site/scripts/ss_fping.php /usr/share/cacti/extras/

Download and Import the template in cacti interface

SNMP Disk Usage

In the monitoring server:
Log into the monitoring server and get the query xml file
cd /usr/share/cacti/site/resource/snmp_queries/
ln -s /usr/share/cacti/site/resource/snmp_queries/hrStorageTable.xml /usr/share/cacti/extras/

Download and Import the template in cacti interface

HTTP Response Time

In the monitoring server:
Log into the monitoring server and get the script file
cd /usr/share/cacti/site/scripts
ln -s /usr/share/cacti/site/scripts/ /usr/share/cacti/extras/

Download and Import the template using cacti web interface

NOTE: If by any chance you get no graphs created after a good 10 minutes then look at this solution:
Click on ‘Graph Management’, Click on one of the ‘HTTP Response Time ‘ graphs links and if you get no graph and the ‘RRDTool Says:’
ERROR: the RRD does not contain an RRA matching the chosen CF
Then the following might be the reason:
You are using (the Graph Template includes) the LAST consolidation function.
But your RRA definitions do not include this CF.
Edit RRAs when clicking onto “Data Sources”, then select “RRAs”
and edit all of them to add “LAST” CF
Then, you’ll have to re-create the failing rrd file
By deleting the graph from Graph management and under each device create the graph again.

PostGres Statistics

PostGres Data Base Cacti templates:
Installation instruction:
1. Make sure you have enabled Statistic Collector in Postgres (postgresql.conf)

Till postgres 8.2
stats_start_collector = true
stats_command_string = true
stats_block_level = true
stats_row_level = true
stats_reset_on_server_start = false

From postgres 8.3
track_activities = on
track_counts = on
update_process_title = on

Also in this configuration file:
Make sure PostGresql server listens to the interfaces that will be used for connections:
Here you give the IP of the server’s local interfaces.
listen_addresses = ','
2. Edit the access rights file /etc/postgresql/8.3/main/pg_hba.conf
Then make sure the clients will be allowed in via the same interface Postgres is listening on above:
Add the access rights line:
host all all md5

3. Create new User in PostgreSQL ,for example ‘monitor’
(you don’t have to grant any special roles to this users AFAIK, any user has access to Statistic Tables).
su - postgres
createuser --pwprompt --encrypted --no-adduser --no-createdb monitor

– Enter password for new role: monitor
– Enter it again: monitor
– Shall the new role be allowed to create more new roles? (y/n) n

4. Try to connect remotely under this user to postgres Database:
psql -h YOUR_POSTGRES_HOST -U monitor -W postgres
and try execute following SQL:
select * from pg_stat_all_tables;
If everything work proceed with installation otherwise fix your problem till you get results.

5.In monitoring server:
cd /usr/share/cacti/site/scripts
cd /usr/share/cacti/site/resource/script_queries

Description of templates.
pgsql_stats.php - the Script, put this in /scripts/
postgres_dbstat.xml - the Definition, put this in /resource/script_queries
cacti_data_query_postgresql_database_stats.xml - Data Query + Graphs - import into Cacti

6. Install the debian package ‘php-pgsql’
apt-get install php5-pgsql
/etc/init.d/apache2 restart

7. Download and Import the template using cacti web interface

8. Edit pgsql_stats.php line 173 and 174 and put username and password you have created at point 1.
(I don’t know how to pass username and password parameters to Data Queries. If you know how,
let me know so I can remote username and password from script)

9. Edit your Host Template or Device and add PostgreSQL Database Stats in Data Queries.

10. Create your Graphs đŸ™‚

My Processes

Note: this self made cacti monitoring template does the monitoring of the number of processes per specific services as follows:
OUTPUT example:
allprocs:226 apache2:12 mysqld:19 mysqld2:0 bash:1 gpg:0 pop3:3
Its called : MyProcessesMGT2 in the monioring list

In the monitoring server:
– get the script file
cd /usr/share/cacti/site/scripts
chmod 755 /usr/share/cacti/site/scripts/

Make sure the user www-data on the monitoring server can run via ssh without password the script /usr/share/cacti/site/scripts/
Commands in monitoring server:
mkdir /home/www-data
usermod -d /home/www-data -s /bin/bash www-data
chown www-data. /home/www-data
su - www-data
ssh-keygen -t rsa
(just press Enter key at every question)

In each monitored hosts:
-Modify the user www-data in each monitored hosts, create a home directory for it
-Commands in monitored hosts:
mkdir /home/www-data
usermod -d /home/www-data -s /bin/bash
chown www-data. /home/www-data
passwd www-data

(Give 2 times the password ‘www-data’ (no worry it will be deleted right after we are finished)

When all monitored hosts are modified as above then go back to the monitoring server
Commands in monitoring server:
su - www-data (only if not already logged-in as www-data)
ssh-copy-id clientHost_1_Name (Give the 'www-data' password)
ssh-copy-id clientHost_2_Name "" "" ""
ssh-copy-id clientHost_3_Name "" "" ""

Try the connection
IMPORTANT: use the same hostname exactly as it is given as hostname in cacti for every monitored host here as clientHost_1_Name. If you get a question like:
Are you sure you want to continue connecting (yes/no)?
Answer ‘yes’.
ssh clientHost_1_Name (if all ok then CTRL-D to exit the session on this remote host)
ssh clientHost_2_Name (if all ok then CTRL-D to exit the session on this remote host)
ssh clientHost_3_Name (if all ok then CTRL-D to exit the session on this remote host)

Disable all password of www-data in all monitored hosts
Make sure you are back loggged in as ‘root’
Commands in all monitored hosts:
ssh clientHost_1_Name sed -i 's/www-data:/www-data:*/' /etc/shadow
ssh clientHost_2_Name sed -i 's/www-data:/www-data:*/' /etc/shadow
ssh clientHost_3_Name sed -i 's/www-data:/www-data:*/' /etc/shadow

Download and Import the template in cacti interface:

22 May 10 Installing Zabbix 2.2.6 on Debian Squeeze

Debian Squeeze has still the Zabbix 1.8.2, if you want the install the 2.2.6, then one solution is to follow these instructions, the other is to do the hard work all the way(not shown here :-):

The easy way:

Zabbix has now Binary packages ready for Debian Wheezy to install:
Steps for version 2.2.6:
dpkg -i zabbix-release_2.0-1wheezy_all.deb

Edit /etc/apt/sources.list.d/zabbix.list and replace the 2.0 for 2.2 as follows:
deb wheezy main
deb-src wheezy main

Update the DPKG db:
apt-get update
Now find out which packages are available and install the one you need:
apt-cache search zabbix
To install the server:
apt-get install zabbix-server-mysql
To install the agent (should be installed in every Server to monitor)
apt-get install zabbix-agent
Edit the configuration file and add the IP address of the host where the Zabbix server runs:
vim /etc/zabbix/zabbix_agentd.conf

Note: You can also download each package individually from this URL:

In order to monitor some extra things in the target servers, you can do it by expanding the functionality of the zabbix-agent as follows:
Example to monitor Apache’s activities:
apt-get install libwww-perl
Edit /etc/zabbix/zabbix-agentd.conf and add the following lines at the end of the file:
# Note: make sure: apt-get install libwww-perl' otherwise you may get : Can't locate LWP/
UserParameter=apache2.total_accesses,/etc/zabbix/|cut -f1 -d":"
UserParameter=apache2.total_kbytes,/etc/zabbix/|cut -f2 -d":"
UserParameter=apache2.cpuload,/etc/zabbix/|cut -f3 -d":"
UserParameter=apache2.uptime,/etc/zabbix/|cut -f4 -d":"
UserParameter=apache2.reqpersec,/etc/zabbix/|cut -f5 -d":"
UserParameter=apache2.bytespersec,/etc/zabbix/|cut -f6 -d":"
UserParameter=apache2.bytesperreq,/etc/zabbix/|cut -f7 -d":"
UserParameter=apache2.busyworkers,/etc/zabbix/|cut -f8 -d":"
UserParameter=apache2.idleworkers,/etc/zabbix/|cut -f9 -d":"
UserParameter=apache2.totalworkers,/etc/zabbix/|cut -f10 -d":"

Script needed for this above extension to function:
Save it as /etc/zabbix/
## Versions 0.99
## Updates here:
use LWP::Simple;
use strict;
my($total_accesses,$total_kbytes,$cpuload,$uptime, $reqpersec,$bytespersec,$bytesperreq,$busyworkers, $idleworkers,$totalworkers);
if (! $server_status) {
print "Can't access $url\nCheck apache configuration\n\n";
$total_accesses = $1 if ($server_status =~ /Total\ Accesses:\ ([\d|\.]+)/ig)||0;
$total_kbytes = $1 if ($server_status =~ /Total\ kBytes:\ ([\d|\.]+)/gi);
$cpuload = $1 if ($server_status =~ /CPULoad:\ ([\d|\.]+)/gi);
$uptime = $1 if ($server_status =~ /Uptime:\ ([\d|\.]+)/gi);
$reqpersec = $1 if ($server_status =~ /ReqPerSec:\ ([\d|\.]+)/gi);
$bytespersec = $1 if ($server_status =~ /BytesPerSec:\ ([\d|\.]+)/gi);
$bytesperreq = $1 if ($server_status =~ /BytesPerReq:\ ([\d|\.]+)/gi);
$busyworkers = $1 if ($server_status =~ /BusyWorkers:\ ([\d|\.]+)/gi);
$idleworkers = $1 if ($server_status =~ /IdleWorkers:\ ([\d|\.]+)/gi);
$totalworkers = $busyworkers + $idleworkers;
printf "%i:%i:%.2f:%i:%.2f:%.2f:%.2f:%i:%i:%i\n",$total_accesses,$total_kbytes,$cpuload,$uptime,$reqpersec,$bytespersec,$bytesperreq,$busyworkers,$idleworkers,$totalworkers;

# Make the script runnable
chmod 755 /etc/zabbix/
IMPORTANT: For this script to work you need to make sure you Apache is configured to deliver a full Extended status with the URL:

Configuration in Zabbix-server:
In Zabbix server interface you create a new item in the ‘linux’ template as follows:

The hard manual way

Using the source code and manually compile it.
For convenience, we install the Debian’s older Zabbix version and then do the updating and modifications necessary.
Note 1: Zabbix authors are saying that older zabbix-agent daemon (like with Debian) is compatible with the new Zabbix Server, therefore it should not be necessary to update the agent. BUT my experience is that the newer agent brings definitely improvements specially in special remote commands controls. So I suggest you always use the same version for agent and the server.

– Install the regular Zabbix packages from Debian repository and some extra needed packages for the compiling of Version 2.2.4:
apt-get install zabbix-agent zabbix-frontend-php zabbix-server-mysql build-essential libmysqlclient15-dev libcurl4-openssl-dev libsnmp-dev snmp snmpd php5-mysql
pkg-config autoconf automake

– Download the new Zabbix 2.2.6 source:
mkdir -p /root/src/zabbix
cd /root/src/zabbix

– Untar the file:
tar fvxz zabbix-2.2.6.tar.gz
cd zabbix-2.2.6

– Run the configure command:
Note: if any error occur, look through apt-cache search commands to find the missing -dev packages, and re-run the following configure command till it goes to the end successfully.
At the end it will present you with the configuration parameters ready to be compiled:
./configure --enable-server --enable-agent --with-mysql --with-libcurl --with-net-snmp
– If all OK then compile it:
(This will compile and install Zabbix binaries in /usr/local/bin, /usr/local/sbin, /usr/local/etc)
make install
Note: Make sure you have got pkg-config and autoconf installed and run the command ‘autoreconf -fi’, or you will receive an error like this:
./configure: line 8092: syntax error near unexpected token `IKSEMEL,iksemel,'
FRONT END(Web interface)
– Rename or delete the installed Debian zabbix front end PHP files:
mv /usr/share/zabbix /usr/share/zabbix.debian
– Copy recursively the PHP frontend files into the original:
mkdir /usr/share/zabbix/
cp -a ./frontends/php/* /usr/share/zabbix/

Rename and edit the Zabbix front end configuration file and enter the correct parameters for Mysql access.
mv /usr/share/zabbix/conf/zabbix.conf.php.example /usr/share/zabbix/conf/zabbix.conf.php
vim /usr/share/zabbix/conf/zabbix.conf.php

Make the front-end configuration directory writable by Apache user(www-data)
(Needed only for the initial configuration via the front-end)
chown -R www-data /usr/share/zabbix/conf
Add the recommended (but optional)following entries in /etc/services:
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper

– Create a new MySQL user called zabbix (incl. his password) and give the full access rights of database zabbix to this zabbix user. (in table: db)

– Reload the databases access rights through the SQL command:

– Create a database called zabbix (or delete the old one and create a new one) in MySQL: (using mysql client or phpMyAdmin)
Bash shell> mysql -u'username' -p'password'
mysql> create database zabbix character set utf8;
mysql> quit;
Bash shell> cd create/schema
Bash shell> cat mysql.sql | mysql -u'username' -p'password' zabbix
Bash shell> cd ../data
Bash shell> cat data.sql | mysql -u zabbix -p'password' zabbix
Bash shell> cat images_mysql.sql | mysql -u zabbix -p'password' zabbix

– Start the zabbix frontend through the browser and follow the instructions for installation.
You might have to change some PHP parameters in /etc/php5/apache2/php.ini to match the

– Modify the above init scripts by changing the binary files paths to:
/etc/init.d/zabbix-server: DAEMON=/usr/local/sbin/zabbix_server
/etc/init.d/zabbix-agent: DAEMON=/usr/local/sbin/zabbix_agentd

Replace the Debian Zabbix Server config file:
mv /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.debian
ln -s /usr/local/etc/zabbix_server.conf /etc/zabbix/zabbix_server.conf

Configure the following zabbix server configuration file regarding the MySQL login data in:
Replace the Debian Zabbix agent config file:
mv /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.debian
ln -s /usr/local/etc/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf

– Make the appropriate changes in the zabbix agent configuration file.
(especially the LogFile, Server and PidFile paramerters)
vim /etc/zabbix/zabbix_agentd.conf

Start both the daemons:
/etc/init.d/zabbix-server start
/etc/init.d/zabbix-agent start

Go to the web interface and try to login as ‘admin’
Note: If you have difficulties logging in as ‘admin’, you might want to change the alias of the administrator to ‘admin’ and his password in MD5 format using phpMyAdmin in the table: ‘users’.
In case of more difficulties you might want to check this link:

– That should be it. Continue everything else via the web interface.

Compiling and Installing Zabbix agent only on zabbix clients(monitored servers).

Note: Although the documentation says that the older agents are compatible with the new version of zabbix server, I had some quircks that got resolved only when I compiled and installed the latest version of zabbix-agent from sources as follows.
– Install the zabbix-agent and build-essential from Debian:
apt-get install build-essential zabbix-agent
– Stop the zabbix-agent daemon
/etc/init.d/zabbix-agent stop
– Download the new Zabbix 2.2.4 source:
mkdir -p /root/src/zabbix
cd /root/src/zabbix

– Untar the file:
tar fvxz zabbix-2.2.4.tar.gz
cd zabbix-2.2.4
autoreconf -fi

– Run the configure command:
Note: if any error occur, look through apt-cache search commands to find the missing -dev packages, and re-run the following configure command till it goes to the end successfully. At the end it will present you with the configuration parameters ready to be compiled:
./configure --enable-agent
– If all OK then compile it:
(This will compile and install Zabbix binaries in /usr/local/bin, /usr/local/sbin, etc.)
make install
Note: If errors occur, it might be because you are using an already compiled copy of the zabbix source directory. If that is the case, just issue the command:
make clean
make install

– Modify the zabbix-agent start script.
vim /etc/init.d/zabbix-agent
make the following changes on line 10:

– Modify the zabbix-agentd configuration file:
vim /etc/zabbix/zabbix_agentd.conf
Enter the IP of the server.(eg. Zabbix server is having the IP:
If more than one server need to call this agent then add the IP list separated with commas’,’ eg.

– Add the following lines in /etc/services:
zabbix-agent 10050/tcp # Zabbix Agent
zabbix-agent 10050/udp # Zabbix Agent
zabbix-trapper 10051/tcp # Zabbix Trapper
zabbix-trapper 10051/udp # Zabbix Trapper

Replace the Debian Zabbix agent config file:
mv /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.debian
ln -s /usr/local/etc/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf

– Make the appropriate changes in the zabbix agent configuration file.
(especially the LogFile, Server PidFile paramerters)
vim /etc/zabbix/zabbix_agentd.conf

– Start the zabbix-agentd
/etc/init.d/zabbix-agent start

Zabbix web site offers now the latest version of Zabbix server/Agent/Frontend 2.0.5 as Debian package. After downloading the .deb files and tried to install them with the dpkg -i command you will be prompted with an error of missing a package(s). Just install this/these package(s) with apt-get install command and all will be installed automatically. Remember that you need to download and install 3 .deb files fromt the site: the Server, the Agent and the Web Frontend.

Enjoy the monitoring with Zabbix.