2Jan/110

Pingdom Update Contact for On Call Roster

Posted by Rianto Wahyudi


#!/bin/bash
# Script to update contact details on pingdom
# Accept phone number as the first argument
# Pingdom will automatically add +61[mobile number] - so the zero '0' prefix in front of mobile number need to be stripped
# Valid input : 432123456
# No error checking on this script as 'we know what we are doing(tm)'

# Change Log:
# 20100809 (rwahyudi) - Create script
# 20100820 (rwahyudi) - Add simple check

USERNAME=username@company.com
PASSWD=XXXXXX
MAIL=oncall-update@company.com
DIR=/opt/scripts/pingdom

if [ $# -lt 1 ]; then
echo "Usage: $0 [mobile number]"
echo " Pingdom will automatically add +61[mobile number] - so the zero '0' prefix in front of mobile number need to be stripped"
echo "Example: $0 432123456"
exit 1
fi

# Remove Cookie and login
rm $DIR/cookie.txt
curl -x proxy.company.com:8080 -c $DIR/cookie.txt -d "username=$USERNAME&password=$PASSWD " https://pp.pingdom.com/index.php/login

# Edit OnCall contact
# OnCall ID = 12345
# See posting on how to get this value
curl -x proxy.company.com:8080 -b $DIR/cookie.txt -d "name=OnCall&email=OnCall%40company.com&country=15&phone=$1&twitter_dm=1&twitter_user=&defaultprovider=3&retryprovider=1&Submit=Update+Contact" https://pp.pingdom.com/index.php/member/contacts/edit/12345

# Check contact and email details on update to confirm that contact has been updated
PINGDOM_ACTIVE_NUMBER=$(curl -sq -b $DIR/cookie.txt https://pp.pingdom.com/index.php/member/contacts | grep -A1 " OnCall

"  | grep "+61-" | cut -d '-' -f2 | cut -d'<' -f1)
PINGDOM_ACTIVE_ONCALL=$(grep $PINGDOM_ACTIVE_NUMBER $DIR/phonelist.csv  | cut -d ',' -f1)

echo "
`date`

Pingdom active On-Call : $PINGDOM_ACTIVE_ONCALL

"| mail -s "$PINGDOM_ACTIVE_ONCALL ($CRT_ACTIVE_ONCALL) is now the active On-Call contact"  $MAIL
27Nov/100

Bash script : DNS Check match between reverse and forward lookup

Posted by Rianto Wahyudi

Basic bash lookup script to check if forward / reverse IP address is matching.

  • The script use host command, it'llĀ  automatically add DNS prefix based on /etc/resolv.conf
  • Support for hostnamesĀ  or PTR address with multiple RR
./checkhost
Usage: ./checkhost <IP or hostname> checkhost<IP or hostname> ...
Example: ./checkhost 69.163.128.215 www pop3.iinet.net.au
This script will check if forward and reverse match

./checkhost shadow pop3.iinet.net.au 202.138.0.9
shadow <-> 69.163.128.215 : Match
pop3.iinet.net.au <-> 203.0.178.192 : Match
mud.starway.net.au <-> 202.138.0.9 : Match

Download the script here :

checkhost
17Nov/101

NFS Monitoring Scripts

Posted by Rianto Wahyudi

I've tried few different NFS mount check, but most of them hang or freeze when the remote server is not responding. So I created a simple script to monitor and automatically mount NFS which kill it self .

I put this script on crontab which then run every 15 minutes :
cron entries :

*/15 * * * * /root/bin/check_nfs.sh

check_nfs.sh :

#!/bin/bash
# Script to check if NFS is mounted properly
# Change Log :

# Script to check and monitor NFS mounted file system

# When NFS is not working, it may hang the process that try to access it.
# As a work around, we start a process in the background that will kill nfs_check script after 30 seconds
# However, if check command works then kill the process that was about to kill me ( killmyparrent.sh )

REMOTE_SERVER=remotenfsserver.example.com
mnt_partition=/remote/nfs/folder/

# Exit if another instance is running
if [ `ps auxwww | grep check_nfs.sh | wc -l` -gt 3 ]
then
echo `pgrep check_nfs.sh | wc -l`
exit
fi

if mount | grep -q $mnt_partition
then :

/root/bin/killmyparent.sh $ "Email Subject - eg : NFS mount failed on xxx server" "Some issue with $mnt_parition. Please check it will you !" &
killerpid=`pgrep killmyparent.sh`

# NFS file system appear to be mounted - lets check if we can access it ..
if df | grep -q $mnt_partition
then :
# df command works .. kill "killmyparent.sh" script before it kill us
kill $killerpid
exit 1;
fi
else
# Wait until server is contactible and then mount the partition
until [ `ping -q -c3 -w5 $REMOTE_SERVER > /dev/null 2>&1; echo $?` -eq 0 ]
do
sleep 10;
done
mount $mnt_partition
exit $?
fi

killmyparent.sh

#!/bin/bash
if [ -z $1 ]
then
echo "Usage $0 "
exit
fi
sleep 20
kill -9 $1
echo $3 | mail -s $2