-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_route.sh
129 lines (111 loc) · 3.16 KB
/
check_route.sh
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/sh
# Description :
# This Plugin checks a specific number of jump, in a traceroute command.
# You can define one primary Route(Expected:OK status) and a Secondary
# Route(Fallback: Warning status). If this number of Jump doesn't match any
# of the above, it goes to critical status.
#
# License : GPL
#
# by Karl Alexander Monzon.
# fixed by Nicolas Le Gall
#
# Requirements :
# Traceroute command and permisions.
#
# Version 1.0 : 07/01/2007
# Initial release.
#
# Version 1.1 : 14/04/2017
# Remove useless code
# Reformat switch case
# Change debug output
#
################################################################################
PROGNAME="check_route"
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`echo '$Revision: 1.0 $' | sed -e 's/[^0-9.]//g'`
#
# Initalize a few variables
#
HOSTADDRESS=$1
NJUMP=$2
ROUTE1=$3
ROUTE2=$4
DEBUG=$5
OUTPUT=''
EXITCODE=3
ERRORMSG="There was a problem."
print_help() {
echo "Nagios Plugin: $PROGNAME $REVISION"
echo "by Karl Alexander Monzon"
echo "fixed by Nicolas Le Gall"
echo ""
echo "Usage: $PROGNAME"
echo "check_route [host ip] [jump] [route 1] [route 2] <debug>"
echo " "
echo "Options:"
echo "[host]: The name or IP address of the server to check."
echo "[jump]: The number of jump to evaluate."
echo "[route 1]: The IP address of the primary node to check."
echo "[route 2]: The IP address of the Secundary node to check."
echo "<debug> [0|1]: optional Parameter. Shows the command for debuging."
echo " "
echo "Example:"
echo "check_route 10.160.254.1 2 192.168.1.1 10.160.2.1"
exit 0
}
case "$1" in
--help | -h)
print_help
exit 0
;;
--version)
print_revision $PROGNAME $REVISION
exit 0
;;
-V)
print_revision $PROGNAME $REVISION
exit 0
;;
*)
if [ "$#" -lt 4 ]; then
echo "This plugin requires 4 arguments."
exit "4"
fi
if [ "$#" == 4 ]; then
DEBUG=0
fi
JUMP=`expr $NJUMP + 1`
RESULT=`traceroute -n $HOSTADDRESS | head -n $JUMP | tail -n 1`
if [ $DEBUG == 1 ]; then
echo "command : traceroute -n $HOSTADDRESS | head -n $JUMP | tail -n 1"
fi
SALTO=`echo $RESULT | cut -f 2 -d " "`
if [ $DEBUG == 1 ]; then
echo "find : $SALTO"
fi
# Check for the error message in the error file.
SUCCESS=`echo $RESULT | wc -l`
if [ $SUCCESS == 0 ]; then
OUTPUT="Error connecting to server running on $HOSTNAME."
EXITCODE=2
else
if [ $SALTO == $ROUTE1 ]; then
OUTPUT="TRACE OK: Primary Route $SALTO"
EXITCODE=0
else
if [ $SALTO == $ROUTE2 ]; then
OUTPUT="TRACE Warning: Secondary Route $SALTO"
EXITCODE=1
else
OUTPUT="TRACE Critical : Current Route to: $HOSTADDRESS via: $SALTO"
EXITCODE=2
fi
fi
fi
# Cleaning up.
echo $OUTPUT
exit $EXITCODE
;;
esac