Monday, 9 January 2012

Port Check with Nagios


Multiple Port Check Plugin for Nagios

#!/bin/bash
#
# Usage: .//check_system_pp
#
# Discription:
# This plugin determine whether the server
# is running properly. It will check the following:
# * Are all the required TCP/IP ports open or not?
#
# Created:      25.12.2011 (IN)
#
#
#

##################################################################################
##
#
# Ports to check

PORT1="21"
PORT2="22"
PORT3="53"
PORT4="80"

##################################################################################

PATH="/usr/bin:/usr/sbin:/bin:/sbin"

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4

print_gpl() {
    echo "This program is free software; you can redistribute it and/or modify"
    echo "it under the terms of the GNU General Public License as published by"
    echo "the Free Software Foundation; either version 2 of the License, or"
    echo "(at your option) any later version."
    echo ""
    echo "This program is distributed in the hope that it will be useful,"
    echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
    echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the"
    echo "GNU General Public License for more details."
    echo ""
    echo "You should have received a copy of the GNU General Public License"
    echo "along with this program; if not, write to the Free Software"
    echo "Nilesh Kumar, New delhi 110067, India"
}

print_help(){
        echo "System process and port check script for Nagios."
        echo "Tested on RHE3/4/5/6, CentOS 4/5/6, Fedora 4, Solaris 9"
        echo ""
        echo "Usage: ./check_system_pp"
        echo "Website: http://www.nagiosexchange.org"
        echo ""
    print_gpl
}

while test -n "$1"
do
        case "$1" in
          *) print_help; exit $STATE_OK;;
        esac
done

check_port1()
{
        PORTS="0"
        ERROR_PORTS=""
        for NUM in `echo $PORT1`; do
                if [ `nmap 127.0.0.1 --system-dns | grep -w $NUM | grep -v grep | wc -l` -lt 1 ]; then
                        PORTS=1
                        ERROR_PORTS="$ERROR_PORTS""$NUM ";
                fi
        done

        if [ $PORTS -eq "1" ]; then
                exit_port1=$STATE_CRITICAL
        elif [ $PORTS -eq "0" ]; then
        exit_port1=$STATE_OK
    fi
}
check_port1

check_port2()
{
        PORTS="0"
        ERROR_PORTS=""
        for NUM in `echo $PORT2`; do
                if [ `nmap 127.0.0.1 --system-dns | grep -w $NUM | grep -v grep | wc -l` -lt 1 ]; then
                        PORTS=1
                        ERROR_PORTS="$ERROR_PORTS""$NUM ";
                fi
        done

        if [ $PORTS -eq "1" ]; then
                exit_port2=$STATE_CRITICAL
        elif [ $PORTS -eq "0" ]; then
        exit_port2=$STATE_OK
    fi
}
check_port2

check_port3()
{
        PORTS="0"
        ERROR_PORTS=""
        for NUM in `echo $PORT3`; do
                if [ `nmap 127.0.0.1 --system-dns | grep -w $NUM | grep -v grep | wc -l` -lt 1 ]; then
                        PORTS=1
                        ERROR_PORTS="$ERROR_PORTS""$NUM ";
                fi
        done

        if [ $PORTS -eq "1" ]; then
                exit_port3=$STATE_CRITICAL
        elif [ $PORTS -eq "0" ]; then
        exit_port3=$STATE_OK
    fi
}
check_port3

check_port4()
{
        PORTS="0"
        ERROR_PORTS=""
        for NUM in `echo $PORT4`; do
                if [ `nmap 127.0.0.1 --system-dns | grep -w $NUM | grep -v grep | wc -l` -lt 1 ]; then
                        PORTS=1
                        ERROR_PORTS="$ERROR_PORTS""$NUM ";
                fi
        done

        if [ $PORTS -eq "1" ]; then
                exit_port4=$STATE_CRITICAL
        elif [ $PORTS -eq "0" ]; then
        exit_port4=$STATE_OK
    fi
}
check_port4

port_exit1=`expr $exit_port1`
port_exit2=`expr $exit_port2`
port_exit3=`expr $exit_port3`
port_exit4=`expr $exit_port4`

