-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_xio_connected_host_status.bash
173 lines (138 loc) · 4.87 KB
/
check_xio_connected_host_status.bash
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/bash
# Copyright (C) 2019 - Joseph Hardeman <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation version 3 of the License
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------------------
# configuration
# --------------------------------------------------------------------
PROGNAME=$(basename $0)
ERR_MESG=()
LOGGER="`which logger` -i -p kern.warn -t"
AUTO=0
AUTOIGNORE=0
IGNOREFSTAB=0
WRITETEST=0
export PATH="/bin:/usr/local/bin:/sbin:/usr/bin:/usr/sbin:/usr/sfw/bin"
LIBEXEC="/opt/nagios/libexec /usr/lib64/nagios/plugins /usr/lib/nagios/plugins /usr/local/nagios/libexec /usr/local/icinga/libexec /usr/local/libexec /opt/csw/libexec/nagios-plugins"
for i in ${LIBEXEC} ; do
[ -r ${i}/utils.sh ] && . ${i}/utils.sh
done
if [ -z "$STATE_OK" ]; then
echo "nagios utils.sh not found" &>/dev/stderr
exit 1
fi
# --------------------------------------------------------------------
# functions
# --------------------------------------------------------------------
function log() {
$LOGGER ${PROGNAME} "$@";
}
function usage() {
echo -e "Usage: $PROGNAME [-H HOSTNAME] -v [snmp version] -C [Community String]"
echo "Usage: $PROGNAME -h,--help"
echo "Options:"
echo " -H Hostname or IP of XIO Storage Device"
echo " -v SNMP version (default: 2c)"
echo " -C SNMP Community String (default: public)"
}
function print_help() {
echo ""
usage
echo ""
echo "Check the status of the XIO Storage Unit Connected Hosts."
echo ""
echo "This plugin is NOT developped by the Nagios Plugin group."
echo "Please do not e-mail them for support on this plugin, since"
echo "they won't know what you're talking about."
echo ""
echo "For contact info, read the plugin itself..."
}
function contains() {
local n=$#
local value=${!n}
for ((i=1;i < $#;i++)) {
if [ "${!i}" == "${value}" ]; then
echo "y"
return 0
fi
}
echo "n"
return 1
}
function ConnectedHost_status() {
#Need to take this number and loop thru to pull stats
iseTotalHosts="SNMPv2-SMI::enterprises.2366.6.1.2.1.2.34.0"
TotalHosts=`snmpget -Oqv -v $SNMP_VERSION -c $COMMUNITY $HOSTNAME $iseTotalHosts`
oidnumber=1
totalhostcount=$TotalHosts
declare -a dpsc
declare -a info
declare -a cdc
for i in `seq $totalhostcount`
do
# Stating at NMPv2-SMI::enterprises.2366.6.1.2.1.9.1 start counting up till you reach the total number of hosts connected
Name="SNMPv2-SMI::enterprises.2366.6.1.2.1.9.${oidnumber}.1.0"
Os="SNMPv2-SMI::enterprises.2366.6.1.2.1.9.${oidnumber}.2.0"
Id="SNMPv2-SMI::enterprises.2366.6.1.2.1.9.${oidnumber}.3.0"
StatusStr="SNMPv2-SMI::enterprises.2366.6.1.2.1.9.${oidnumber}.4.0"
StatusDetailsStr="SNMPv2-SMI::enterprises.2366.6.1.2.1.9.${oidnumber}.5.0"
hoststatus=`snmpget -Oqv -v $SNMP_VERSION -c $COMMUNITY $HOSTNAME $StatusStr`
hostname=`snmpget -Oqv -v $SNMP_VERSION -c $COMMUNITY $HOSTNAME $Name`
hoststatus=`sed -e 's/^"//' -e 's/"$//' <<<"$hoststatus"`
if [ $hoststatus == "Operational" ]
then
info[$oidnumber]="OK - Host $hostname: $hoststatus, "
dpsc[$oidnumber]="0"
else
info[$oidnumber]="CRITICAL - Host $hostname: $hoststatus, "
dpsc[$oidnumber]="2"
fi
let oidnumber=$oidnumber+1
done
echo "${info[@]}"
if [ $(contains "${dpsc[@]}" "2") == "y" ]
then
exit 2
else
exit 0
fi
}
# --------------------------------------------------------------------
# startup checks
# --------------------------------------------------------------------
if [ $# -eq 0 ]; then
usage
exit $STATE_CRITICAL
fi
# --------------------------------------------------------------------
# Default States
# --------------------------------------------------------------------
SNMP_VERSION="2c"
COMMUNITY="public"
# --------------------------------------------------------------------
# pull in variables
# --------------------------------------------------------------------
while [ "$1" != "" ]
do
case "$1" in
--help) print_help; exit $STATE_OK;;
-h) print_help; exit $STATE_OK;;
-H) HOSTNAME=$2; shift 2;;
-v) SNMP_VERSION=$2; shift 2;;
-C) COMMUNITY=$2; shift 2;;
*) usage; exit $STATE_UNKNOWN;;
esac
done
#
#
ConnectedHost_status