2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
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.
28 # Inst dpkg [1.17.5ubuntu5.3] (1.17.5ubuntu5.4 Ubuntu:14.04/trusty-updates [amd64])
29 # Inst libtasn1-6-dev [3.4-3ubuntu0.1] (3.4-3ubuntu0.2 Ubuntu:14.04/trusty-updates [amd64]) []
30 # Inst libtasn1-6 [3.4-3ubuntu0.1] (3.4-3ubuntu0.2 Ubuntu:14.04/trusty-updates [amd64])
31 # Inst ntpdate [1:4.2.6.p5+dfsg-3ubuntu2.14.04.2] (1:4.2.6.p5+dfsg-3ubuntu2.14.04.3 Ubuntu:14.04/trusty-security [amd64])
32 # Inst udev [204-5ubuntu20.10] (204-5ubuntu20.11 Ubuntu:14.04/trusty-updates [amd64]) []
33 # Inst libudev1 [204-5ubuntu20.10] (204-5ubuntu20.11 Ubuntu:14.04/trusty-updates [amd64])
34 # Inst libpam-systemd [204-5ubuntu20.10] (204-5ubuntu20.11 Ubuntu:14.04/trusty-updates [amd64]) []
35 # Inst systemd-services [204-5ubuntu20.10] (204-5ubuntu20.11 Ubuntu:14.04/trusty-updates [amd64]) []
36 # Inst libsystemd-daemon0 [204-5ubuntu20.10] (204-5ubuntu20.11 Ubuntu:14.04/trusty-updates [amd64])
37 # Inst libsystemd-login0 [204-5ubuntu20.10] (204-5ubuntu20.11 Ubuntu:14.04/trusty-updates [amd64])
38 # Inst libpolkit-gobject-1-0 [0.105-4ubuntu2] (0.105-4ubuntu2.14.04.1 Ubuntu:14.04/trusty-updates [amd64])
39 # Inst libxext-dev [2:1.3.2-1] (2:1.3.2-1ubuntu0.0.14.04.1 Ubuntu:14.04/trusty-security [amd64]) []
41 factory_settings
["apt_default_levels"] = {
47 # Check that the apt section is in valid format of mk_apt plugin and not
48 # from the apt agent plugin which can be found on the Check_MK exchange.
49 def apt_valid_info(info
):
50 return info
and len(info
[0]) == 1 and \
51 (len(info
[0][0].split(None, 3)) == 4 or info
[0][0] == "No updates pending for installation")
54 def inventory_apt(info
):
55 if apt_valid_info(info
):
59 def check_apt(_no_item
, params
, info
):
60 if not apt_valid_info(info
):
63 if info
[0][0] == "No updates pending for installation":
64 yield 0, "No updates pending for installation"
67 sec_regex
= regex("^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)")
71 if not line
[0].startswith("Inst"):
73 _inst
, packet
, _version
, _hints
= line
[0].split(None, 3)
74 if sec_regex
.match(line
[0]):
75 sec_updates
.append(packet
)
77 updates
.append(packet
)
81 state
= params
["normal"]
82 yield state
, "%d normal updates" % len(updates
), [("normal_updates", len(updates
))]
86 state
= params
["security"]
87 text
= " (%s)" % ", ".join(sec_updates
)
91 yield state
, "%d security updates%s" % (len(sec_updates
), text
), [("security_updates",
96 "inventory_function": inventory_apt
,
97 "check_function": check_apt
,
98 "service_description": "APT Updates",
100 "has_perfdata": True,
101 "default_levels_variable": "apt_default_levels",