Problem With PostgreSQL ODBC ZenPack

In my new job(if after 8 months you can count it as new!) I am responsible to maintain Zenoss and some week I am on call for Zenoss’s Alarm.

One of the strangest problem that we had was about PostgreSQL ODBC Database Monitor package. suddenly zenperfsql stopped without any log.

I tried to run zenperfsql in debug mode and I hoped that I would fix the problem. but after the daemon died again the error that I saw was :

python: pthread_mutex_lock.c:62: __pthread_mutex_lock: Assertion `mutex->__data.__owner == 0' failed.

I never thought that I would face to python’s thread stuff ! as far as I knew Zenoss use Twisted framework and this error just happened for sql daemon so I reviewed the way that we had installed the packahe

For using this package you need to follow these steps

/usr/local/zenoss/python/bin/easy_install pyodbc apt-get install odbc-postgresq apt-get install unixodbc-dev

And edit /etc/odbcinst.ini, here is the tricky part, if you follow unixodbc document, it recommends you to config like :

[PostgreSQL] Description = PostgreSQL ODBC driver (Unicode version) Driver = /usr/lib/odbc/psqlodbca.so Setup = /usr/lib/odbc/libodbcpsqlS.so

But you need to add an other line which is specifying number of Threads

[PostgreSQL] Description = PostgreSQL ODBC driver (Unicode version) Driver = /usr/lib/odbc/psqlodbca.so Setup = /usr/lib/odbc/libodbcpsqlS.so Threading = 2

After adding Threading line I never face that problem, I dunno why Twisted which is built as asynchronous framework can not handle this and we need to limit ODBC’s Thread.


I found another blog that he faced same problem and he explains the reason (see more)

When You Are Not Free Even to Do Rm -rf / !

How much it is painful that you can’t do rm -rf / in your machine !

when I did rm I got this error :

rm: cannot remove root directory `/’

In past great responsibility brought great power but this days you are not free.


Cheers for past that you can do every thing you want !


Matching List and Map in Scala

For a while that I’ve been reading Scala I find it as a strong and powerfull language which helps you to write your application perfectly, it’s not like Java that ties you to follow some arid rules and it’s not like PHP that let you screw in your application(of course you can handle your code in PHP). Programing in Scala is fun as programming Python and it’s powerful as Java!

Scala’s Match syntax is liitle like Switch-Case but you can match value, type, regex, special type of class and more. 

Here is a syntax of matching for List and map in Scala, for finding these codes I search a lot to ! so I wrote these samples for future usage. 

val foobar = Map("foo"->"bar") foobar match {    case map :  scala.collection.Map[_, _] => println(map) }


val foobar = List("foo","bar") foobar match {    case  list:Seq[_] => println(list) }


So maybe you ask that why you need to handle something like this ?

It’s real world senario: I wanna to pass mix value of Map and List and String to function and get JSON string from that. some thing like this :

def toJson(ob: Any):String = {   ob match {     case s : String   => return "\""+ s + "\""     case d:Double   => return "\""+ d.toString + "\""     case map:scala.collection.Map[_, _] => return "{" + ((for((k,v) <- map) yield toJson(k) + ":" + toJson(v) ).reduceLeft(_ + ", " + _) ) + "}"     case list @ List(_*)   => return "[" + ((for (m<-list) yield toJson(m)).reduceLeft(_ + ", " + _) )   + "]" }

Mabye last code doesn’t work probably ! because I write it to just show you how you can use this feature

Yet Another Programming Language : Scala

Every day you wake up, you hear new language is growing in town. after that language becomes mature, you fill unstable in your current position.

You think why they ever think about another language while there are bunch of languages out ?you think there is many languages still waiting in your TODO list which you want try so how can you skip them and try this new guy !

Anyway I am going to interest in this one : Scala !

My first reason is Remember The Milk. I am actually in love with this app.
Second one is, it smells Java! I don’t like Java to much because of it’s complexity but Scala give me power of Java.

In my new job, I should learn more about Perl so this year will be funniest year in my life.
Fight between obsolescence and adolescent.

Let’s who will win !

How to Setup Blogger Custom Domain With BIND

Just for record in history !
1. You need to go in your blogger Setting->Publishing, click on custom domain, add your domain (with subdomain ) and save settings.

2. Connect ssh to your BIND server and create file /etc/bind/named.mydomain with this content :
$TTL 86400
@ IN SOA ns.here. root.here. (
2 ; Serial
28800 ; Refresh
14400 ; Retry
604800 ; Expire - 1 week
86400 ) ; Minimum

blog IN CNAME ghs.google.com. ; don’t remove last dot

3. Open /etc/bind/named.conf.local and append these lines :
zone “mydomain.org” IN {
type master;
file “/etc/bind/named.mydomain”;
allow-update { none; };
4. Restart your bind server /etc/init.d/bind9 restart

5. Open your blog with web browser.

Drawing Cartoons and Comics for Dummies

After 8 years it’s my second time which I try to learn drawing cartoons.
I found this book useful but part 1 of book is so boring!
Beginning of part 2 makes you little move, learns you how to draw head,neck,under body,objects and at the end of this part shows you how to draw Editorial cartoons (political cartoons)
In next part learns you about assembling what you learnt until now, tries to give you views about perspective, learns some hints about using letters in your cartoons and in last chapter of this part helps you use correct layout and background for your cartoons.
Part 4 talks about how to enhance your cartoon in Photoshop and part 5 has hints for you if you wana be a real cartoonist

Overall I like the book, currently read until beginning of chapter 6 and you can see my first cartoons :

PHP AGI Is So Slow

In one case exactly in our customer’s server, AGI which I wrote it was so slow !
I checked line by line of codes but it was hooked in some line of code. because we are pythonic company, immediately I want from team to rewrite that code with python ! (python AGI is more better that PHP ones)

A few days ago on that server , tail of syslog was opened and suddenly another PHP AGI run and I saw bunch of error in syslog which said that you didn’t set TimeZone in php.ini !

And bingo! I guess problem is here, I add TimeZone in php.ini and AGI works fine !

SIP Channel Stuck on Asterisk

In some case we need to set call-limit=1 in sip config but after a while a SIP channel stuck and we got problem on sending new call to that SIP number.
Logger save this error :
“Call from peer XXX rejected due to usage limit of 1”
Asterisk*CLI> sip show channels 111 1e436b221c0 00102/00000 0x0 (nothing) No (d) Tx: ACK

Even when turn of that SIP, we got that error !
I always try to fixed that but every time this event happen we forced to fix this problem.

Now it seems this problem solved in Asterisk 1.4.26 !
If you have problem like me check new version of asterisk

MusicOnHold Is Choppy in Asterisk

Sometimes after you setup your Asterisk system maybe you hear MOH-Music so choppy.

Solutions which I test and solved problems are :
  1. check your Zaptel and especially module ztdummy (you can use this guide)
  2. check you VoiceGateway VAD (Voice Activity Detection) config and Disabled it ! you can follow my samples for Cisco AS5300 and Quintum Tenor
VAD Configurations :
1. Cisco AS5300 :
  1. Login to your Cisco
  2. Type : “conf terminal”
  3. Enter your voip dial peer : “dial-peer voice 200 voip” (200 is my dial-peer, yours maybe is something else )
  4. Type : “no vad”
  5. Press Ctr+C
  6. write your configuration by typing write command : ” write”
2. Quintum Tenor
  1. Login to your Tenor
  2. Type: “config”
  3. Type : “IPRoutingGroup” (depends on your config maybe need to add a number after this command )
  4. Type : “set VADEnable 0”
  5. Save your config with command : “Submit”