#
if [ $port_exit1 -eq "0" ]; then
    p1u=$PORT1,; else
    p1d=$PORT1,
fi
#
if [ $port_exit2 -eq "0" ]; then
    p2u=$PORT2,; else
    p2d=$PORT2,
fi
#
if [ $port_exit3 -eq "0" ]; then
    p3u=$PORT3,; else
    p3d=$PORT3,
fi
#
if [ $port_exit4 -eq "0" ]; then
    p4u=$PORT4; else
    p4d=$PORT4
fi
#

UP=`echo $p1u $p2u $p3u $p4u`
DOWN=`echo $p1d $p2d $p3d $p4d`

final_exit=`expr $exit_port1 + $exit_port2 + $exit_port3 + $exit_port4`

if [ $final_exit -eq "0" ]; then
    echo "Port $p1u $p2u $p3u $p4u UP and no any port DOWN"
    exitstatus=$STATE_OK
elif [ $final_exit -eq "1" ]; then
    echo "Port $p1u $p2u $p3u $p4u UP and Port $p1d $p2d $p3d $p4d DOWN"
    exitstatus=$STATE_WARNING
elif [ $final_exit -ge "1" ]; then
    echo "Port $p1u $p2u $p3u $p4u UP and Port $p1d $p2d $p3d $p4d DOWN"
    exitstatus=$STATE_CRITICAL
fi

exit $exitstatus

RAID Metadata Error


BIOS RAID Metadata Error

This type of error may be occurred due to if the hard drive previously installed in those systems which configured with hardware RAID and when we use this hard drive in another system that has not hardware RAID so that error may appear and during installation of Linux OS on create partition windows the hard drive latter may be appear like as “/dev/mapper/…”. Until we correct this error, OS cannot install on this hard drive. If may be install Linux OS but cannot boot the OS.

To correct this problem follow the instructions bellow.

First of all attach the error hard drive as secondary with any Linux primary hard drive and boot the system with primary hard drive.

Now open terminal and run the following command on the terminal.
# fdisk   -l                               (To check the details of disk status).
# cat /dev/zero > /dev/sdx    (where sdx is our secondary hard drive letter).

It will repair the all block of hard drive as zero i.e. low level formatting.

This command will take time as depend upon size of hard drive it will take about 1Hr or more than this to take terminal back.

After terminal is getting back turn off the system and unattached the secondary hard drive.

If we want to check the hard drive RAID Metadata problem is solved or not. Attach only this hard drive in the system and boot the system with Linux DVD and check this on were we create partitions during Linux installation. Here should show the hard drive physical path as “/dev/hda” for IDE or “/dev/sad” for SATA/SCSI.

Access NTFS from Linux

Access NTFS file-system from Linux

There are some method of accessing windows system from a Linux system one of them I use to prefer is ntfs-3g driver.

First of all, we must have “ntfs-3g” package for accessing windows NTFS file system through Linux file system which can be download through  this link http://www.ntfs-3g.org/

            Package Recuired:
1. fuse-2.6.0
2. ntfs-3g-1.913.tgz

Check to see if you have the required package, FUSE 2.6.0 or later. We assume our system already has one, follow the given process as…
# yum list installed | grep fuse
# tar xvzf ntfs-3g-1.913.tgz              (Extract the ntfs-3g driver package)

Install ntfs-3g driver as…
# cd ntfs-3g-1.913
# ./configure
# make
# make install

Try to mount NTFS hard disk in /mnt or we can make another mount point (Folder) for access it.
# mkdir /mnt/windows
# mount  -t ntfs-3g /dev/sdb1 /mnt/windows

If it had already been mounted somehow, unmount it first.
# umount /meia/My\ Book/
# mount -t ntfs-3g /dev/sdb1 /mnt/windows

Sometimes, you may need to enforce mounting like
# mount -t ntfs-3g /dev/sdb1 /mnt/windows -o force

To unmount the volume, type
# umount /mnt/windows

To view the all mount file-system information, type
# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/sdb1 on /mnt/windows type fuseblk (rw,nosuid,nodev,noatime,allow_other,blksize=4096)

# more /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
devpts /dev/pts devpts gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0

