2011/04/01

Bladecenter switches acting funny

Today I had a nice problem. When a second switch was added to the a 3 com uplink switch the network went down. Not so very nice. I fixed it in a not so good way but it gives me a clue were to start looking for the error. I executed the following on both switches.

interface range GigabitEthernet0/17 - 20
spanning-tree portfast trunk
spanning-tree bpdufilter enable
spanning-tree bpduguard enable
!

Basically this means that the switch will not do Spanning tree on its external ports. Do not do this if you are unsure that you have loops or not. In my case I was quite sure so I just did it :) . Probably some 3 com spanning tree protocol that does not talk nice with rapid-pvst

2011/03/30

Growl fun on Mac

Growl is a general accepted way of notifying something to users in Mac. You are probably using (for example the twitter app can send you updates via Growl) but what you might not now is that you can easily script. It is quite easy although I haven't figured out the details.

First you need to install the library. You can compile it yourself but you can also easy install it
sudo easy_install-2.6 py-Growl

Then you can test it
>>> import Growl
/Library/Python/2.6/site-packages/py_Growl-0.0.7-py2.6-macosx-10.6-universal.egg/Growl.py:17: DeprecationWarning: the md5 module is deprecated; use hashlib instead
>>> gn = Growl.GrowlNotifier("overtime",['overtime'])
>>> gn.register()
>>> gn.notify("overtime","Are you still working?","Yes I am!")

(Code from http://prehensile.co.uk/blog/?p=92)
This should display a message if you have installed Growl

I also created a small script that you run directly from cli if you don't like python. You can run it like this in the terminal
$ ./gnotify "Some Test" "A very good test"

BTW SQLAlchemy also install easily via easy_install-2.6 on Mac :)

2011/03/25

Installing python 26 + sqlalchemy on centos

Turns out there is a very very very easy . Just use the repo for fedora on the redhat site.

rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
yum install python26 python26-devel python26-distribute python26-tools
easy_install-2.6 SQLAlchemy

test it via
python2.6
>>>import sqlalchemy
>>>sqlalchemy.__version__

2011/03/22

Random password in CLI

Just a small script so that we can generate passwords from the command line

NUMPASS=10
if [[ "$1" =~ ^[0-9]+$ ]] ; then
NUMPASS=$1
fi
echo "Spicy salt $(date)" | md5sum | sed "s/\(.\{$NUMPASS\}\).*/\1/"

2011/03/17

Zimbra server status all red crosses

I always have this problem when configuring zimbra servers (everything is working fine but service have red crosses in the web gui). At this point I tried this and waiting if it will help :)

su - zimbra
zmsshkeygen
zmupdateauthkeys
zmloggerctl stop ; zmloggerctl start

2011/03/16

Blueprint script to create DNS records in AD

Create this following code as a bat. You can than run the following (assuming you called the bat adddns.bat):
>adddns mynewhost01 0 10

This will create the records for a host 192.168.0.10 (in the example)

@echo off
:start
if "%1" == "" goto error
if "%2" == "" goto error
if "%3" == "" goto error

dnscmd abinbev.demo /recordadd yourdomain.com %1 A 192.168.%2.%3
dnscmd abinbev.demo /recordadd %2.168.192.in-addr.arpa %3 PTR %1.yourdomain.com

goto end

:error
echo name
echo adddns.bat host1 2 213
goto end
:end

2011/03/01

Setting up django: step 1, python 2.7.1

Just trying out some django in centos 5.5. So this should not been seen as a good solution. Just me trying to set it up properly

some pre preps
yum -y groupinstall 'Development Tools'
yum -y install openssl-devel* zlib*.x86_64
yum -y install httpd-devel
yum -y install mysql-devel
yum -y install wget

downloaded and untarred 2.7.1
cd /usr/local/src
wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz
tar -xzvf Python-2.7.1.tgz


compiled it with embedded so we can use apache mod wsgi. Used a seperate path so that it is not conflicting with the internal python
./configure --prefix=/opt/python2.7 --with-threads --enable-shared
make
make install

added the new library to the dynamic loader
echo "/opt/python2.7/lib" > /etc/ld.so.conf.d/python27.conf
ldconfig

We can now test it
[root@django ld.so.conf.d]# /opt/python2.7/bin/python
Python 2.7.1 (r271:86832, Mar 1 2011, 21:14:38)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

ln -s /opt/python2.7/bin/python2.7 /usr/bin/python2.7
ln -s /opt/python2.7/lib/libpython2.7.so /usr/lib/libpython2.7.so

Installing the setup tools
cd /usr/local/src
wget http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
sh setuptools-0.6c11-py2.7.egg --prefix=/opt/python2.7


Installing the mysql bindings
cd /usr/local/src
wget http://downloads.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz?r=&ts=1299013136&use_mirror=netcologne
tar -xzvf MySQL-python-1.2.3.tar.gz
python2.7 setup.py build
python2.7 setup.py install

Installing wsgi
cd /usr/local/src
wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
./configure --enable-shared --prefix=/opt/mod_wsgi-3.3 --with-python=/opt/python2.7/bin/python
make
make install

A mod should be made. You can find it in
Libraries have been installed in:
/usr/lib64/httpd/modules

The mod itself:
/usr/lib64/httpd/modules/mod_wsgi.so

echo "LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so" > /etc/httpd/conf.d/wsgi.conf
echo "AddHandler wsgi-script .wsgi" >> /etc/httpd/conf.d/wsgi.conf
chmod 755 /etc/httpd/conf.d/wsgi.conf
/etc/init.d/httpd restart

Installing django
wget http://www.djangoproject.com/download/1.2.5/tarball/
python2.7 setup.py install

cd /tmp
cat <<> test.py
#!/opt/python2.7/bin/python
import django
print django.get_version()
EOF
chmod +x test.py
[root@django html]# ./test.py
1.2.5

Symlinking the django admin so we can use it everywhere
ln -s /opt/python2.7/bin/django-admin.py /usr/local/bin/django-admin.py

Configuring apache to use django
cat <<> /etc/httpd/conf.d/django.conf
WSGIScriptAlias / /var/www/django/django.wsgi

Order allow,deny
Allow from all
EOF

creating the django handler
mkdir -p /var/www/django
cat <<> /var/www/django/django.wsgi
import os
import sys

path = '/var/www/django'
if path not in sys.path:
sys.path.append(path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
EOF
chmod 755 /var/www/django/django.wsgi

Now we can create a site
cd /var/www/django/
django-admin.py startproject mysite

Restart the webserver to activate everything
/etc/init.d/httpd restart

Surf to your http server ot see the result