Monitor Slow Queries in MySQL

In an application we had many connection to MySQL database to insert and select data.
Always MySQL cup usage was about 30%, I googled and found a MySQL option which store slow queries in a log file.
That’s awesome !
You should add log-slow-queries to file /etc/my.cnf and restart MySQL service and here it is !

Go and check around ! make a tea for your self and after a while check log file in /var/run/mysqld/mysqld-slow.log

You can read more about this config in MySQL Reference

Asterisk’s AMI Return Empty String

About 2 months a ago, one day server of our customer decided to response empty string on Command Action. we feed bunch of data for reporting with AMI and especially with Command Action.

It was so mystery for us ! what happen suddenly ? anyway we were lucky, we had a backup and moved server to backup ones.

After works on that server we discovered this problem solved when we run asterisk as a root !
Anyway we did not work on that server until today. I get asterisk source code and debug lines and found a problem :
For unknown reason ownership of /tmp was different from always and a function wants to create temporary file but could not access to /tmp (file main/manager.c about line 1736).

If Asterisk Developers checks return value of mkstemp and debug if value is -1, life would be more pleasure

Asterisk’s Chanspy Is Out of Sync

About 3 month ago we had a problem on ChanSpy in Asterisk. sounds were out of sync.
We do everything ! changing asterisk version, compiling different version of asterisk !
Users of that customer use EyeBeam as SIP Client, in asterisk bug tracker someone wrote there is a problem with onboard sound cards. so that we take a PAP2 and test ChanSpy with ordinary telephone and Bingoo ! everything was sync !

We did update EyeBeams and problem solved.

These days I have problem like before, this time problem is files which recorded by MixMonitor are out of sync. tomorrow I am going to take PAP2 to that location and test files. I hope problem solves by changing EyeBeam or even add PCI sound card.

I will update this post when get answer.
Update :

problem solved by updating asterisk to

Hylafax T.30 T1 Timeout Problem

I configured  iaxmodem and hylafax for on of our customer last week. I test FAX with sending fax internal extensions and everything worked prefect.
But today they called me and said they have a problem in sending and receiving FAX ! Again troubleshooting !

I checked out log file log file was :
SEND FAILED: JOB 4 DEST 88276650 ERR [126] No receiver protocol (T.30 T1 timeout)

I googled about this problem and there was no direct answer to this. someone said there is a problem on connection your device and you have some thing like “UDP being a lossy medium”.

Anyway after question from friends problem solved with changing Tenor configure:

#set FaxRelay G.711 Mu-Law

If you have a same problem set FaxRelay to Mu-Law maybe cause to solve yours.

How to Config Slave DNS Server

In a project we have servers which were in different cities, and they connected to each other with Radio connection.
We want to setup DNS server in each server for easy use, but configuring dns in each server was to painful if server of one IP changed. we should change config in all server.

So I setup a master DNS server and config other server as Slave.
Slave config is :

zone “sip.server.loc”{
        type slave;
        file “/etc/bind/sip.server.loc”;
        masters {;};

Setting file value is useful when Master server is not accessible and Slave response requests with last config file(which updated that file from Master)

Create Custom SNMP Tree With Bash

In some case you need to monitor your service, and SNMP is ROCKs in reporting.
But if you don’t like to read bunch of document about SNMP protocol and creating server flow this instructions.

snmpd helps you so much with pass config, it run your command when request comes for a exact MIB.
Just open /etc/snmpd.conf and add this line to end of config file :
pass . /bin/sh /usr/local/snmp_script/snmp_asterisk

With this config when you request snmp walk on . returns this result :
$ snmpwalk -v 1 pbx -c public .
UCD-SNMP-MIB::ucdavis.256.1 = Gauge32: 3
UCD-SNMP-MIB::ucdavis.256.2 = Gauge32: 10
UCD-SNMP-MIB::ucdavis.256.3 = Gauge32: 1
UCD-SNMP-MIB::ucdavis.256.4 = Gauge32: 3
UCD-SNMP-MIB::ucdavis.256.5 = Gauge32: 3

Yes ! I monitored my asterisk’s important status.
Now what’s line of that bash script ? you can locate passtest and create your file from that sample but I put my file for more sample !
#!/bin/sh -f

if [ "$1" = "-s" ]; then
echo $* >> /tmp/passtest.log
exit 0

if [ "$1" = "-n" ]; then
case "$REQ" in
*) exit 0 ;;
case "$REQ" in
$PLACE) exit 0 ;;
*) RET=$REQ ;;