Note: Sometimes we need “fuse” to access it. So Installing FUSE (File-system in User space). Download the latest stable release from http://fuse.sourceforge.net

Extract the fuse package for installing.
# tar xvzf fuse-2.7.0.tar.gz

Install FUSE by using these steps.
# cd fuse-2.7.0
# ./configure
# make
# make install

Friday, 23 December 2011

Nagios Script

System Process and Port check script for Nagios

#!/bin/bash
#
# Usage: .//check_system_pp
#
# Description:
# This plugin determines whether the server
# is running properly. It will check the following:
# * Are all required processes running?
# * Are all the required TCP/IP ports open?
#
# Created:      27.01.2006 (FBA)
#
# Changes:      28.01.2006      added yellow check (FBA)
#               29.01.2006      change "px -ef" to "ps -ax" (FBA). Problems with long arguments
#               31.01.2006      added all OK Status with all procs and ports (FBA)
#           15.07.2006      change "ps -ax" to "ps ax" (FBA). Also problems with long arguments under RedHat 3/4
#           17.07.2006  Plugin rewrite and bugfixes (Magnus Glantz)
#           19.07.2006  Removed utils.sh dependency.
#
#
#

##################################################################################
#
# Processes to check
PROCLIST_RED="bearerbox"
PROCLIST_YELLOW=""

# Ports to check
PORTLIST=""

##################################################################################

PATH="/usr/bin:/usr/sbin:/bin:/sbin"

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4

print_gpl() {
    echo "This program is free software; you can redistribute it and/or modify"
    echo "it under the terms of the GNU General Public License as published by"
    echo "the Free Software Foundation; either version 2 of the License, or"
    echo "(at your option) any later version."
    echo ""
    echo "This program is distributed in the hope that it will be useful,"
    echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
    echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the"
    echo "GNU General Public License for more details."
    echo ""
    echo "You should have received a copy of the GNU General Public License"
    echo "along with this program; if not, write to the Free Software"
    echo "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA"
}

print_help(){
        echo ""
        echo "System process and port check script for Nagios."
      echo "Tested on RHE3/4, Fedora 4, Solaris 9"
      echo ""
        echo "Usage: ./check_system_pp"
        echo "Website: http://www.nagiosexchange.org"
      echo ""
      print_gpl
}

while test -n "$1"
do
        case "$1" in
          *) print_help; exit $STATE_OK;;
        esac
done

check_processes_red()
{
        PROCESS="0"
        ERROR_PROCS=""
        for PROC in `echo $PROCLIST_RED`; do
        if [ `ps -ef | grep $PROC | grep -v grep | wc -l` -lt 1 ]; then
                        PROCESS=1
                        ERROR_PROCS="$ERROR_PROCS""$PROC ";
        fi
        done

        if [ $PROCESS -eq "1" ]; then
                exit_red=$STATE_CRITICAL
      elif [ $PROCESS -eq "0" ]; then
            exit_red=$STATE_OK
        fi
}

check_processes_yellow()
{
        PROCESS="0"
        WARNING_PROCS=""
        for PROC in `echo $PROCLIST_YELLOW`; do
        if [ `ps -ef | grep $PROC | grep -v grep | wc -l` -lt 1 ]; then
                        PROCESS=1
                        WARNING_PROCS="$WARNING_PROCS""$PROC ";
        fi
        done

        if [ $PROCESS -eq "1" ]; then
                exit_yellow=$STATE_WARNING
        elif [ $PROCESS -eq "0" ]; then
            exit_yellow=$STATE_OK
      fi
}

check_ports()
{
        PORTS="0"
        ERROR_PORTS=""
        for NUM in `echo $PORTLIST`; do
                if [ `netstat -an | grep LISTEN | grep $NUM | grep -v grep | wc -l` -lt 1 ]; then
                        PORTS=1
                        ERROR_PORTS="$ERROR_PORTS""$NUM ";
                fi
        done

        if [ $PORTS -eq "1" ]; then
                exit_ports=$STATE_CRITICAL
        elif [ $PORTS -eq "0" ]; then
            exit_ports=$STATE_OK
      fi
}

check_processes_red
check_ports
check_processes_yellow

