support@yourtech.us | Webmail |  DNS Login | *Billing* | cPanel | (814) 652-5358

Welcome to YourTech, LLC. If you are unfamiliar with this site, you may want to find out about my services, read my story, or you could simply be looking for a way to contact me. On this site, you will find a collection of technical musings, howto guides, and technical reference information.

Generating exim statistics on Centos 4

| No Comments | No TrackBacks

One of my clients uses Centos 4 + cPanel. The default install seems to come with exim, which I don't have much experience with. Because of some recurring issues (either imaginary or real) that I haven't been able to pin down as issues, I decided to try and gather email statistics.

exim-snmp-stats setup

Looking around, there isn't much to use. Matthew Newton seems to be the only person that has something current, his exim-snmp-stats program. I downloaded his tarball and extracted it to /usr/local/exim-snmp-stats. The files need to be executed by a user that can read the exim_mainlog (in this case, mailnull) and an archive directory needs to be created, owned by the same user

cd /usr/local/exim-snmp-stats
mkdir archive
chown mailnull archive snmp-stats-get.pl snmp-stats-show.pl

Edit snmp-stats-get.pl to reflect your setup. The setup for Centos is show below, with my own comments

     36 my $suffix = "";
37 my $conf = "/usr/local/exim-snmp-stats/current-state$suffix";
38 my $statsfile = "/usr/local/exim-snmp-stats/statistics$suffix";
39 my $mainlog = "/var/log/exim_mainlog";
40 my $mainlogold = "/var/log/exim_mainlog.01";
41 my $archive = "/usr/local/exim-snmp-stats/archive";
...
# edit these patterns in to match your local network. Be as explicit as you need.
161 if ($line =~ /<=.*\s\[:192.168/) {
162 $$stats{"localin"}++;
163 } elsif ($line =~ /[=-]>.*\s\[:192.168/) {
164 $$stats{"localout"}++;


Run the command once as the mailnull user (or root) to make sure it works. If you ran it as root, be sure to chown the files back to mailnull for future runs.

./usr/local/exim-stats-get.pl
chown -R mailnull archive current-state statistics

Once that works, add it to your /etc/crontab with a line like this:

4,9,14,19,24,29,34,39,44,49,54,59 * * * *       mailnull        /usr/local/exim-snmp-stats/snmp-stats-get.pl

net-snmp setup

Installing net-snmp on Centos is about as easy as doing it on Debian. I ran up2date, copied the supplied config file to a backup name, and then roughly utilized the config file provided by Matt.

up2date -i net-snmp net-snmp-utils 
cd /etc/snmp
cp snmpd.conf snmpd.conf.dist

Making my /etc/snmp/snmpd.conf file look like this (be sure to change the community string from public to something more secretive):

####
# First, map the community name "public" into a "security name"

# sec.name source community
com2sec notConfigUser default public

####
# Second, map the security name into a group name:

# groupName securityModel securityName
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser

####
# Third, create a view for us to let the group have rights to:

# Make at least snmpwalk -v 1 localhost -c public system fast again.
# name incl/excl subtree mask(optional)
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1

####
# Finally, grant the group read-only access to the systemview view.

# group context sec.model sec.level prefix read write notif
access notConfigGroup "" any noauth exact systemview none none

###############################################################################
# System contact information
#

syslocation servername or geographic location
syscontact Admin Name <email@example.com>

###############################################################################
# exim stats

exec .1.3.6.1.4.1.3031.64 snmp-stats-show.pl /usr/local/exim-snmp-stats/snmp-stats-show.pl

You can start snmpd by running

/etc/init.d/snmpd start

. To run it after a reboot, make a symlink:

ln -s /etc/init.d/snmpd /etc/rc3.d/S90snmpd

.

setup cacti

Basically following: http://howtoforge.com/cacti_centos4.4_plugin_architecture. However, at the time of this writing, cacti-0.8.7b is the current version.

Very quick run:

wget http://www.cacti.net/downloads/cacti-0.8.6j.tar.gz
wget http://cactiusers.org/downloads/cacti-plugin-arch.tar.gz

The howto has you setup rpmforge and then install some other software. I skipped this step as my install already contained the software. But here it is the full set of commands:

rpm -Uvh http://apt.sw.be/packages/rpmforge-release/rpmforge-release-0.3.6-1.el4.rf.i386.rpm
yum install freetype-devel libpng-devel libart_lgpl-devel php-gd php-mysql

Here is what I had to install on a Centos 4.6 with cPanel installation (note that cPanel doesn't install php using rpms but rather through it's own scripts - however, php and php-gd, as well as freetype-devel are installed through the cPanel web interface.

rpm -Uvh http://apt.sw.be/packages/rpmforge-release/rpmforge-release-0.3.6-1.el4.rf.i386.rpm\
yum install libart_lgpl-devel

rrdtool:

wget http://oss.oetiker.ch/rrdtool/pub/rrdtool.tar.gz
tar -xvzf rrdtool.tar.gz
cd rrdtool-1.2.27/
./configure --disable-tcl
make
make install
ln -s /usr/local/rrdtool-1.2.27/bin/rrdtool /usr/local/bin/rrdtool

I skipped the howto's net-snmp steps because I already did that earlier.

setup cacti

tar -xzvf cacti-0.8.7b.tar.gz
cp -Rf cacti-0.8.7b /usr/local/cacti
tar -xvzf cacti-plugin-arch.tar.gz
cp cacti-plugin-arch/cacti-plugin-0.8.7b-PA-v2.0.diff /usr/local/cacti/
cd /usr/local/cacti/
patch -p1 -N --dry-run < cacti-plugin-0.8.7b-PA-v2.0.diff

Next you edit include/config.php and setup your database. I created the database using the cPanel MySQL admin pages. You're going to want to import /usr/local/cacti/cacti.sql into your new MySQL database. You can use either phpMyAdmin or the CLI.

Create the cacti user:

/usr/sbin/groupadd cacti
/usr/sbin/useradd -g cacti cactiuser
/usr/sbin/usermod -G cacti cactiuser

Set permissions:

chown -R cactiuser rra/ log/
chgrp nobody log/cacti.log
chmod g+w log/cacti.log

Edit /etc/crontab and add the following line:

*/5 * * * * cactiuser /usr/bin/php /usr/local/cacti/poller.php > /dev/null 2>&1

At this point, just create a symbolic link from /usr/local/cacti to a web-accessible directory (ie "ln -s /usr/local/cacti /home/user/public_html/cacti). Then, browse to example.com/cacti and go through the installation process.

Once you're done with the web based setup, login as admin/admin. You'll be forced to change the password immediately.

The final thing to do is go to "Import template" and import the xml file provided with exim-snmp-stats. The easiest way to do this is to copy the xml file to a web-accessible directory on the server, rename it to a .txt file, and then copy/paste it. Alternatively, you can download a copy to your local PC and then upload it through the web interface.

Once you have imported the template, go to Create Graphs. From the drop-down, select (one at a time) the four exim graphs and click the create button. It will take 10-20 minutes for your graphs to solidify, but all of your graphs can be viewed by clicking the "Graphs" option at the top of the page.

No TrackBacks

TrackBack URL: http://www.yourtech.us/cgi-bin/mt/mt-tb.cgi/2

Leave a comment