-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmoneyconversioncheck
95 lines (83 loc) · 2.83 KB
/
moneyconversioncheck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/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;;
--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