final_exit=`expr $exit_ports + $exit_red + $exit_yellow`

if [ $final_exit -eq "0" ]; then
      echo "Bearerbox  is running"
      exitstatus=$STATE_OK
elif [ $final_exit -eq "1" ]; then
        echo "Bearerbox is down"
      exitstatus=$STATE_WARNING
elif [ $final_exit -ge "1" ]; then
      echo "Bearerbox is Down"
      exitstatus=$STATE_CRITICAL
fi

exit $exitstatus
 

Saturday, 17 December 2011

HDR Photography


Photoshop HDR and Photomatix Tone Mapping
Introduction:
In this tutorial we will take a look at HDR photography. HDRI (High Dynamic Range Imaging) was originally used in 3D and is now in full force in photography. Basically it's the process of taking multiple exposures and merging them together into a single 32 bit image. Let me explain: A camera is capable of capturing a limited amount of tones in a single photo. Typically we sacrifice elements in a photo when we press the shutter. For example there is a powerful cloudscape and some cliffs. If we expose for the clouds the cliffs become dark. If we set the camera's exposure to capture detail in the cliffs, the brighter sky is blown out and detail is lost. This is because the human eye can see a larger range of tones than the camera can capture on the chip or film in a single photograph.
The solution is to take more than one photograph and bracket the photos. Shoot normal exposure, then under-expose a shot to capture highlights and over-expose a shot to capture shadow detail. Finally, merge these photos together to produce a single image with a larger range of tones that can now show all the details in the shadows and highlights. This tutorial will show you how to complete this process with the minimum fuss.
            First we need to get our source images. (You could begin with a 32 bit 3D image and then skip to step 6). Typically we will capture these with our camera. You will need to shoot a minimum of 2 photos with different exposure settings.
            It’s been recommended by Adobe to limit the bracketing by 1 stop and this will help reduce banding. You may also take 5 or more shots with a smaller gap in the bracketing. I personally get good results from 3 shots. I like to over expose and under expose by 2 stops. I know this is a bigger bracket than most people are comfortable with, but for the type of HDR images I like to create (cityscapes), this works great. If you’re shooting people, you may want to reduce this to even 3rd stops.
            (Note: You can't use a single raw image and exposure it several times as some people suggest, for a true HDR photo. This is known as pseudo-HDR. Photoshop will not allow you to merge these because there isn't sufficient tone detail captured).
Step 1:
Start with 3 images. One normal exposure, the second underexposed and the third overexposed. In this case I used 2 stop bracketing. As I shoot a lot of city scapes I can get away with 2 stops, because I'm mainly shooting flat surfaces and banding and posterization isn't such a problem. If your shooting rounded and curved surfaces you will want to lower your bracketing to get smoother gradients.
            I set the bracketing on my camera to 2 stops. Then I set the shooting mode to burst. When I hold the shutter down, 3 photos will be captured. I shoot in RAW mode for the widest possible dynamic range. You can still create HDR if your camera doesn't support RAW. Make sure you shoot in Aperture Priority or in Manual. You want to bracket the exposure time, not the Aperture. If you change the aperture, the depth of field won't be consistent and you'll get blurring. Also avoid any moving subjects in the photo or you'll get ghosting.

