Module: check_mk
Branch: master
Commit: 67c9e598f2b493f6667fda651f8fdb3eefaa97a0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=67c9e598f2b493…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Dec 3 17:46:23 2014 +0100
#1569 check_mk_agent.openbsd: add sections for mem and lnx_if (memory and network
interfaces)
Thanks to Henry Wahl for this contribution.
---
.werks/1569 | 9 +++
ChangeLog | 3 +-
agents/check_mk_agent.openbsd | 136 ++++++++++++++++++++++++++++++++++-------
agents/plugins/lnx_if.bsd | 105 -------------------------------
4 files changed, 125 insertions(+), 128 deletions(-)
diff --git a/.werks/1569 b/.werks/1569
new file mode 100644
index 0000000..64b548b
--- /dev/null
+++ b/.werks/1569
@@ -0,0 +1,9 @@
+Title: check_mk_agent.openbsd: add sections for mem and lnx_if (memory and network
interfaces)
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.5i7
+Date: 1417625147
+Class: feature
+
+Thanks to Henry Wahl for this contribution.
diff --git a/ChangeLog b/ChangeLog
index 17f057c..713e381 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -35,9 +35,10 @@
* 1565 mem.win: set default levels for page file to 80%/90%
* 1608 zpool_status: Add an overall state check (thx to Craig Cook)...
* 1567 postfix_mailq: speedup in Linux agent for large mail queues...
- * 1450 checkpoint_connections, checkpoint_packets: new checks to monitor Checkpoint
firewalls
* 1611 mssql.vbs: Supporting SQL-Server 2014 now
* 1568 f5_bigip_cluster_v11: new check for F5 cluster status for firmware version 11
+ * 1450 checkpoint_connections, checkpoint_packets: new checks to monitor Checkpoint
firewalls
+ * 1569 check_mk_agent.openbsd: add sections for mem and lnx_if (memory and network
interfaces)...
* 1478 FIX: kernel.util, statgrab_cpu: fix computation of utilization...
* 1480 FIX: brocade_vdx_status: disable check on some devices that do not support
it...
* 1485 FIX: dell_om_disks, dell_om_esmlog, dell_om_mem, dell_om_processors,
dell_om_sensors: detect more devices...
diff --git a/agents/check_mk_agent.openbsd b/agents/check_mk_agent.openbsd
index cd25740..75ff1d1 100755
--- a/agents/check_mk_agent.openbsd
+++ b/agents/check_mk_agent.openbsd
@@ -78,7 +78,29 @@ echo `sysctl -n vm.loadavg | tr -d '{}'` `top -b -n 1 | grep -E
'^[0-9]+ process
echo '<<<uptime>>>'
echo `date +%s` - `sysctl -n kern.boottime | cut -d' ' -f 4,7 | tr ','
'.' | tr -d ' '` | bc
-echo '<<<netctr>>>'
+echo "<<<mem>>>"
+MEM_FREE=$(vmstat | tail -n1 | awk '{ print $5 }')
+MEM_TOTAL=$(sysctl hw.usermem | cut -d= -f2)
+MEM_TOTAL=$(echo $MEM_TOTAL/1024 | bc)
+
+SWAPCTL_OUTPUT=$(swapctl -k -s)
+SWAP_FREE=$(echo $SWAPCTL_OUTPUT | awk '{ print $7 }')
+SWAP_TOTAL=$(echo $SWAPCTL_OUTPUT | awk '{ print $2 }')
+
+# if there is no swap space swap values are 0
+if [ -z "$SWAPCTL_OUTPUT" ]
+ then
+ SWAP_FREE=0
+ SWAP_TOTAL=0
+fi
+
+echo "MemTotal:\t" $MEM_TOTAL kB
+echo "MemFree:\t" $MEM_FREE kB
+echo "SwapTotal:\t" $SWAP_TOTAL kB
+echo "SwapFree:\t" $SWAP_FREE kB
+
+echo '<<<lnx_if:sep(58)>>>'
+# MC= MAC address
# BI= Bytes in
# PI= Packets in
# EI= Errors in
@@ -86,33 +108,103 @@ echo '<<<netctr>>>'
# BO= Bytes out
# PO= Packets out
# CO= Colls
-# NI= number of interfaces
+# NI= Number of interfaces
+# INTERFACES= Array of interfaces
+
+set -A INTERFACES
+set -A MC
+set -A BI
+set -A BO
+set -A PI
+set -A PO
+set -A EI
+set -A EO
+set -A CO
-Z1=1
-Z2=p
-NI=$(netstat -in | grep 'Link' | wc -l)
+NI=0
+# special (lo/pfsync/pflog/enc) and inactive (*) interfaces are not needed
+NETSTAT_OUTPUT=$(netstat -in | grep '<Link>' | egrep -v
"\*|lo|pfsync|enc")
+NETSTAT_OUTPUT_BYTES=$(netstat -inb | grep '<Link>' | egrep -v
"\*|lo|pfsync|enc")
+
+# adjust internal field separator to get lines from netstat and backup it before
+OFS=$IFS
+IFS='
+'
+# collect netstat values and interface number
+for NS in $NETSTAT_OUTPUT
+ do
+ NI=$(($NI+1))
+ INTERFACES[$NI]=$(echo $NS | awk '{print $1}')
+ MC[$NI]=$(echo $NS | awk '{print $4}')
+ PI[$NI]=$(echo $NS | awk '{print $5}')
+ EI[$NI]=$(echo $NS | awk '{print $6}')
+ PO[$NI]=$(echo $NS | awk '{print $7}')
+ EO[$NI]=$(echo $NS | awk '{print $8}')
+ CO[$NI]=$(echo $NS | awk '{print $9}')
+done
+
+# need NIC counter again for byte values - reset it
+NI=0
+for NS in $NETSTAT_OUTPUT_BYTES
+ do
+ NI=$(($NI+1))
+ BI[$NI]=$(echo $NS | awk '{print $5}')
+ BO[$NI]=$(echo $NS | awk '{print $6}')
+done
+
+# what is this for?
[ "${NI}" -ge 1 ] || NI=15
+# jot is OpenBSD "range"
+for i in $(jot $NI)
+ do
+ 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"
+done
+
+for IF in $(jot $NI)
+ do
+ echo \[${INTERFACES[$IF]}\]
+
+ IFCONFIG_OUTPUT=$(ifconfig ${INTERFACES[$IF]})
+ for IO in $IFCONFIG_OUTPUT
+ do
+ # Speed
+ SP=$(echo "$IO" | egrep "media:.*base" | cut -d\( -f2 | cut -db
-f1)
+ if [ "$SP" ]
+ then
+ echo "\tSpeed: "$SP"Mb/s"
+ fi
+ # Detect duplexity - in reality only available for physical devices but
+ # virtual ones like CARP devices will get at least a half duplex
+ if [ "$(echo "$IO" | egrep "media:.*full-duplex")" ]
+ then
+ echo "\tDuplex: Full"
+ elif [ "$(echo "$IO" | grep "media:" | grep -v
"full-duplex")" ]
+ then
+ echo "\tDuplex: Half"
+ fi
+ # Auto-negotiation
+ if [ "$(echo "$IO" | egrep "media:.*autoselect")" ]
+ then
+ echo "\tAuto-negotiation: on"
+ elif [ "$(echo "$IO" | grep "media:" | grep -v
"autoselect")" ]
+ then
+ echo "\tAuto-negotiation: off"
+ fi
+ # Detect detected link
+ if [ "$(echo "$IO" | grep "status:" | egrep
"active|backup|master")" ]
+ then
+ echo "\tLink detected: yes"
+ fi
+ done
+
+ echo "\tAddress: "${MC[$IF]}
-date +%s
-while [ $Z1 -lt $NI ]
- do
- BI=$( netstat -inb | egrep -v Name | grep Link | awk '{print $1"
"$5}' | sed -ne $Z1$Z2 )
- PI=$( netstat -in | egrep -v Name | grep Link | awk '{print $5}' | sed -ne
$Z1$Z2 )
- EI=$( netstat -in | egrep -v Name | grep Link | awk '{print $6}' | sed -ne
$Z1$Z2 )
- FF1="0 0 0 0 0"
- BO=$( netstat -inb | egrep -v Name | grep Link | awk '{print $6}' | sed -ne
$Z1$Z2 )
- PO=$( netstat -in | egrep -v Name | grep Link | awk '{print $7}' | sed -ne
$Z1$Z2 )
- EO=$( netstat -in | egrep -v Name | grep Link | awk '{print $8}' | sed -ne
$Z1$Z2 )
- CO=$( netstat -in | egrep -v Name | grep Link | awk '{print $9}' | sed -ne
$Z1$Z2 )
- FF2="0 0"
- if [ "$(echo ${PI} | cut -c 1-3)" -gt 0 ]
- then
- echo $BI $PI $EI $FF1 $BO $PO $EO $FF2 $CO $FF2
- fi
- Z1=$(($Z1+1))
done
+# reset IFS to default
+IFW=$OFS
+
# IPMI-Data (Fans, CPU, temperature, etc)
# needs the sysutils/ipmitool and kldload ipmi.ko
if which ipmitool >/dev/null ; then
diff --git a/agents/plugins/lnx_if.bsd b/agents/plugins/lnx_if.bsd
deleted file mode 100755
index 7b5b686..0000000
--- a/agents/plugins/lnx_if.bsd
+++ /dev/null
@@ -1,105 +0,0 @@
-echo '<<<lnx_if:sep(58)>>>'
-# MC= MAC address
-# BI= Bytes in
-# PI= Packets in
-# EI= Errors in
-# EO= Errors out
-# BO= Bytes out
-# PO= Packets out
-# CO= Colls
-# NI= Number of interfaces
-# INTERFACES= Array of interfaces
-
-set -A INTERFACES
-set -A MC
-set -A BI
-set -A BO
-set -A PI
-set -A PO
-set -A EI
-set -A EO
-set -A CO
-
-NI=0
-# special (lo/pfsync/pflog/enc) and inactive (*) interfaces are not needed
-NETSTAT_OUTPUT=$(netstat -in | grep '<Link>' | egrep -v
"\*|lo|pfsync|enc")
-NETSTAT_OUTPUT_BYTES=$(netstat -inb | grep '<Link>' | egrep -v
"\*|lo|pfsync|enc")
-
-# adjust internal field separator to get lines from netstat and backup it before
-OFS=$IFS
-IFS='
-'
-# collect netstat values and interface number
-for NS in $NETSTAT_OUTPUT
- do
- NI=$(($NI+1))
- INTERFACES[$NI]=$(echo $NS | awk '{print $1}')
- MC[$NI]=$(echo $NS | awk '{print $4}')
- PI[$NI]=$(echo $NS | awk '{print $5}')
- EI[$NI]=$(echo $NS | awk '{print $6}')
- PO[$NI]=$(echo $NS | awk '{print $7}')
- EO[$NI]=$(echo $NS | awk '{print $8}')
- CO[$NI]=$(echo $NS | awk '{print $9}')
-done
-
-# need NIC counter again for byte values - reset it
-NI=0
-for NS in $NETSTAT_OUTPUT_BYTES
- do
- NI=$(($NI+1))
- BI[$NI]=$(echo $NS | awk '{print $5}')
- BO[$NI]=$(echo $NS | awk '{print $6}')
-done
-
-# what is this for?
-[ "${NI}" -ge 1 ] || NI=15
-
-# jot is OpenBSD "range"
-for i in $(jot $NI)
- do
- 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"
-done
-
-for IF in $(jot $NI)
- do
- echo \[${INTERFACES[$IF]}\]
-
- IFCONFIG_OUTPUT=$(ifconfig ${INTERFACES[$IF]})
- for IO in $IFCONFIG_OUTPUT
- do
- # Speed
- SP=$(echo "$IO" | egrep "media:.*base" | cut -d\( -f2 | cut -db
-f1)
- if [ "$SP" ]
- then
- echo "\tSpeed: "$SP"Mb/s"
- fi
- # Detect duplexity - in reality only available for physical devices but
- # virtual ones like CARP devices will get at least a half duplex
- if [ "$(echo "$IO" | egrep "media:.*full-duplex")" ]
- then
- echo "\tDuplex: Full"
- elif [ "$(echo "$IO" | grep "media:" | grep -v
"full-duplex")" ]
- then
- echo "\tDuplex: Half"
- fi
- # Auto-negotiation
- if [ "$(echo "$IO" | egrep "media:.*autoselect")" ]
- then
- echo "\tAuto-negotiation: on"
- elif [ "$(echo "$IO" | grep "media:" | grep -v
"autoselect")" ]
- then
- echo "\tAuto-negotiation: off"
- fi
- # Detect detected link
- if [ "$(echo "$IO" | grep "status:" | egrep
"active|backup|master")" ]
- then
- echo "\tLink detected: yes"
- fi
- done
-
- echo "\tAddress: "${MC[$IF]}
-
-done
-
-# reset IFS to default
-IFW=$OFS