Currency rate monitor script

December 10th, 2008

Using Nagios I am able to monitor the currency conversion rate, so I can know exactly when to sell my currency and to buy my currency. I wrote a creative plugin to nagios that does just that!
Its not my best bash code, I should really rewrite in perl. But the idea is here, and it works.
Anyone wants to build a nagios just to monitor and graph currency exchange rates? I am up for it.
Example:
bash currencymon.sh
Usage: currencymon.sh [--minwarn value] [--maxwarn value] [--mincrit value] [--maxcrit value] [-v|--verbose]
# bash currencymon.sh 2.65 2.95 2.55 3.15
MONEYX OK: Value of EURO is - 3.1623
The current conversion is from Euro x Real, inside the script there is a parameter to change it.
currencymon.sh

#!/bin/bash
#Script to monitor Money Conversion Rates
#####################################################
# Nagios plugin to monitor currency exchange value #
#####################################################
#Author Felipe Ferreira Version: 1.0 Date: 16/10/2008
#Melhoras:
#Allow passing the Conversion Type as Param
#Allow graphing inside Nagios

VERBOSE=0
MINCRIT=0
MINWARN=0
MAXCRIT=99999999
MAXWARN=99999999
VALUE=0
CONVERSION=”EURBRL”
#CONVERSION=”BRLEUR”

# Test if Arguments are passed to script
outputDebug() {
if [ $VERBOSE -gt 0 ] ; then
echo $1
fi
}
# no args passed, TEMP output string variable
if [ $# -eq 0 ] ; then
TEMP=”-h”
#getpot parses the args
else
TEMP=`getopt -o vhm -l ‘help,verbose,minwarn:,mincrit:,maxwarn:,maxcrit:’ — “$@”`
fi

outputDebug “Processing Args $TEMP”
if [ $? != 0 ] ; then echo “Terminating…” >&2 ; exit 1 ; fi
eval set — “$TEMP”

while true ; do
case “$1″ in
-v|–verbose) VERBOSE=1 ; outputDebug “Verbose Mode ON” ; shift ;;
-h|–help) echo “Usage: $0 [--minwarn value] [--maxwarn value] [--mincrit value] [--maxcrit value] [-v|--verbose] ” ; exit 0;;
–minwarn) outputDebug “Option $1 is $2″ ; MINWARN=$2 ; shift 2;;
–maxwarn) outputDebug “Option $1 is $2″ ; MAXWARN=$2 ; shift 2;;
–mincrit) outputDebug “Option $1 is $2″ ; MINCRIT=$2 ; shift 2;;
–maxcrit) outputDebug “Option $1 is $2″ ; MAXCRIT=$2 ; shift 2;;
# –conv) outputDebug “Option $1 is $2″ ; CONVERSION=$2 ; shift 2;;
–) shift ; break ;;
*) echo “Internal error! - found $1 and $2″ ; exit 3 ;;
esac
done

#echo “CONVERSION is $CONVERSION”

assertSizeOK() {
outputDebug ” EURO is $1 validating ”
if awk ‘BEGIN{if(0+’$1′<'$MINCRIT'+0)exit 0;exit 1}'
then
echo "MONEYX Critical: Min Crit is $MINCRIT and Value of EURO - $VALUE" ; exit 2
fi
if awk 'BEGIN{if(0+'$1'<'$MINWARN'+0)exit 0;exit 1}'
then
echo "MONEYX Warning: Min Warn is $MINWARN and Value of EURO - $VALUE" ; exit 1
fi
if awk 'BEGIN{if(0+'$1'>‘$MAXCRIT’+0)exit 0;exit 1}’
then
echo “MONEYX Critical: Max Cirtical is $MAXCRIT and Value of EURO - $VALUE” ; exit 2
fi
if awk ‘BEGIN{if(0+’$1′>’$MAXWARN’+0)exit 0;exit 1}’
then
echo “MONEYX Warning: Max warn $MAXWARN Value of EURO - $VALUE” ; exit 1
fi
}

getValue()
{
cd /tmp
#Get the info from yahoo
wget -q -O euro.csv wget “http://download.finance.yahoo.com/d/quotes.csv?s=$CONVERSION=X&f=l1&e=.csv”
VALUE=`cat euro.csv`
#Should remove .
#cat euro.csv | sed -e “s/./_/” >>euro2.txt
#cat euro.csv | sed -i e ’s/./_/g’>>euro2.txt
#VALUE=`cat euro2.txt`
#echo $VALUE
}

getValue
assertSizeOK $VALUE $1
echo “MONEYX OK: Value of EURO is - $VALUE”
exit 0

BashScripts, HowTo, Linux, Nagios

Uninstall Gnome and Office

December 10th, 2008

If you have a server there is no need of the GUI interface, is there?
A good linux admin will never need it. So I am removing it, here are the commands:
Remove GUI (Gnome)
# apt-get remove gnome\*
# apt-get remove \*xorg\*
# apt-get remove mplayer\*

And to remove Office.
# apt-get remove openoffice.org
If it is a server and you dont mind the extra junk space, at least disable from startup
Remove GUI from boot up ( Free up memory):
# update-rc.d -f gdm remove
To start GUI:
# startx
To have it GUI startup again:
# /usr/sbin/update-rc.d gdm defaults

The main reason one would uninstall gnome , is to free space on the disk.
It will free up about 600 MB.
To troubleshoot space problems you can use these commands:
Find the current disk space utilization:
# df -k
# du -kx / | sort -nr | less
Find the biggest folders:
# find / -type f -ls | sort -k 7 -r -n | grep -v ‘/bin’ | head
Folder sizes:
# du –summarize –human-readable

HowTo, Linux

Nagios Nuvola Style

December 5th, 2008

*****Make Nagios Pretty ( Nuvola Style )

First Backup /usr/local/nagios/share/*..html and all stylesheets directory.
# cd /usr/local/nagios/share
# wget http://www.xoroz.com/files/nagiosstyle.zip
# unzip nagiosstyle.zip
Set the permissions
# chown nagios:nagios *.*
# chown nagios:nagios -R side
# chown nagios:nagios -R stylesheet
Edit the config.js with your correct cgi-bin
# /etc/init.d/apache2 restart

*******More cool cmds Get an overview of all hosts (new cmd with nagios 2.11)
# /usr/local/nagios/bin/nagiostats /usr/local/nagios/etc/nagios.cfg -v NUMHOSTS
********Autostart Daemon only with Debian
# /usr/sbin/update-rc.d mysql defaults
*********Install FIREFOX ADD-ON NAGIOS CHECKER

https://addons.mozilla.org/en-US/firefox/addon/3607

************Troubleshooting problems…
Check my older post

HowTo, Nagios

Mental Multiplication Trick

December 2nd, 2008

Amazing Multiplication Trick

Multiply With Lines

News