Cleanup config.nodes_of
[check_mk.git] / agents / check_mk_agent.openbsd
blob945ff5afce3987eced66a14694693de080cb4e1d
1 #!/bin/sh
2 # Check_MK Agent for OpenBSD
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
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
34 export LC_ALL=C
35 unset LANG
37 export MK_LIBDIR="/usr/lib/check_mk_agent"
38 export MK_CONFDIR="/etc"
40 # Optionally set a tempdir for all subsequent calls
41 #export TMPDIR=
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
58 if [ "$1" = -d ]
59 then
60 set -xv
61 else
62 exec <&- 2>/dev/null
65 echo "<<<check_mk>>>"
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"
75 osver="$(uname -r)"
77 echo '<<<df>>>'
78 df -kPt ffs | sed -e 's/^\([^ ][^ ]*\) \(.*\)$/\1 ffs \2/' | sed 1d
80 # processes including username, without kernel processes
81 echo '<<<ps>>>'
82 COLUMNS=10000
83 ps ax -o user,vsz,rss,pcpu,command | sed -e 1d -e 's/ *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) */(\1,\2,\3,\4) /'
85 echo '<<<cpu>>>'
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`
88 echo '<<<uptime>>>'
89 echo `date +%s` - `sysctl -n kern.boottime | cut -d' ' -f 4,7 | tr ',' '.' | tr -d ' '` | bc
91 echo "<<<mem>>>"
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" ]
102 then
103 SWAP_FREE=0
104 SWAP_TOTAL=0
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)>>>'
113 # MC= MAC address
114 # BI= Bytes in
115 # PI= Packets in
116 # EI= Errors in
117 # EO= Errors out
118 # BO= Bytes out
119 # PO= Packets out
120 # CO= Colls
121 # NI= Number of interfaces
122 # INTERFACES= Array of interfaces
124 set -A INTERFACES
125 set -A MC
126 set -A BI
127 set -A BO
128 set -A PI
129 set -A PO
130 set -A EI
131 set -A EO
132 set -A CO
134 NI=0
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
140 OFS=$IFS
141 IFS='
143 # collect netstat values and interface number
144 for NS in $NETSTAT_OUTPUT
146 NI=$(($NI+1))
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}')
154 done
156 # need NIC counter again for byte values - reset it
157 NI=0
158 for NS in $NETSTAT_OUTPUT_BYTES
160 NI=$(($NI+1))
161 BI[$NI]=$(echo $NS | awk '{print $5}')
162 BO[$NI]=$(echo $NS | awk '{print $6}')
163 done
165 # what is this for?
166 [ "${NI}" -ge 1 ] || NI=15
168 # jot is OpenBSD "range"
169 for i in $(jot $NI)
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"
172 done
174 for IF in $(jot $NI)
176 echo \[${INTERFACES[$IF]}\]
178 IFCONFIG_OUTPUT=$(ifconfig ${INTERFACES[$IF]})
179 for IO in $IFCONFIG_OUTPUT
181 # Speed
182 SP=$(echo "$IO" | egrep "media:.*base" | cut -d\( -f2 | cut -db -f1)
183 if [ "$SP" ]
184 then
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")" ]
190 then
191 echo "\tDuplex: Full"
192 elif [ "$(echo "$IO" | grep "media:" | grep -v "full-duplex")" ]
193 then
194 echo "\tDuplex: Half"
196 # Auto-negotiation
197 if [ "$(echo "$IO" | egrep "media:.*autoselect")" ]
198 then
199 echo "\tAuto-negotiation: on"
200 elif [ "$(echo "$IO" | grep "media:" | grep -v "autoselect")" ]
201 then
202 echo "\tAuto-negotiation: off"
204 # Detect detected link
205 if [ "$(echo "$IO" | grep "status:" | egrep "active|backup|master")" ]
206 then
207 echo "\tLink detected: yes"
209 done
211 echo "\tAddress: "${MC[$IF]}
213 done
215 # reset IFS to default
216 IFS=$OFS
218 # IPMI-Data (Fans, CPU, temperature, etc)
219 # needs the sysutils/ipmitool and kldload ipmi.ko
220 if which ipmitool >/dev/null ; then
221 echo '<<<ipmi>>>'
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>>>'
231 mailq | tail -n 6
235 # Einbinden von lokalen Plugins, die eine eigene Sektion ausgeben
236 if cd $PLUGINSDIR
237 then
238 for skript in $(ls)
240 if [ -x "$skript" ] ; then
241 ./$skript
243 done
246 # Lokale Einzelchecks
247 echo '<<<local>>>'
248 if cd $LOCALDIR
249 then
250 for skript in $(ls)
252 if [ -x "$skript" ] ; then
253 ./$skript
255 done
258 # MK's Remote Plugin Executor
259 if [ -e "$MK_CONFDIR/mrpe.cfg" ]
260 then
261 echo '<<<mrpe>>>'
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
268 echo
269 done