Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / agents / check_mk_agent.macosx
blobd997dcec5117307e3a0b9ffe3dc6dafd4b29cf6e
1 #!/bin/sh
2 # Check_MK Agent for Mac OS/X
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 # 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>
31 export LC_ALL=C
32 unset LANG
34 export MK_LIBDIR="/to/be/changed"
35 export MK_CONFDIR="/to/be/changed"
37 # Optionally set a tempdir for all subsequent calls
38 #export TMPDIR=
40 # close standard input (for security reasons) and stderr
41 if [ "$1" = -d ]
42 then
43 set -xv
44 else
45 exec <&- 2>/dev/null
49 echo "<<<check_mk>>>"
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"
59 osver="$(uname -r)"
61 echo '<<<df>>>'
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"
66 done
68 echo '<<<cpu>>>';
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`
72 echo '<<<mem>>>'
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"
76 echo "SwapFree: 0 kB"
77 # FIXME: Just call vm_stat here, write a check plugin that uses that
78 # navite output of vm_stat
80 echo '<<<uptime>>>';
81 echo `date +%s` - `sysctl -n kern.boottime | cut -d' ' -f 4,7 | tr ',' '.' |
82 tr -d ' '` | bc
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
87 echo '<<<netctr>>>';
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
93 echo '<<<ps>>>'
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
98 echo '<<<ntp>>>'
99 ntpq -np | sed -e 1,2d -e 's/^\(.\)/\1 /' -e 's/^ /%/'
102 # TCP Conn stats
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)>>>'
111 old_state=$(set +o)
112 set +f
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
116 case $pattern in
117 /*) pattern=$(replace_datevariable "$pattern")
118 for f in $pattern; do echo $f; done
120 esac
121 done | perl -e '
122 print time."\n";
123 print "[[[header]]]\n";
124 print "name|status|size|time\n";
125 print "[[[content]]]\n";
126 while (<>) {
127 chomp $_;
128 if (-d $_) { next; }
129 if (not -f $_) {
130 print "$_|missing\n";
131 next;
133 ($device, $inode, $mode, $nlink, $uid, $gid, $rdev, $size,
134 $atime, $mtime, $ctime, $blksize, $blocks) = stat($_);
135 if ($!) {
136 print "$_|stat failed\n";
137 } else {
138 print "$_|ok|$size|$mtime\n";
141 set +vx; eval "$old_state"
145 if type tmutil >/dev/null
146 then
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" ]
164 then
165 echo '<<<mrpe>>>'
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
172 echo
173 done