Showing posts with label Step-by-Step. Show all posts
Showing posts with label Step-by-Step. Show all posts

Friday, July 31, 2009

Nagios - Alerting by SMS using ClickATell

ClickATell is a SMS gateway supporting email to SMS, direct HTTP and other methods.

  • create libexec/send_sms


#!/bin/sh

# This function call the clickatell through HTTP instead of Email to SMS

# Print the help and exit.
dumphelp(){
echo "send_sms "
exit
}

# Check if number of parameter is 1. If not, print the help and exit.
if [ $# -ne 2 ]; then
dumphelp
fi

NAGIOSHOME=/usr/local/nagios
NAGIOSLOG=$NAGIOSHOME/var
SMSLOG=$NAGIOSLOG/sms.log

USER="XXXXXXX"
PASSWORD="XXXXXXX"
API_ID="XXXXXXXX"

PHONE=$1
MSG=$2

# As calling through HTTP instead of email to SMS, need to replace all space with +
MSG1=`echo $2 | sed "s/ /+/g"`

# Get the current log time
LOGTIME=`date "+%Y%m%d %H:%M:%S.%N"`

echo "$LOGTIME [To: $PHONE] [Msg: $MSG1]" >> $SMSLOG

wget -q -O /tmp/sms.html "http://api.clickatell.com/http/sendmsg?user=$USER&password=$PASSWORD&api_id=$API_ID&to=$PHONE&text=$MSG1"

  • Add the following to command.cfg



# 'notify-host-by-sms' command definition
define command{
command_name notify-host-by-sms
command_line $USER1$/send_sms $CONTACTPAGER$ "$NOTIFICATIONTYPE$ $HOSTALIAS$ $HOSTSTATE$ [$HOSTOUTPUT$]"
}

# 'notify-service-by-sms' command definition
define command{
command_name notify-service-by-sms
command_line $USER1$/send_sms $CONTACTPAGER$ "$NOTIFICATIONTYPE$ $SERVICEDESC$ $HOSTALIAS$ $SERVICESTATE$ [$SERVICEOUTPUT$]"
}


  • Add the generic-sms-contact to templates.cfg


define contact{
name generic-sms-contact ; The name of this contact template
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-sms ; send service notifications via sms
host_notification_commands notify-host-by-sms ; send host notifications via sms
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}


  • Add the following to contacts.cfg


# Define the person to receive the SMS
define contact{
contact_name SMS.XXX
use generic-sms-contact
alias System Admin
email AAA@bbb.ccc.com
pager 1234567890
}

# Define the SMS contact group
define contactgroup{
contactgroup_name SMS_ABCDE
alias Server Application Admin
members SMS.XXX
}


  • Use the SMS_ABCDE in the contact_groups when you define the service/host.
  • That's all.

Wednesday, July 22, 2009

Nagios Plugin - NConf

URL: NConf

Prerequisite
  • PHP
  • MySQL - Create a catalog for nconf. (e.g. catalog=nconf, username=nconf, password=nconf)
Installation Steps
  • Get the file from NConf
  • Assume your document root is /var/www


> tar xvfz nconf-1.2.5-0.tgz
> cp nconf /var/www
> Go to http://localhost/nconf and follow the steps


Should have folder authentication problem when generate the config. Following steps solve the problem:
> sudo vigr
# Add the user www-data to group nagios
nagios:x:1002:nagios,www-data

> sudo chmod g+w -R nagios
> sudo chown www-data:nagios /var/www/nconf

> restart apache

  • Done

Sunday, July 19, 2009

Nagios Installation in Ubuntu

Download the latest version 3.1.2.

Add new users nagios and nagiosadmin
> sudo adduser nagios
> sudo adduser nagiosadmin


Configure and install Nagios
> tar xvfz nagios-3.1.2.tar.gz
> cd nagios-3.1.2
> ./configure --with-nagios-user=nagios --with-nagios-group=nagios
> make all
> make fullinstall
> htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
> /etc/init.d/apache2 reload


Get the server to start the nagios when reboot
> sudo ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios


Install the plugin.
Download the Plugin 1.4.13
> ./configure
> make
> sudo make install
> sudo chown nagios:nagios /usr/local/nagios -R


  • Start FireFox
  • http://localhost/nagios
  • Enter nagiosadmin and the password

Wednesday, May 13, 2009

Easy steps to upgrade Ubuntu from 8.10 to 9.04

  1. Check your Ubuntu version

  2. lsb_release -a


  3. Apply all updates for your Ubuntu 8.10

  4. sudo apt-get update

    sudo apt-get upgrade


  5. Upgrade from Ubuntu 8.10 to 9.04

  6. sudo do-release-upgrade


  7. Check your Ubuntu version

  8. lsb_release -a


  9. Bingo.

Thursday, April 30, 2009

Ext JS - Grid - Fetch Website Information into Tabs - Task Reload

To reload a task periodically is pretty easy. Add the following in the js\grid.js.

Ext.TaskMgr.start({
run: storeprice.reload,
scope: storeprice,
interval: 120000 // 1000 = 1 second
});

Ext.TaskMgr.start({
run: storeah.reload,
scope: storeah,
interval: 120000 // 1000 = 1 second
});

Tuesday, April 14, 2009

Apache + PHP (Windows) Step-By-Step

  1. Download the 2.2.11 windows binary from Apache
  2. Run to install Apache. Assuming you are installed to C:\Program Files\Apache Software Foundation\Apache2.2
  3. Download the PHP windows binary (Zip Package) from PHP.net
  4. Unzip the package and put everything inside c:\php
  5. Copy c:\php\php.ini-recommended to c:\php\php.ini
  6. Assume your web root folder is C:\WebRoot
  7. Edit the php.ini

  8. doc_root = "C:\WebRoot"


    upload_max_files = 10M /* Modify the maximum upload file size to 10 megabytes, default 2 M */

    uncomment the following line for using MySQL or other lines for other database
    extension=php_mysql.dll
    extension=php_mysqli.dll

  9. Edit the Apache conf\http.conf

  • Change the DocumentRoot to your webroot
  • Change the <Directory "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs"> to <Directory "C:/WebRoot">
  • Change the Deny from all to Allow from all
  • Add the following line to conf\http.conf
    # Configure the path for php.ini
    PHPIniDir "C:/php"
    LoadModule php5_module "C:/php/php5apache2_2.dll"