Module: check_mk
Branch: master
Commit: 63ce31a7a94e23549796f4a2d82e05d97d60ca28
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=63ce31a7a94e23…
Author: Marcel Arentz <ma(a)mathias-kettner.de>
Date: Wed Apr 5 16:17:40 2017 +0200
4554 FIX cups_queues: Moved agent section into own plugin script
Due performance issues we decided to remove this section from the linux agent
and put into a plugin. Now you are able to define individual caching ages
instead of being forced having a caching of five minutes to satisfy large
environments even if you do not have one.
Change-Id: I068f563794f44f2302f18a242b072a6f20b84d01
---
.werks/4554 | 13 +++++++++++
agents/check_mk_agent.linux | 39 -------------------------------
agents/plugins/mk_cups_queues | 54 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 67 insertions(+), 39 deletions(-)
diff --git a/.werks/4554 b/.werks/4554
new file mode 100644
index 0000000..50f6236
--- /dev/null
+++ b/.werks/4554
@@ -0,0 +1,13 @@
+Title: cups_queues: Moved agent section into own plugin script
+Level: 1
+Component: checks
+Compatible: incomp
+Edition: cre
+Version: 1.5.0i1
+Date: 1491400977
+Class: fix
+
+Due performance issues we decided to remove this section from the linux agent
+and put into a plugin. Now you are able to define individual caching ages
+instead of being forced having a caching of five minutes to satisfy large
+environments even if you do not have one.
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index 8af57f4..caeed2a 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -577,45 +577,6 @@ if [ -e /proc/drbd ]; then
cat /proc/drbd
fi
-# Status of CUPS printer queues
-if type lpstat > /dev/null 2>&1; then
- # Systemd starts cupsd on demand: Instead of checking that the cupsd is
- # running we check that the cups service exists and is enabled.
- if pgrep -f "\bcupsd" > /dev/null 2>&1 \
- || (type systemctl >/dev/null 2>&1 && systemctl is-enabled
cups.service); then
- # first define a function to check cups
- function cups_queues () {
- CPRINTCONF=/etc/cups/printers.conf
- if [ -r "$CPRINTCONF" ] ; then
- LOCAL_PRINTERS=$(grep -E "<(Default)?Printer .*>"
$CPRINTCONF | awk '{print $2}' | sed -e 's/>//')
- lpstat -p | while read LINE
- do
- PRINTER=$(echo $LINE | awk '{print $2}')
- if echo "$LOCAL_PRINTERS" | grep -q "$PRINTER";
then
- echo $LINE
- fi
- done
- echo '---'
- lpstat -o | while read LINE
- do
- PRINTER=${LINE%%-*}
- if echo $LOCAL_PRINTERS | grep -q $PRINTER; then
- echo $LINE
- fi
- done
- else
- lpstat -p
- echo '---'
- lpstat -o | sort
- fi
- }
- # Make cups_queues available for subshell
- export -f cups_queues
- # Use cups_queues function with run_cached and cache time of 5 mins
- run_cached -s cups_queues 300 "cups_queues"
- fi
-fi
-
# Heartbeat monitoring
# Different handling for heartbeat clusters with and without CRM
# for the resource state
diff --git a/agents/plugins/mk_cups_queues b/agents/plugins/mk_cups_queues
new file mode 100755
index 0000000..986a7ef
--- /dev/null
+++ b/agents/plugins/mk_cups_queues
@@ -0,0 +1,54 @@
+#!/bin/bash
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2017 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# tails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+if type lpstat > /dev/null 2>&1 ; then
+ export LC_TIME="en_US.UTF-8"
+ echo "<<<cups_queues>>>"
+ CPRINTCONF=/etc/cups/printers.conf
+ if [ -r "$CPRINTCONF" ] ; then
+ LOCAL_PRINTERS=$(grep -E "<(Default)?Printer .*>" $CPRINTCONF |
awk '{print $2}' | sed -e 's/>//')
+ lpstat -p | while read LINE
+ do
+ PRINTER=$(echo $LINE | awk '{print $2}')
+ if echo "$LOCAL_PRINTERS" | grep -q "$PRINTER"; then
+ echo $LINE
+ fi
+ done
+ echo '---'
+ lpstat -o | while read LINE
+ do
+ PRINTER=${LINE%%-*}
+ if echo $LOCAL_PRINTERS | grep -q $PRINTER; then
+ echo $LINE
+ fi
+ done
+ else
+ PRINTER=$(lpstat -p)
+ echo $PRINTER
+ echo '---'
+ QUEUE=$(lpstat -o | sort)
+ echo $QUEUE
+ fi
+fi