2 # Check_MK Agent for OpenBSD
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
10 # | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
11 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
16 # check_mk is free software; you can redistribute it and/or modify it
17 # under the terms of the GNU General Public License as published by
18 # the Free Software Foundation in version 2. check_mk is distributed
19 # in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
20 # out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
21 # PARTICULAR PURPOSE. See the GNU General Public License for more de-
22 # tails. You should have received a copy of the GNU General Public
23 # License along with GNU Make; see the file COPYING. If not, write
24 # to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
25 # Boston, MA 02110-1301 USA.
27 # Author: Lars Michelsen <lm@mathias-kettner.de>
28 # Florian Heigl <florian.heigl@gmail.com>
29 # Christian Zigotzky <chzigotzky@xenosoft.de>
31 # NOTE: This agent has been adapted from the Check_MK FreeBSD agent.
33 # Remove locale settings to eliminate localized outputs where possible
37 export MK_LIBDIR
="/usr/lib/check_mk_agent"
38 export MK_CONFDIR
="/etc"
40 # Optionally set a tempdir for all subsequent calls
43 # Make sure, locally installed binaries are found
44 PATH
=$PATH:/usr
/local
/bin
46 # All executables in PLUGINSDIR will simply be executed and their
47 # ouput appended to the output of the agent. Plugins define their own
48 # sections and must output headers with '<<<' and '>>>'
49 PLUGINSDIR
=$MK_LIBDIR/plugins
51 # All executables in LOCALDIR will by executabled and their
52 # output inserted into the section <<<local>>>. Please refer
53 # to online documentation for details.
54 LOCALDIR
=$MK_LIBDIR/local
57 # close standard input (for security reasons) and stderr
66 echo "Version: 1.6.0i1"
67 echo "AgentOS: openbsd"
68 echo "Hostname: $(hostname)"
69 echo "AgentDirectory: $MK_CONFDIR"
70 echo "DataDirectory: $MK_VARDIR"
71 echo "SpoolDirectory: $SPOOLDIR"
72 echo "PluginsDirectory: $PLUGINSDIR"
73 echo "LocalDirectory: $LOCALDIR"
78 df
-kPt ffs |
sed -e 's/^\([^ ][^ ]*\) \(.*\)$/\1 ffs \2/' |
sed 1d
80 # processes including username, without kernel processes
83 ps ax
-o user
,vsz
,rss
,pcpu
,command |
sed -e 1d
-e 's/ *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) */(\1,\2,\3,\4) /'
86 echo `sysctl -n vm.loadavg | tr -d '{}'` `top -b -n 1 | grep -E '^[0-9]+ processes' | awk '{print $3"/"$1}'` `sysctl -n hw.ncpu`
89 echo `date +%s` - `sysctl -n kern.boottime | cut -d' ' -f 4,7 | tr ',' '.' | tr -d ' '` |
bc
92 MEM_FREE
=$
(vmstat |
tail -n1 |
awk '{ print $5 }')
93 MEM_TOTAL
=$
(sysctl hw.usermem | cut
-d= -f2)
94 MEM_TOTAL
=$
(echo $MEM_TOTAL/1024 |
bc)
96 SWAPCTL_OUTPUT
=$
(swapctl
-k -s)
97 SWAP_FREE
=$
(echo $SWAPCTL_OUTPUT |
awk '{ print $7 }')
98 SWAP_TOTAL
=$
(echo $SWAPCTL_OUTPUT |
awk '{ print $2 }')
100 # if there is no swap space swap values are 0
101 if [ -z "$SWAPCTL_OUTPUT" ]
107 echo "MemTotal:\t" $MEM_TOTAL kB
108 echo "MemFree:\t" $MEM_FREE kB
109 echo "SwapTotal:\t" $SWAP_TOTAL kB
110 echo "SwapFree:\t" $SWAP_FREE kB
112 echo '<<<lnx_if:sep(58)>>>'
121 # NI= Number of interfaces
122 # INTERFACES= Array of interfaces
135 # special (lo/pfsync/pflog/enc) and inactive (*) interfaces are not needed
136 NETSTAT_OUTPUT
=$
(netstat
-in |
grep '<Link>' |
egrep -v "\*|lo|pfsync|enc")
137 NETSTAT_OUTPUT_BYTES
=$
(netstat
-inb |
grep '<Link>' |
egrep -v "\*|lo|pfsync|enc")
139 # adjust internal field separator to get lines from netstat and backup it before
143 # collect netstat values and interface number
144 for NS
in $NETSTAT_OUTPUT
147 INTERFACES
[$NI]=$
(echo $NS |
awk '{print $1}')
148 MC
[$NI]=$
(echo $NS |
awk '{print $4}')
149 PI
[$NI]=$
(echo $NS |
awk '{print $5}')
150 EI
[$NI]=$
(echo $NS |
awk '{print $6}')
151 PO
[$NI]=$
(echo $NS |
awk '{print $7}')
152 EO
[$NI]=$
(echo $NS |
awk '{print $8}')
153 CO
[$NI]=$
(echo $NS |
awk '{print $9}')
156 # need NIC counter again for byte values - reset it
158 for NS
in $NETSTAT_OUTPUT_BYTES
161 BI
[$NI]=$
(echo $NS |
awk '{print $5}')
162 BO
[$NI]=$
(echo $NS |
awk '{print $6}')
166 [ "${NI}" -ge 1 ] || NI
=15
168 # jot is OpenBSD "range"
171 echo "${INTERFACES[$i]}:${BI[$i]} ${PI[$i]} ${EI[$i]} 0 0 0 0 0 ${BO[$i]} ${PO[$i]} ${EO[$i]} 0 0 ${CO[$i]} 0 0"
176 echo \
[${INTERFACES[$IF]}\
]
178 IFCONFIG_OUTPUT
=$
(ifconfig
${INTERFACES[$IF]})
179 for IO
in $IFCONFIG_OUTPUT
182 SP
=$
(echo "$IO" |
egrep "media:.*base" | cut
-d\
( -f2 | cut
-db -f1)
185 echo "\tSpeed: "$SP"Mb/s"
187 # Detect duplexity - in reality only available for physical devices but
188 # virtual ones like CARP devices will get at least a half duplex
189 if [ "$(echo "$IO" | egrep "media
:.
*full-duplex
")" ]
191 echo "\tDuplex: Full"
192 elif [ "$(echo "$IO" | grep "media
:" | grep -v "full-duplex
")" ]
194 echo "\tDuplex: Half"
197 if [ "$(echo "$IO" | egrep "media
:.
*autoselect
")" ]
199 echo "\tAuto-negotiation: on"
200 elif [ "$(echo "$IO" | grep "media
:" | grep -v "autoselect
")" ]
202 echo "\tAuto-negotiation: off"
204 # Detect detected link
205 if [ "$(echo "$IO" | grep "status
:" | egrep "active|backup|master
")" ]
207 echo "\tLink detected: yes"
211 echo "\tAddress: "${MC[$IF]}
215 # reset IFS to default
218 # IPMI-Data (Fans, CPU, temperature, etc)
219 # needs the sysutils/ipmitool and kldload ipmi.ko
220 if which ipmitool
>/dev
/null
; then
222 ipmitool sensor list \
223 |
grep -v 'command failed' \
224 |
sed -e 's/ *| */|/g' -e "s/ /_/g" -e 's/_*$//' -e 's/|/ /g' \
225 |
egrep -v '^[^ ]+ na ' \
226 |
grep -v ' discrete '
229 if which mailq
>/dev
/null
2>&1 && getent passwd postfix
>/dev
/null
2>&1; then
230 echo '<<<postfix_mailq>>>'
235 # Einbinden von lokalen Plugins, die eine eigene Sektion ausgeben
240 if [ -x "$skript" ] ; then
246 # Lokale Einzelchecks
252 if [ -x "$skript" ] ; then
258 # MK's Remote Plugin Executor
259 if [ -e "$MK_CONFDIR/mrpe.cfg" ]
262 grep -Ev '^[[:space:]]*($|#)' "$MK_CONFDIR/mrpe.cfg" | \
263 while read descr cmdline
265 PLUGIN
=${cmdline%% *}
266 OUTPUT
=$
(eval "$cmdline")
267 echo -n "(${PLUGIN##*/}) $descr $? $OUTPUT" |
tr \\n
\\1