From Sanet

Jump to: navigation, search


Installing requirements

On a Debian 7 system

On a Debian 7 (current as of version 7.4), most requirements are met with the following line:

apt-get install \
subversion \
postgresql \
python-psycopg2 \
redis-server \
python-redis \
rrdtool \
python-rrdtool \
rrdcached \
python-pyparsing \
python-pygraphviz \
python-django \
python-ipaddr \
gcc \
lm-sensors \
libsensors4-dev \
make \
libperl-dev \
python-dev \
python-setuptools \
python-reportlab \
python-pydot \
antlr3 \
libantlr3c-3.2-0 \
libantlr3c-dev \
python-networkx \
python-pisa \
apache2 \
libapache2-mod-wsgi \

Put this line in /etc/defaults/rrdcached:

OPTS="-s www-data -m 775 -l unix:/var/run/rrdcached.sock"

A few packages must be installed by hand. One is net-snmp, debian 7 has an ancient version:

apt-get purge python-pyasn1 python-pynetsnmp python-twisted-bin python-twisted-core python-zope.interface snmp snmpd libsnmp15
wget -O net-snmp-5.7.2.tar.gz
tar xzvf net-snmp-5.7.2.tar.gz
cd net-snmp-5.7.2
./configure --prefix=/usr/local/net-snmp-5.7.2 --enable-ipv6 --with-mib-modules="ucd-snmp/diskio ip-mib/ipv4InterfaceTable ip-mib/ipv6InterfaceTable agentx" --with-python-modules && make && make install
cd /usr/local/
ln -s net-snmp-5.7.2 net-snmp
cd bin
ln -s ../net-snmp/bin/* .
cd ../lib/
ln -s ../net-snmp/lib/* .
cd ../sbin/
ln -s ../net-snmp/sbin/* .
cd ../include/
ln -s ../net-snmp/include/* .
cd ../share/man
for i in 1 3 5 8; do mkdir -p man$i; cd man$i; ln -s ../../../net-snmp/share/man/man$i/* .; cd -; done
cd net-snmp-5.7.2
cd python
python build
python install
rm -rf net-snmp-5.7.2*
mkdir -p /usr/local/net-snmp-5.7.2/etc/snmp
ln -s /usr/local/net-snmp-5.7.2/etc/snmp /etc

If it is OK to show your snmp to anyone:

echo "rocommunity public" > /etc/snmp/snmpd.conf

Debian has a package with the old version of antlr-python, we need version 3:

tar xzvf antlr_python_runtime-3.1.3.tar.gz
cd antlr_python_runtime-3.1.3
python install
cd ..
rm -rf antlr_python_runtime-3.1.3*

Reportlab fonts must be installed by hand:

cd /usr/lib/python2.7/dist-packages/reportlab/fonts

Since sanet needs an UTF-8 database, we advise to change the postgresql template1 database encoding to utf-8:

su postgres -c psql
UPDATE pg_database SET datallowconn = TRUE WHERE datname = 'template0';
\c template0
UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1';
drop database template1;
create database template1 with template = template0 encoding 'utf-8';
UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template1';
\c template1
UPDATE pg_database SET datallowconn = FALSE WHERE datname = 'template0';

Edit /etc/postgresql/9.1/main/pg_hba.conf and add, after "Put your actual configuration here", the line:

local      sanet2  sanet  md5

Set a locale, because Django will break if none is defined:

update-locale LC_ALL=C.UTF-8 LANG=C.UTF-8

Add the directory where you are going to install sanet in /etc/environment:


On a generic Linux system

SANET is a Django application written in Python. It has been tested in many flavours of Linux, it will probably run on other unices, it would probabily run on Windows with some modifications.

SANET on Linux requires many packages. You can install them as part of your distribution, or you can install them "by hand" as explained in their documentation: the choice is up to you. We list the needed packages, with reference to their website and specific version or patch requirements.


SANET requires postgresql 8.4 or greater. It has been tested with 9.0.1.

SANET scripts will connect to the database while running as root, so please adjust your pg_hba.conf accordingly.


Install the version 2 (2.0.1 or greater) Redis server.

Here is a sample script we use to launch redis, linked in /etc/init.d, but you distribution may require something different.




        REDIS_PID_FILE=$(grep 'pidfile' $REDIS_CONFIG_FILE | awk -F" " '{print $2}')

        case "$1" in
                        echo "Starting redis server..."
                        cat $REDIS_CONFIG_FILE | $REDIS_BIN -
                        PID=$(cat $REDIS_PID_FILE)
                        echo "Stopping redis server (pid=$PID)..."
                        kill $PID
                        $0 stop
                        $0 start
                        echo "usage $0 start|stop|restart"

You should adjust redis configuration according to your needs. As a minimum, apply the following patch to the distributed redis.conf:

< daemonize no
> daemonize yes
< timeout 300
> timeout 0
< logfile stdout
> logfile /var/log/redis.log
< dir ./
> dir /usr/local/redis
< vm-max-memory 0
> #vm-max-memory 0
> vm-max-memory 350MB

SANET works with recent versions (including 1.4) of rrdtool. Version 1.4 with rrdcached has a much better performance, but its installation is quite complicated, so you had better use your distribution if you can.

After installing rrdtool, you should check the python module with:

# python
Python 2.6.1 (r261:67515, Apr  1 2009, 08:53:41)
[GCC 3.2.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import rrdtool

If you get an ImportError, you should installl the rrdtool python binding, with you distribution or via the install documentation for rrdtool.


If you don't find Graphviz packaged for your distribution, here is an example installation from source. You will need libexpat, libjpeg, fontconfig, and freetype: if you are usnig a slackware system they can be installed as a slackware package, category "L".

root@server:~# wget
root@server:~# tar xzvf graphviz-2.20.2.tar.gz
root@server:~# cd graphviz-2.20.2
root@server:~/graphviz-2.20.2# ./configure --prefix=/usr/local/graphviz-2.20.2 && make && make install
root@server:~/graphviz-2.20.2# cd /usr/local
root@server:/usr/local# ln -s graphviz-2.20.2 graphviz
root@server:/usr/local# cd bin
root@server:/usr/local/bin# ln -s ../graphviz/bin/* .
root@server:/usr/local/bin# cd ..
root@server:/usr/local# cd lib
root@server:/usr/local/lib# ln -s ../graphviz/lib/* .
root@server:/usr/local/lib# cd ..
root@server:/usr/local# cd include/
root@server:/usr/local/include# ln -s ../graphviz/include/graphviz .
root@server:/usr/local/include# cd ..
root@server:/usr/local# cd man
root@server:/usr/local/man# for i in 1 3 n
> do
> cd man$i
> ln -s ../../graphviz/share/man/man$i/* .
> cd ..
> done
root@server:/usr/local/man# cd
root@server:~# rm  -rf graphviz-2.20.2*

Then pyparsing needs to be installed:

root@server:~# wget
root@server:~# tar xzf pyparsing-1.5.0.tar.gz
root@server:~# cd pyparsing-1.5.0
root@server:~/pyparsing-1.5.0# python install
root@server:~/pyparsing-1.5.0# cd ..
root@server:~# rm -rf pyparsing-1.5.0*


You need at least version 5.6. At the time of this writing, many distributions have an older version, so here is an example installation from source:

# ./configure --prefix=/usr/local/net-snmp-5.5.pre2 && make && make install
# cd /usr/local/
# ln -s net-snmp-5.5.pre2 net-snmp
# cd bin
# ln -s ../net-snmp/bin/* .
# cd ../lib/
# ln -s ../net-snmp/lib/* .
# cd ../sbin/
# ln -s ../net-snmp/sbin/* .
# cd ../include/
# ln -s ../net-snmp/include/* .
# cd ../share/man
# for i in 1 3 5 8; do mkdir -p man$i; cd man$i; ln -s ../../../net-snmp/share/man/man$i/* .; cd -; done

Then execute ldconfig to update your dynamic linker configuration.

You can then proceed with netsnmp python module installation. Come back to source directory and:

# cd python
# python build
# python install

To test module installation exit from current directory and try:

# python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import netsnmp
>>> CTRL+D

You must exit from building directory because there is a netsnmp directory in it.

If you get and error try to install from the python directory in the source tree with:

# python install  --install-platlib /path/to/your/lib/python2.x/site-packages/

Antlr3 is not available via setuptools. The python runtime can be dawnloaded from (python 2.4 o 2.5 or newer) or from here .

# tar xzvf antlr_python_runtime-3.1.2.tar.gz
# cd antlr_python_runtime-3.1.2
# python install
# cd ..
# rm -rf antlr_python_runtime-3.1.2*

WARNING: Version 1.1.7 does not work with SANET. You will need version 1.1.6. If you cannot install 1.1.6 with your distribution, download the package from the Pil homepage. It requires libjpeg library version 6a or 6b, which should already be present in the default installation.

Here is a direct link.

        $ tar -xzvf Imaging-1.1.6.tar.gz
        $ cd Imaging-1.1.6
        $ python build
        $ python install

SANET needs Apache 2.x with mod_python or mod_wsgi, and has been tested in mpm mode (not in prefork mode).

Set the right ownership and file permissions in order to make apache write into $SANET_HOME directory.

chown -R www-data:www-data *
Python modules

You should install the needed python modules using your distribution, if they were packaged for it, or using setuptools.

These are the package that can be installed with your distribution or with setuptools:

easy_install django==1.3
easy_install psycopg2
easy_install redis==2.0.0
easy_install PyXML
easy_install pydot
easy_install reportlab==2.5
easy_install html5lib
easy_install pisa
easy_install networkx
easy_instalL ipaddr

Optional but recommended:

easy_install setproctitle

If the installation of PyXML gives you an error like the following:

ImportError: No module named xml.sax.saxutils

You can try to fix it with:

cd /usr/lib/python2.X/site-packages/PyXML-0.8.4-py2.X-linux-i686.egg
ln -s _xmlplus xml

If you are using python 2.5 you should install the last supported version for python 2.5

easy_install networkx==1.2
NTLM modules (optional)

You need external NTLM modules in order to support NTLM proxy authentication.

cd /usr/local/src/
svn checkout  python-ntlm
cd ./python-ntlm
python build
python install
reportlab fonts

Download the required fonts from here or File:Linfonts.tar.gz

Unzip the package and copy the files in the directory (create it if missing):




For more info look at [1].

Installing SANET

Checkout from SVN

We don't provide tarballs: you have to run SANET out of an SVN working copy. In order to make a working copy in a directory called "sanet" in your current directory, you can use the command:

svn checkout  sanet

Basic setup

In your profile export the environment variable SANET_HOME pointing to the directory into which you extracted SANET:

# export SANET_HOME=`pwd`/SANET

You have to put this variable also in cron scripts and in the Apache configuration.

Copy `` to `` and edit it according to your needs, according to the comments in the file itself and in DO NOT edit, since it is overwritten during upgrades.

You MUST uncomment database connection settings and change them to suit your needs. Please note that postgresql_psycopg2 postgresql_psycopg2 is the only supported database. In this documentation we always assume that you are using the default database name and owner.

# DATABASE_ENGINE = 'postgresql_psycopg2'  # 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'ado_mssql'.
# DATABASE_NAME = 'SANET'             # Or path to database file if using sqlite3.
# DATABASE_USER = 'SANET'             # Not used with sqlite3.
# DATABASE_PASSWORD = ''         # Not used with sqlite3.
# DATABASE_HOST = ''             # Not used with sqlite3.
# DATABASE_PORT = ''             # Not used with sqlite3.

Setup database

Create your own user and database:

# psql -U postgres
Welcome to psql 8.3.1, the PostgreSQL interactive terminal.

postgres=# create role SANET login password '';
postgres=# create database SANET owner SANET encoding 'utf-8';
postgres=# grant all privileges on database SANET to SANET;
postgres=# \q

Initialize database and SANET library:

# python $SANET_HOME/ syncdb
# python $SANET_HOME/ SANETdata
# python $SANET_HOME/ cli -l < $SANET_HOME/etc/library-it

Start the poller

You must be root to start the Poller process (you must be able to open RAW sockets to **ping**), or if you're using a GNU/Linux system, at least you must have the **CAP_NET_RAW** capability active.

# $SANET_HOME/etc/rc.SANET start

Deploy on your webserver

Before deploying SANET into mod_python or mod_wsgi, you can test the web user interface on port 7777 with:

# $SANET_HOME/etc/rc.SANET web

Remember to make $SANET_HOME/static/measures writable by your http daemon. Most people just chmod -R www-data.www-data $SANET_HOME.

Apache mod_wsgi

Edit your file and set URL_PREFIX to the empty string, and SITE_PREFIX to the url prefix you want for this installation, trailing slash included and no leading slash.

After setting URL_PREFIX and SITE_PREFIX, set two more variables that depend on these:

LOGIN_URL = "/%slogin/" % SITE_PREFIX

To get a configuration fragment for your VirtualHost:

python deploy mod_wsgi

Remember to make the suggested symlinks.

Apache mod_python

mod_python is deprecated and unmaintained. If you still want to deploy with it, edit your file and set URL_PREFIX to the url prefix you want for this installation, trailing slash included and no leading slash. Set SITE_PREFIX equal to URL_PREFIX.

To get a configuration fragment for your VirtualHost:

python deploy mod_python

Remember to make the suggested symlinks.

Cron job

The script /etc/rc.d/rc.SANET nightly performs some maintenance operations. Copy to, edit it according to your needs and put nightly script it in your crontab (i.e. setting it to be launched every day at 6:45 am):

# SANET maintainance
45 6 * * * /etc/rc.d/rc.SANET nightly > /root/lastoutput.SANET.nightly 2>&1


When upgrading SANET from an older version, or when performing an "svn update", the first and most important rule is:


Web interface advanced settings

Set visible blocks in resource pages

Every resource page is divided in several data blocks. The number and the order of these information data block can be customized by changing the following setup variable

RESOURCE_PAGE_BLOCKS[ <resource type name > ] = [ <block name>, <block name>, ecc.... ]  


RESOURCE_PAGE_BLOCKS[ 'site' ] =  [ 'details', 'rstate', 'targets', 'measures' ]
Add sub sections to resource pages

Instead of having a simple vertical sequence of data blocks the page can be divided in sub sections.

This is the configuration syntax:

RESOURCE_PAGE_BLOCKS[ <resource type name> ] = [ 

      <section 1 conf>,
      <section 2 conf>,
      <section n conf>,


Where a section is an element with the following syntax:

        'name'  : <section id>,
        'descr' : <visible name>,
        'blocks': [ <block name>, <block name>, ecc.... ]

The id value assigned to the field name MUST be unique inside a resource page.

Example 1

Set up all the sections for the node page:


          'name'  : 'state', 
          'descr' : 'State', 
          'blocks': [ 'details', 'rstate', 'targets', 'measures', ]     
          'name'  : 'reports', 
          'descr' : 'Static Reports', 
          'blocks': [ 'reports_list', 'periodicreports_list']
          'name'  :'advanced', 
          'descr' : 'Advanced', 
          'blocks': [ 'states_logack', 'calendar' ] 
          'name'  : 'netinfo', 
          'descr' : 'More info', 
          'blocks': [ 'ipmon_data' ]


Example 2

Add the block alarms to the first section (index 0) in the site page:


Example 3

Add a new section to the existing site page:

RESOURCE_PAGE_BLOCKS['site'].append( { 'name':'brief', 'descr':'Brief', 'blocks': [ 'alarms' ] } )



	... cut & paste content from ...
	{ 'name':'brief', 'descr':'Brief', 'blocks': [ 'alarms' ] },

Extending the context menu with scripts

It is possible to alter the web context menu of a resource by adding new entries linked to external commands.

Every external command must be a shell script located in the following directory:

$SANET_HOME/var/menus/<resource type>/<script file>

The resource type can be: site, container, node, interface, target, measure:


Note: if the directory is missing it must be created and the related file permissions must be configured properly.

Script meta information

The script must follow the following structure.

#SANET_META:<visible text>,<description>


#SANET_META:Show Env,Shows environment variables
echo "***SCRIPT START***"
echo "***SCRIPT END***"


Sanet passes parameters to the script using environment variables with this naming scheme:


Sanet passes at least these two variables:

SANET_RESOURCE_TYPE     the resource type ('node','target', ...)
SANET_RESOURCE_NAME	The resource name ('phink0', 'mason::server-linux:reach', ...)


Create the following script file (and subdirectories):


The script content:

#SANET_META:Ping now,Simple ping Test

echo "---environment---"
echo "***END***"

Redirect Example

Redirect to a generic URL using the resource name (node name):


Script code:

#SANET_META:Info app. collegati, no-description


# Format redirect URL


# Send redirect page

echo "<html>"
echo "<head>"
echo ""
echo ""
echo "</head>"
echo "<body>"
echo "Nodo: " $SANET_RESOURCE_NAME " <br />"
echo "<br />"
echo "Redirecting..."
echo "<a href='$URL'> link </a>"
echo "</body>"
echo "</html>"

Personal tools