Category Archives: Technical

07 Jun

XML to JSON converter in Siebel

Often we come across requirement for Siebel to integrate with external applications. Siebel provides various ways to integrate through EAI (Enterprise Application Integration) like EIM, Prebuilt connectors, various queues like MSMQ, JMS, WebSphere MQ. Also Web service based integration using SOAP. Siebel also supports RESTful based integration using Fusion Middleware.

One important feature of Siebel EAI is EAI Java Business Service which can be used to invoke external Java class to perform various operations.
In this article we will see how we can use various EAI Business services to communicate with JSON API of external application. We will have an XML input processed and resulted into a JSON output in Siebel.

Read More

20 May

Cannot connect to MySQL server on ‘localhost': Cacti Error

I was installing and setting up Cacti recently and faced following error:

“FATAL: Cannot connect to MySQL server on ‘localhost’.”

This post includes debugging steps and solution for the issue.

Along with the Cacti’s web-interface, the poller.php was generating the same error as follows:

root@ubuntu:/var/www/cacti# php /var/www/cacti/poller.php
FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php'

Read More

10 Mar

10 useful shell script code snippets | Linux

This post is collection of 10 useful unix / linux shell script code snippets I’ve often used.

Following these code snippet you will be able to answer following questions:
1. How to calculate script run-time in shell.
2. How to parse parameters / arguments to shell script.
3. How to safely change a directory in shell script.
4. How to check if a command was successful in shell script.
5. How to add timestamps in script log output.
6. How to check if a process is running.
7. How to colour your script output.
8. How to read variables from config file.
9. How to loop over files in a folder.
10. How to perform actions based on variable value using SWITCH…CASE

And a bonus snippet
11: How to send emails from shell script.

Let’s begin.
Continue Reading…

18 Nov

10 Steps: MySQL Monitoring through Nagios: Install & Configure

Nagios is a powerful monitoring system and here we will learn how to monitor MySQL through Nagios. We will be installing Nagios, required plugins and configuring it to monitor MySQL Database Server.

Let’s unleash the power step by step:

Installing and configuring Nagios

Step-1 : Install required stuff:
yum install httpd
yum install gcc
yum install glibc*
yum install gd*

Step-2 :Create Nagios user account and group
useradd nagios
passwd nagios
groupadd nagcmd
usermod -G nagcmd nagios
usermod -G nagcmd apache

Step-3: Downloads:
Create directory:
mkdir NagiosSetup
cd NagiosSetup

Download nagios
wget -X Get "http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.1/nagios-3.2.1.tar.gz/download"

Download Nagios Plugins:
wget -X Get "http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.15/nagios-plugins-1.4.15.tar.gz/download"

Follow up articles:
1: Installing Percona Monitoring Tools for MySQL Nagios.
2: Adding remote MySQL Host to Nagios Setup.

Step-4: Install Nagios

tar -xzvf nagios-3.2.1.tar.gz
cd nagios-3.2.1
./configure --with-command-group=nagcmd
make all
make install
make install-config
make install-commandmode
make install-init
chkconfig --add nagios

[If you miss step “make install-init” you may get:: error reading information on service nagios: No such file or directory ]

Configure Nagios Web Interface:
make install-webconf
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

[specify password for nagios admin]

Step-5: Install plugins
tar xvf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

Step-6: Verify Installation, Starting nagios for the first time

service nagios start
Browse: http://localhost/nagios

Here if you get Error:
“You don’t have permission to access /nagios/ on this server.”

Check /etc/httpd/conf/httpd.conf for DirectoryIndex.
If it’s not having index.php add it as follows:

vi /etc/httpd/conf/httpd.conf
DirectoryIndex index.php index.html index.html.var

Make sure you do restart apache(httpd) and nagios every time you change the config file. You must have php installed.

Monitoring MySQL:

Step-7: Download, Extract and install the MySQL Plugin:

wget http://labs.consol.de/wp-content/uploads/2010/10/check_mysql_health-2.1.3.tar.gz

tar -zxvf check_mysql_health-2.1.3.tar.gz
cd check_mysql_health-2.1.3
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-perl=/usr/bin/perl
make
make install

Step-8: Create database user:
grant usage, replication client on *.* to 'nagios'@'localhost' identified by 'nagios';

Step-9: Provide email address for nagiosadmin:
[Change contacts.cfg file accordingly.]
vi /usr/local/nagios/etc/objects/contacts.cfg

define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Kedar ; Full name of user
email kedar@nitty-witty.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}

Step-10: Configuring Nagios to Monitor MySQL Server

vi /usr/local/nagios/etc/nagios.cfg
add following line:
cfg_file=/usr/local/nagios/etc/objects/mysqlmonitoring.cfg

Define check_mysql_health command as follows:

vi /usr/local/nagios/etc/objects/commands.cfg

define command{
command_name check_mysql_health
command_line $USER1$/check_mysql_health -H $ARG4$ --username $ARG1$ --password $ARG2$ --port $ARG5$ --mode $ARG3$
}

Enter services to be monitored in mysqlmonitoring.cfg:

vi /usr/local/nagios/etc/objects/mysqlmonitoring.cfg
Add:

define service{
use local-service
host_name localhost
service_description MySQL connection-time
check_command check_mysql_health!nagios!nagios!connection-time!127.0.0.1!3306!
}


define service{
use local-service
host_name localhost
service_description MySQL slave-io-running
check_command check_mysql_health!nagios!nagios!slave-io-running!127.0.0.1!3306!
}


define service{
use local-service
host_name localhost
service_description MySQL slave-sql-running
check_command check_mysql_health!nagios!nagios!slave-sql-running!127.0.0.1!3306!
}

Here we’ve monitored 3 services: Connection-time, io thread and sql thread (replication) status. You can monitor more parameters described here: http://labs.consol.de/nagios/check_mysql_health/

Note: Every time you change configuration file, verify before starting nagios using command:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Finally start nagios service and you’re done with nagios installation and configuration for monitoring MySQL.

Download PDF

I hope you’ve found this useful.

12 Nov

How to Get Stock Quote on Linux using Google ,Curl, Grep, Awk

If you are a Stock Market Addict and a Techie; normally working on Linux(es); this post will interest you as you still can get quote of your stock on your Linux prompt.

Consider, we have Google Finance url for Tata Consultancy Services Stock: http://www.google.com/finance?q=NSE:TCS

So, how do you get above stock price while you’re on Linux / Unix server?
It’s a sinlge line command and you get your stock’s current price. :)

curl --silent -X Get "http://www.google.com/finance?q=NSE:TCS" > /tmp/ChangeIsInevitable && cat /tmp/ChangeIsInevitable | grep -m1 -E 'span id="ref_' | awk -F ">" '{print $2}' | awk -F "<" '{print $1}'

This work for other Stock Exchanges like NYSE as well:

curl --silent -X Get "http://www.google.com/finance?q=nyse:goog" > /tmp/bgz && cat /tmp/bgz | grep -m1 -E 'span id="ref_' | awk -F ">" '{print $2}' | awk -F "<" '{print $1}' && date
617.19
Fri Nov 12 17:07:52 IST 2010

and that’s it. Well, I’m thinking thinking more about further extensions of this.
Special thanks goes to: Jignesh Bhai, Google, Curl, Grep, Awk.

-- Kedar Vaijanapurkar --