2 # Check_MK Agent for Mac OS/X
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 # NOTE: This agent has beed adapted from the Check_MK linux agent.
29 # Remove locale settings to eliminate localized outputs where possible
30 # Author: Christian Zigotzky <info@xenosoft.de>
34 export MK_LIBDIR
="/to/be/changed"
35 export MK_CONFDIR
="/to/be/changed"
37 # Optionally set a tempdir for all subsequent calls
40 # close standard input (for security reasons) and stderr
50 echo "Version: 1.6.0i1"
51 echo "AgentOS: macosx"
52 echo "Hostname: $(hostname)"
53 echo "AgentDirectory: $MK_CONFDIR"
54 echo "DataDirectory: $MK_VARDIR"
55 echo "SpoolDirectory: $SPOOLDIR"
56 echo "PluginsDirectory: $PLUGINSDIR"
57 echo "LocalDirectory: $LOCALDIR"
62 df
-kPT hfs
,apfs |
sed 1d | \
63 while read DEV REST
; do
64 TYPE
=$
(diskutil info
"$DEV" |
grep '^\s*Type' | cut
-d: -f2 |
tr -d '[:space:]')
65 echo "$DEV $TYPE $REST"
69 echo `sysctl -n vm.loadavg | tr -d '{}'` `top -l 1 -n 1 | egrep ^Processes: |
70 awk '{print $4"/"$2;}'` `echo 'echo $$' | bash` `sysctl -n hw.ncpu`
73 echo "MemTotal: $(echo $(sysctl -n hw.memsize)/1024 | bc) kB"
74 echo "MemFree: $(echo "( $
(vm_stat |
grep speculative
: |
awk '{print $3}') + $
(vm_stat |
grep inactive
: |
awk '{print $3}') + $
(vm_stat |
grep free
: |
awk '{print $3}') ) * $
(vm_stat |
grep Mach |
awk '{print $8}') / 1024" | bc) kB"
75 echo "SwapTotal: 0 kB"
77 # FIXME: Just call vm_stat here, write a check plugin that uses that
78 # navite output of vm_stat
81 echo `date +%s` - `sysctl -n kern.boottime | cut -d' ' -f 4,7 | tr ',' '.' |
83 # FIXME: use sysctl -a for outputting *all* kernel values. Write
84 # checks plugins with subchecks for parsing that output. Maybe reduce
85 # the output size by grepping away totally useless parts
88 date +'%s'; netstat
-inb |
egrep -v '(^Name|lo|plip)' |
grep Link |
awk '{
89 print $1,$7,$5,$6,"0","0","0","0","0",$10,$8,$9,"0","0",$11,"0","0"; }'
90 # FIXME: send netstat -inb plain, write proper check plugins for
91 # clean parsing of the output
94 ps ax
-o user
,vsz
,rss
,pcpu
,command |
sed -e 1d
-e 's/ *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) *\([^ ]*\) */(\1,\2,\3,\4) /'
96 # NTP seems to be enabled as a default
97 if which ntpq
>/dev
/null
; then
99 ntpq
-np |
sed -e 1,2d
-e 's/^\(.\)/\1 /' -e 's/^ /%/'
103 echo '<<<tcp_conn_stats>>>'
104 netstat
-ntfinet |
awk ' /^tcp/ { c[$6]++; } END { for (x in c) { print x, c[x]; } }'
107 # Fileinfo-Check: put patterns for files into /etc/check_mk/fileinfo.cfg
108 if [ -r "$MK_CONFDIR/fileinfo.cfg" ]; then
109 echo '<<<fileinfo:sep(124)>>>'
114 # let the shell do all the expansion, and pipe all files to perl
115 (cat "$MK_CONFDIR/fileinfo.cfg" "$MK_CONFDIR/fileinfo.d/*" 2>/dev
/null
) |
while read -r pattern
; do
117 /*) pattern
=$
(replace_datevariable
"$pattern")
118 for f
in $pattern; do echo $f; done
123 print "[[[header]]]\n";
124 print "name|status|size|time\n";
125 print "[[[content]]]\n";
130 print "$_|missing\n";
133 ($device, $inode, $mode, $nlink, $uid, $gid, $rdev, $size,
134 $atime, $mtime, $ctime, $blksize, $blocks) = stat($_);
136 print "$_|stat failed\n";
138 print "$_|ok|$size|$mtime\n";
141 set +vx
; eval "$old_state"
145 if type tmutil
>/dev
/null
147 echo '<<<timemachine>>>'
148 tmutil latestbackup
2>&1
151 ###############################
152 # Things up for takers:
153 ###############################
154 # *OSX SW Raid status
155 # *launchctl daemon status
156 # *hw sensors, how to query them?
157 # *OSX Server specific stuff, LDAP, etc...
158 # *Rewrite cpu / ps check to be faster - takes >1s on my laptop
159 # ioreg -l zeigt etliche interessante Inventurdaten
162 # MK's Remote Plugin Executor
163 if [ -e "/etc/mrpe.cfg" ]
166 grep -Ev '^[[:space:]]*($|#)' "/etc/mrpe.cfg" | \
167 while read descr cmdline
169 PLUGIN
=${cmdline%% *}
170 OUTPUT
=$
(eval "$cmdline")
171 echo "(${PLUGIN##*/}) $descr $? $OUTPUT" |
tr \\n
\\1