How to Install Cacti Plugin Architecture

Cacti Plugin Architecture allow you to run useful monitoring plugins on Cacti. There are several good plugins like Thold, Aggregator and Weathermap which give you comprehensive network device monitoring.

There are a few steps involve In order to install Cacti Plugin Architecture. First we will need to backup current cacti files, and overwrite the files for Cacti Plugin Architecture and lastly to make some changes on configuration files in order to activate Cacti Plugin Architecture.

Installing Cacti Plugin Architecture

Cacti Plugin Architecture can be downloaded at Cacti Users website. The demo I am going to show is to download Cacti Plugin Architecture version 2.8 on Cacti version 0.8.7g.

Before installing Cacti Plugin Architecture, lets make a backup copy of your cacti files, in case something goes wrong, you can roll back to the original files. During the backup, we are going to exclude rra and log directory.

First change directory to the directory which located Cacti files, in FreeBSD would be /usr/local/share


shell> cd /usr/local/share
shell> tar -zcf cacti.backup.tar.gz --exclude=rra --exclude=log cacti

After backup, it’s now safe to replace your cacti files with cacti architecture files. First untar Cacti Plugin Architecture which you have downloaded earlier.


shell> tar -zxf cacti-plugin-0.8.7g-PA-v2.8.tar.gz

After untar-ed cd to plugin architecture folder and edit config.php.dist file with your mysql database credentials. Follow with rename the file to config.php


shell> tar -zxf cacti-plugin-0.8.7g-PA-v2.8.tar.gz
shell> cd cacti-plugin-arch
shell> vi include/config.php.dist
shell> mv include/config.php.dist include/config.php

In include/global.php, edit MySQL database credentials as well.


shell> vi include/global.php

Next, create the database table which required by Plugin Architecture. The file is located at cacti-plugin-arch directory with file name pa.sql.


shell> mysql -u username -p cacti < pa.sql

Now, it's all good, copy all the files into cacti directory. You cacti directory might be different from mine directory path.


shell> cp -rf * /usr/local/share/cacti/

The installation for Cacti Plugin Architecture is done. In order to access to Plugin Setting. Log on to Cacti, go to User Management, click on Admin, check Plugin Management on realm management and Save.

You should see Plugin Management on your left menu bar. On the next post we will go through the plugins for Cacti Plugin Architecture.

How to Check Linux Version and Distro

Who run more than 10 Linux servers with different version of Linux Distro? We all know there are many type of Linux distro such as Ubuntu, Centos, Gentoo, Fedora, debian, OpenSUSE and etc. Every single distro runs on different version and etc. Sometime I am having problem to remember what Linux distro is running on my DNS server or Mail Server, and what Linux version is it on now. There are two methods to find linux version on your server.

To check Linux distro on your server


shell> cat /etc/issue

To check Linux Version and distro on your server


shell> cat /etc/*-release

Linux/Unix Search and Replace Text from Multiple Files

In Linux/Unix, for newbie to do search text from multiple files/folder look like difficult, replacing string from file sound even harder. It’s actually not hard or complicated to search and replace text from multiple files in Unix/Linux. The key is what command to use, there will be two main commands involve in search and replace, which are find and sed

For example I am hosting multiple web applications, the development might have several pg_connect command to connect database, in the event I am migrating database to other IP address, it might be hard for them to dig the file and replace the IP Address with new IP Addresses.

In Linux/Unix, you can search through the directories, looking for the files and replace it with the new IP address. Here is the sample.


shell> find /path/to/dir/* -type f -exec sed -i .backup20100714 -e "s/host=x.x.x.x/host=y.y.y.y/g" {} \\;

The command above will search for files in the directory.
find -type f mean look for File only.
find -exec is to execute something from returned results.
sed -i means backup the files, in case you would like to restore later.
sed -e “s/host=x.x.x.x/host=y.y.y.y/g” is to replace x.x.x.x to y.y.y.y

You have backup files name filename.php.backup20100714, now what you need to do is move the files in a backup directory.


shell> find /path/to/dir/* -name "*.backup20100714" -exec mv {} /your/backup/dir/ \\;

You might want to explore on find command, it can do a lot of cool stuffs.

Perl, Trim White Space from a String

When we grep a bunch of string, there are white spaces where we wish to trim, especially the white space at the beginning and the end of a string. There is no trim function in Perl like trim in PHP. The Perl function below should help you to trim the string.


#!/usr/bin/perl


sub trim($);
sub ltrim($);
sub rtrim($);

sub trim($)
{
	my $trim_string = shift;
	$trim_string =~ s/^\s+//;
	$trim_string =~ s/\s+$//;
	return $trim_string;
}

sub ltrim($)
{
	my $trim_string = shift;
	$trim_string =~ s/^\s+//;
	return $trim_string;
}

sub rtrim($)
{
	my $trim_string = shift;
	$trim_string =~ s/\s+$//;
	return $trim_string;
}

my $long_string = "  \t  foo foo        bar \t \t bar          ";
print trim($long_string);

PostgreSQL Database psql Command Line Query

Sometime psql command line query can be useful when it comes to Bash script processing. There are data stored in PostgreSQL database and I would like to write a bash script to massage the data into report. Example below show query to PostgreSQL database by using the psql command.


/usr/local/bin/psql -c "SELECT email_address FROM members WHERE active is TRUE;" -U someuser -t -A -o member-email-address.txt accounting

psql is connecting to accounting database, query from members table and out the result into a txt file name member-email-address.txt.

-t – Return result only, do not result with table name.
-A – By default, returned result will have white space, this is to remove the white space.
-o – Output the result into a file.