Step 2:
Time to merge the photos together into a single 32 bit image.
            Choose File>Automate >Merge to HDR. This works on Photoshop CS2 and CS3. (CS2 Doesn't have auto align). Choose either images or folder. I organize each set of photos in its own folder so I used the folder option. Select your photos to merge. Turn on Auto Align in Photoshop CS3. Click OK. (Photoshop CS3 uses new Auto-align technology that even allows you to create HDR without the use of a tripod!)


Step 3:
            Your images will now be merged into a single photo. You can turn off individual photos by un checking their boxes on the left filmstrip. If you get some blurring caused by camera shake in the longest exposure, you may want to turn off that photo.


Step 4:
            The merged result is a floating-point 32 bit image. You can adjust the overall tones by sliding the White Point slider. Easy with it, a little movement goes a long way!


Step 5:
            Click OK to merge the photos into a 32 bit image. Now is a good time to save your file.


Step 6:
            In order to use the photos, you'll need to convert them t 16 or 8 bit images. When we convert them we will create what I call interpretations of the photo. The reason I say this is because we have unlimited ways we can make the photo look. While we have this huge dynamic range available in 32 bit, we will no longer have those options after conversion. Always work from the saved 32 bit version, and then convert and save versions (personal interpretations). Avoid overwriting the 32 bit image, it's our master and we may want to go back to it many times.
            Choose Image>Mode>16 bit (or 8 bit). Now we get to play with some fun options. You're now at the tone mapping part of the process. This is were all the creativity can ooze.
            (If you want to make the adjustments without converting, choose view>32 Bit Preview Options. You can use several of Photoshop's tools in the Image>Adjustments menu. The most important of these is the Exposure control)
            You'll see an HDR Conversion Dialog box. Exposure and Gamma is the default option. Best way to approach this? Set the gamma first, then adjust the exposure to suit. If you want an image with lots of contrast, lower the gamma. For less contrast raise the gamma. Finally, adjust the exposure to get the desired brightness. If you want more control, read on... otherwise press OK to convert.


Step 7:
            Change the Method to Local Adaption. (There are 4 available methods, but these are the only 2 with user input).
            With local Adaption, you can adjust the curves. Set these like you would normally work in curves, but don't be afraid to clip the histogram a little. You can clip because your working with a larger dynamic range than you're used to. Bring out the detail in the image, but don't forget to put some shadow in there or it will look washed out and fake. Once your happy with the curve, adjust the radius and Threshold sliders to make sure there are no halos in the photo. (Badly converted HDR images have a glow around the areas of contrast.) The radius controls the mask blur while the threshold decides what gets blurred and what doesn't.
            Click ok to convert.


Step 8:
            Here we have a merged image from HDR. The second image is a variation. In the second variation, I applied exposure, curves and sharpening settings while in 32-bit mode (Highlight Compression Method). Photoshop is great for producing very realistic HDR images.


            Step 9:
            If you desire a more surreal result there is different plug-ins that you can use. My favourite is Photomatix pro from HDR soft. You can just get the tone mapping plug in for Photoshop which works great. Use the coupon code Photoshop cafe to save 15%.
            Using photomatix tone mapping plugin allows you to get highly detailed textures in your photographs. You merge in Photoshop as shown in this tutorial. Then choose Filter>Photomatix to apply tone mapping. Convert and save as normal.


            Step 10:
            This image shows an image after tone mapping using Photomatix pro.


Step 11:
          Here you can see comparisons between single images; subtle Photoshop HDR and a radical Photomatix effect (Click for larger image). Whatever result you’re after, hopefully this tutorial has helped demystify the HDR process.


Step 12:
            Here is another HDR shot of mine. This is a night scene converted to grayscale.


            I hope you enjoyed this tutorial!

Friday, 16 December 2011

eth up/down

Up another LAN interface if one is link down
#!/bin/bash

# Periodically check a interface for link up.
# If found the current interface link down,
# up another interface and down the current interface.
# It consume about 0.3% of CPU and 0.1% of Memory.

while :
do

if [[ $(ip link show | grep eth0 | cut -d ',' -f 3) = UP ]]
then
echo eth0 Up > /dev/null
else
        if [[ $(ip link show | grep eth1 | cut -d ',' -f 3) = UP ]]
        then
        echo eth1 already Up > /dev/null
        else
        /sbin/ifup eth1 &> /dev/null
        /sbin/ifdown eth0 &> /dev/null
        fi
fi

sleep 1

if [[ $(ip link show | grep eth1 | cut -d ',' -f 3) = UP ]]
then
echo eth1 Up > /dev/null
else
        if [[ $(ip link show | grep eth0 | cut -d ',' -f 3) = UP ]]
        then
        echo eth0 already Up > /dev/null
        else
        /sbin/ifup eth0 &> /dev/null
        /sbin/ifdown eth1 &> /dev/null
        fi
fi

sleep 1

done

Boot to UEFI Mode or legacy BIOS mode

Boot to UEFI Mode or legacy BIOS mode Choose UEFI or legacy BIOS modes while installing Windows. After Windows is installed, if you nee...