echo "$RET"
case "$RET" in
$PLACE.1) echo "gauge"; echo `member_in_queue` ; exit 0 ;;
$PLACE.2) echo "gauge"; echo `number_of_answerd_call` ; exit 0 ;;
$PLACE.3) echo "gauge"; echo `number_of_missed_call`; exit 0 ;;
$PLACE.4) echo "gauge"; echo `rate_answerd_call` ;;
$PLACE.5) echo "gauge"; echo `rate_missed_call` ; exit 0 ;;
*) echo "string"; echo "ack... $RET $REQ"; exit 0 ;;

You can use this MIBS in Monitoring System like Zenoss and …

Samsung Galaxy Farsi Fonts and Keyboard

After I change my G1 fonts to read farsi SMS and also farsi keyboard some one post me a comment which want from me to check if I could do same things on his Samsung Galaxy .

And now I do that staff. rooting Samsung Galaxy was bit little more difficult  than G1 !

How to Use Libjalali

About 2 years ago my friend Ashkan Ghassemi developed a Jalali Calender for use in terminal and as Eric S. Raymond says in his book The Art of Unix Programming : “Write simple parts connected by clean interfaces”, Ashkan followed Raymond and create beautiful program .

In a project I need to use that library so I get source file and install it, but there was no any documentation for developer. here I write fast tutorial :

int main (){
j_date jcal;calc_current(&jcal) ;
printf("curentdate is :%d/%d/%d\n ",jcal.year,jcal.month,jcal.day);}

and after that compile this code :
cc jcaltest.c -I/usr/local/include/jalali/ -L/usr/local/lib/ -ljalali -o jalal.bin

and run jalal.bin

Configure Asterisk and Zaptel on Ubuntu 6.*

Always I installed Asterisk and Zaptel on Ubutnu 6.*, I got a error and couldn’t find any files in folder /dev/zap/ !
Actually he said true ! because Zaptel file was in /dev/ folder.
When servers restart, I should create link to real device file(I try put this command on file rc.local but still had a problem on creating link). Until I goggled and find some manual for this problem.our problem will solved by udev.

Create File : /etc/udev/rules.d/50-udev.rules

KERNEL="zapctl", NAME="zap/ctl" , GROUP = "asterisk"
KERNEL="zaptimer", NAME="zap/timer" , GROUP = "asterisk"
KERNEL="zapchannel", NAME="zap/channel" , GROUP = "asterisk"
KERNEL="zappseudo", NAME="zap/pseudo" , GROUP = "asterisk"
KERNEL="zap[0-9]*", NAME="zap/%n" , GROUP = "asterisk"

Restart udev : /etc/init.d/udev restart

Now every time server restart udev create device in place where Asterisk wanted.

Script for Removing Changed Host Identification

As I am working as a system administer this days and always had a problem with changing Remote Identification of servers, I write simple script which you can delete a line from your ~/.ssh/known_hosts

#rm_known_hosts bash script

line_nums=$(cat $file_name | wc -l )

cat $file_name | head -n`echo "$1 -1 " | bc ` > $tmp_head
cat $file_name | tail -n`echo "$line_nums - $1 "| bc` > $tmp_tail

cat $tmp_head > $tmp_dest
cat $tmp_tail >> $tmp_dest

cp $tmp_dest $file_name

#remove tmps
rm -f $tmp_head
rm -f $tmp_tail
rm -f $tmp_dest

for example run when you got error like this :

Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /root/.ssh/known_hosts:90
RSA host key for has changed and you have requested strict checking.
Host key verification failed.

you just run

./rm_known_hosts 90

Life will be essayer with tiny scripts !