error if there are no pending updates
Message-ID: <570fa1b9.Jofu7dVeWvTQc529%si(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 3667851567f54fff28af2e38fb3db6c901ca7f69
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3667851567f54f…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Thu Apr 14 15:56:10 2016 +0200
3409 FIX apt: fixed 'UNKNOWN - Item not found in agent output' error if there are
no pending updates
---
.werks/3409 | 10 ++++++++++
ChangeLog | 1 +
agents/plugins/mk_apt | 15 +++++++++++++--
checks/apt | 9 ++++++++-
4 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/.werks/3409 b/.werks/3409
new file mode 100644
index 0000000..21d9fc9
--- /dev/null
+++ b/.werks/3409
@@ -0,0 +1,10 @@
+Title: apt: fixed 'UNKNOWN - Item not found in agent output' error if there are
no pending updates
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.9i1
+Date: 1460642074
+
+
diff --git a/ChangeLog b/ChangeLog
index 0fe2aed..de4e421 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -149,6 +149,7 @@
* 3406 FIX: hp_proliant_temp: fixed wrong params data type
* 3408 FIX: temperature.include: now does not ignore levels with value 0 any more
* 3122 FIX: netapp_fcpio: the rules for this check are now actually used...
+ * 3409 FIX: apt: fixed 'UNKNOWN - Item not found in agent output' error if
there are no pending updates
Multisite:
* 3187 notification view: new filter for log command via regex
diff --git a/agents/plugins/mk_apt b/agents/plugins/mk_apt
index 3905e28..5abcf4f 100755
--- a/agents/plugins/mk_apt
+++ b/agents/plugins/mk_apt
@@ -40,10 +40,21 @@
UPGRADE=upgrade
DO_UPDATE=yes
-if type apt-get > /dev/null ; then
- echo '<<<apt:sep(0)>>>'
+
+function check_apt_update {
if [ "$DO_UPDATE" = yes ] ; then
apt-get update -qq
fi
apt-get -o 'Debug::NoLocking=true' -s -qq "$UPGRADE" | grep -v
'^Conf'
+}
+
+
+if type apt-get > /dev/null ; then
+ echo '<<<apt:sep(0)>>>'
+ out=$(check_apt_update)
+ if [ -z $out ]; then
+ echo "No updates pending for installation"
+ else
+ echo $out
+ fi
fi
diff --git a/checks/apt b/checks/apt
index a00ae6c..c9bb04e 100644
--- a/checks/apt
+++ b/checks/apt
@@ -39,15 +39,18 @@
# Inst libpolkit-gobject-1-0 [0.105-4ubuntu2] (0.105-4ubuntu2.14.04.1
Ubuntu:14.04/trusty-updates [amd64])
# Inst libxext-dev [2:1.3.2-1] (2:1.3.2-1ubuntu0.0.14.04.1 Ubuntu:14.04/trusty-security
[amd64]) []
+
factory_settings["apt_default_levels"] = {
"normal" : 1,
"security" : 2,
}
+
# Check that the apt section is in valid format of mk_apt plugin and not
# from the apt agent plugin which can be found on the Check_MK exchange.
def apt_valid_info(info):
- return info and len(info[0]) == 1 and len(info[0][0].split(None, 3)) == 4
+ return info and len(info[0]) == 1 and \
+ (len(info[0][0].split(None, 3)) == 4 or info[0][0] == "No updates pending
for installation")
def inventory_apt(info):
@@ -59,6 +62,10 @@ def check_apt(_no_item, params, info):
if not apt_valid_info(info):
return
+ if info[0][0] == "No updates pending for installation":
+ yield 0, "No updates pending for installation"
+ return
+
sec_regex = regex("^[^\\(]*\\(.*
(Debian-Security:|Ubuntu:[^/]*/[^-]*-security)")
updates = []
sec_updates = []