summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
authorSven Nierlein <sven@nierlein.org>2013-01-23 19:43:26 (GMT)
committerSven Nierlein <sven@nierlein.org>2013-01-23 19:43:26 (GMT)
commit307da669ee8774aee1ac0c21e230f22a59ccb063 (patch)
tree377d782181ac537314e6c38fc3b298f5db68e7c6 /plugins/t
parent596af9df576b0ecf7a7dcc9a2c19ae771f23bf1d (diff)
parent13e85a0f4f9d1ede624e1135f1646c64ecc052a4 (diff)
downloadmonitoring-plugins-307da669ee8774aee1ac0c21e230f22a59ccb063.tar.gz
Merge pull request #20 from abradley/aptcritical
Fixes for check_apt handling of -i/-e/-c regexps and SECURITY_RE, plus tests
Diffstat (limited to 'plugins/t')
-rw-r--r--plugins/t/check_apt.t90
-rw-r--r--plugins/t/check_apt_input/debian14
-rw-r--r--plugins/t/check_apt_input/debian237
-rw-r--r--plugins/t/check_apt_input/debian342
-rw-r--r--plugins/t/check_apt_input/ubuntu114
-rw-r--r--plugins/t/check_apt_input/ubuntu254
6 files changed, 241 insertions, 0 deletions
diff --git a/plugins/t/check_apt.t b/plugins/t/check_apt.t
new file mode 100644
index 0000000..7123097
--- /dev/null
+++ b/plugins/t/check_apt.t
@@ -0,0 +1,90 @@
1#!/usr/bin/perl -w -I ..
2#
3# Test check_apt using input files.
4# Contributed by Alex Bradley, October 2012
5#
6
7use strict;
8use Test::More;
9use NPTest;
10
11sub make_result_regexp {
12 my ($warning, $critical) = @_;
13 my $status;
14 if ($warning == 0 && $critical == 0) {
15 $status = "OK";
16 } elsif ($critical == 0) {
17 $status = "WARNING";
18 } else {
19 $status = "CRITICAL";
20 }
21 return sprintf('/^APT %s: %d packages available for upgrade \(%d critical updates\).\s*$/',
22 $status, $warning, $critical);
23}
24
25if (-x "./check_apt") {
26 plan tests => 28;
27} else {
28 plan skip_all => "No check_apt compiled";
29}
30
31my $result;
32
33my $testfile_command = "./check_apt %s --input-file=t/check_apt_input/%s";
34
35$result = NPTest->testCmd( sprintf($testfile_command, "", "debian1") );
36is( $result->return_code, 0, "No upgrades" );
37like( $result->output, make_result_regexp(0, 0), "Output correct" );
38
39$result = NPTest->testCmd( sprintf($testfile_command, "", "debian2") );
40is( $result->return_code, 1, "Debian apt output, warning" );
41like( $result->output, make_result_regexp(13, 0), "Output correct" );
42
43$result = NPTest->testCmd( sprintf($testfile_command, "", "debian3") );
44is( $result->return_code, 2, "Debian apt output, some critical" );
45like( $result->output, make_result_regexp(19, 4), "Output correct" );
46
47$result = NPTest->testCmd( sprintf($testfile_command, "-c '^[^\\(]*\\(.* (Debian-Security:|Ubuntu:[^/]*/[^-]*-security)'", "debian3") );
48is( $result->return_code, 2, "Debian apt output - should have same result when default security regexp specified via -c" );
49like( $result->output, make_result_regexp(19, 4), "Output correct" );
50
51$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6", "debian3") );
52is( $result->return_code, 1, "Debian apt output, filter for libc6" );
53like( $result->output, make_result_regexp(3, 0), "Output correct" );
54
55$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6 -i xen", "debian3") );
56is( $result->return_code, 2, "Debian apt output, filter for libc6 and xen" );
57like( $result->output, make_result_regexp(9, 4), "Output correct" );
58
59$result = NPTest->testCmd( sprintf($testfile_command, "-i libc6 -i xen -i linux", "debian3") );
60is( $result->return_code, 2, "Debian apt output, filter for libc6, xen, linux" );
61like( $result->output, make_result_regexp(12, 4), "Output correct" );
62
63$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6", "debian3") );
64is( $result->return_code, 2, "Debian apt output, filter out libc6" );
65like( $result->output, make_result_regexp(16, 4), "Output correct" );
66
67$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -e xen", "debian3") );
68is( $result->return_code, 1, "Debian apt output, filter out libc6 and xen" );
69like( $result->output, make_result_regexp(10, 0), "Output correct" );
70
71$result = NPTest->testCmd( sprintf($testfile_command, "-e libc6 -e xen -e linux", "debian3") );
72is( $result->return_code, 1, "Debian apt output, filter out libc6, xen, linux" );
73like( $result->output, make_result_regexp(7, 0), "Output correct" );
74
75$result = NPTest->testCmd( sprintf($testfile_command, "-c Debian-Security -c linux", "debian3") );
76is( $result->return_code, 2, "Debian apt output, critical on Debian-Security or linux" );
77like( $result->output, make_result_regexp(19, 9), "Output correct" );
78
79$result = NPTest->testCmd( sprintf($testfile_command, "-i lib -i linux -e gc1c -c linux-image", "debian3") );
80is( $result->return_code, 2, "Debian apt output, include lib and linux, exclude gc1c, critical on linux-image" );
81like( $result->output, make_result_regexp(10, 2), "Output correct" );
82
83$result = NPTest->testCmd( sprintf($testfile_command, "", "ubuntu1") );
84is( $result->return_code, 1, "Ubuntu apt output, warning" );
85like( $result->output, make_result_regexp(5, 0), "Output correct" );
86
87$result = NPTest->testCmd( sprintf($testfile_command, "", "ubuntu2") );
88is( $result->return_code, 2, "Ubuntu apt output, some critical" );
89like( $result->output, make_result_regexp(25, 14), "Output correct" );
90
diff --git a/plugins/t/check_apt_input/debian1 b/plugins/t/check_apt_input/debian1
new file mode 100644
index 0000000..317e7ea
--- /dev/null
+++ b/plugins/t/check_apt_input/debian1
@@ -0,0 +1,4 @@
1NOTE: This is only a simulation!
2 apt-get needs root privileges for real execution.
3 Keep also in mind that locking is deactivated,
4 so don't depend on the relevance to the real current situation!
diff --git a/plugins/t/check_apt_input/debian2 b/plugins/t/check_apt_input/debian2
new file mode 100644
index 0000000..effd155
--- /dev/null
+++ b/plugins/t/check_apt_input/debian2
@@ -0,0 +1,37 @@
1NOTE: This is only a simulation!
2 apt-get needs root privileges for real execution.
3 Keep also in mind that locking is deactivated,
4 so don't depend on the relevance to the real current situation!
5Reading package lists... Done
6Building dependency tree
7Reading state information... Done
8The following packages will be upgraded:
9 base-files debian-archive-keyring dpkg firmware-linux-free libc-bin libc-dev-bin libc6 libc6-dev linux-base
10 linux-image-2.6.32-5-xen-amd64 linux-libc-dev locales lockfile-progs
1113 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
12Inst base-files [6.0squeeze5] (6.0squeeze6 Debian:6.0.6/stable [amd64])
13Conf base-files (6.0squeeze6 Debian:6.0.6/stable [amd64])
14Inst dpkg [1.15.8.12] (1.15.8.13 Debian:6.0.6/stable [amd64])
15Conf dpkg (1.15.8.13 Debian:6.0.6/stable [amd64])
16Inst linux-base [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all])
17Inst linux-image-2.6.32-5-xen-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64])
18Inst debian-archive-keyring [2010.08.28] (2010.08.28+squeeze1 Debian:6.0.6/stable [all])
19Conf debian-archive-keyring (2010.08.28+squeeze1 Debian:6.0.6/stable [all])
20Inst libc6-dev [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) []
21Inst libc-dev-bin [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) []
22Inst linux-libc-dev [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64]) []
23Inst libc-bin [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ]
24Conf libc-bin (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ]
25Inst libc6 [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64])
26Conf libc6 (2.11.3-4 Debian:6.0.6/stable [amd64])
27Inst locales [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [all])
28Inst firmware-linux-free [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all])
29Inst lockfile-progs [0.1.15] (0.1.15+squeeze1 Debian:6.0.6/stable [amd64])
30Conf linux-base (2.6.32-46 Debian:6.0.6/stable [all])
31Conf linux-image-2.6.32-5-xen-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64])
32Conf libc-dev-bin (2.11.3-4 Debian:6.0.6/stable [amd64])
33Conf linux-libc-dev (2.6.32-46 Debian:6.0.6/stable [amd64])
34Conf libc6-dev (2.11.3-4 Debian:6.0.6/stable [amd64])
35Conf locales (2.11.3-4 Debian:6.0.6/stable [all])
36Conf firmware-linux-free (2.6.32-46 Debian:6.0.6/stable [all])
37Conf lockfile-progs (0.1.15+squeeze1 Debian:6.0.6/stable [amd64])
diff --git a/plugins/t/check_apt_input/debian3 b/plugins/t/check_apt_input/debian3
new file mode 100644
index 0000000..719dce9
--- /dev/null
+++ b/plugins/t/check_apt_input/debian3
@@ -0,0 +1,42 @@
1NOTE: This is only a simulation!
2 apt-get needs root privileges for real execution.
3 Keep also in mind that locking is deactivated,
4 so don't depend on the relevance to the real current situation!
5Inst base-files [6.0squeeze5] (6.0squeeze6 Debian:6.0.6/stable [amd64])
6Conf base-files (6.0squeeze6 Debian:6.0.6/stable [amd64])
7Inst dpkg [1.15.8.12] (1.15.8.13 Debian:6.0.6/stable [amd64])
8Conf dpkg (1.15.8.13 Debian:6.0.6/stable [amd64])
9Inst linux-base [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all])
10Inst linux-image-2.6.32-5-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64])
11Inst xen-hypervisor-4.0-amd64 [4.0.1-5.3] (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
12Inst xen-linux-system-2.6.32-5-xen-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64]) []
13Inst linux-image-2.6.32-5-xen-amd64 [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [amd64])
14Inst debian-archive-keyring [2010.08.28] (2010.08.28+squeeze1 Debian:6.0.6/stable [all])
15Conf debian-archive-keyring (2010.08.28+squeeze1 Debian:6.0.6/stable [all])
16Inst libc6-i386 [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) []
17Inst libc-bin [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ]
18Conf libc-bin (2.11.3-4 Debian:6.0.6/stable [amd64]) [libc6:amd64 ]
19Inst libc6 [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [amd64])
20Conf libc6 (2.11.3-4 Debian:6.0.6/stable [amd64])
21Inst libgc1c2 [1:6.8-1.2] (1:6.8-2 Debian:6.0.6/stable [amd64])
22Inst locales [2.11.3-3] (2.11.3-4 Debian:6.0.6/stable [all])
23Inst firmware-linux-free [2.6.32-45] (2.6.32-46 Debian:6.0.6/stable [all])
24Inst libxenstore3.0 [4.0.1-5.3] (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
25Inst lockfile-progs [0.1.15] (0.1.15+squeeze1 Debian:6.0.6/stable [amd64])
26Inst xen-utils-4.0 [4.0.1-5.3] (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
27Inst xenstore-utils [4.0.1-5.3] (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
28Inst libconfig-inifiles-perl [2.52-1] (2.52-1+squeeze1 Debian:6.0.6/stable [all])
29Conf linux-base (2.6.32-46 Debian:6.0.6/stable [all])
30Conf linux-image-2.6.32-5-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64])
31Conf xen-hypervisor-4.0-amd64 (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
32Conf linux-image-2.6.32-5-xen-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64])
33Conf xen-linux-system-2.6.32-5-xen-amd64 (2.6.32-46 Debian:6.0.6/stable [amd64])
34Conf libc6-i386 (2.11.3-4 Debian:6.0.6/stable [amd64])
35Conf libgc1c2 (1:6.8-2 Debian:6.0.6/stable [amd64])
36Conf locales (2.11.3-4 Debian:6.0.6/stable [all])
37Conf firmware-linux-free (2.6.32-46 Debian:6.0.6/stable [all])
38Conf libxenstore3.0 (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
39Conf lockfile-progs (0.1.15+squeeze1 Debian:6.0.6/stable [amd64])
40Conf xen-utils-4.0 (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
41Conf xenstore-utils (4.0.1-5.4 Debian:6.0.6/stable, Debian-Security:6.0/stable [amd64])
42Conf libconfig-inifiles-perl (2.52-1+squeeze1 Debian:6.0.6/stable [all])
diff --git a/plugins/t/check_apt_input/ubuntu1 b/plugins/t/check_apt_input/ubuntu1
new file mode 100644
index 0000000..2f61c30
--- /dev/null
+++ b/plugins/t/check_apt_input/ubuntu1
@@ -0,0 +1,14 @@
1NOTE: This is only a simulation!
2 apt-get needs root privileges for real execution.
3 Also keep in mind that locking is deactivated,
4 so don't depend on the relevance to the real current situation!
5Inst grub-pc [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) []
6Inst grub-pc-bin [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) []
7Inst grub2-common [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) []
8Inst grub-efi-amd64-bin [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64]) []
9Inst grub-common [1.99-21ubuntu3.1] (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
10Conf grub-common (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
11Conf grub2-common (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
12Conf grub-pc-bin (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
13Conf grub-pc (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
14Conf grub-efi-amd64-bin (1.99-21ubuntu3.4 Ubuntu:12.04/precise-updates [amd64])
diff --git a/plugins/t/check_apt_input/ubuntu2 b/plugins/t/check_apt_input/ubuntu2
new file mode 100644
index 0000000..29a14a0
--- /dev/null
+++ b/plugins/t/check_apt_input/ubuntu2
@@ -0,0 +1,54 @@
1NOTE: This is only a simulation!
2 apt-get needs root privileges for real execution.
3 Also keep in mind that locking is deactivated,
4 so don't depend on the relevance to the real current situation!
5Inst libc6-dev [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) []
6Inst libc-dev-bin [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) []
7Inst linux-libc-dev [3.2.0-29.46] (3.2.0-31.50 Ubuntu:12.04/precise-security [amd64]) []
8Inst tzdata [2012e-0ubuntu0.12.04] (2012e-0ubuntu0.12.04.1 Ubuntu:12.04/precise-security [all]) []
9Conf tzdata (2012e-0ubuntu0.12.04.1 Ubuntu:12.04/precise-security [all]) []
10Inst libc-bin [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) [libc6:amd64 ]
11Conf libc-bin (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64]) [libc6:amd64 ]
12Inst libc6 [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
13Conf libc6 (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
14Inst libapt-pkg4.12 [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
15Conf libapt-pkg4.12 (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
16Inst ubuntu-keyring [2011.11.21] (2011.11.21.1 Ubuntu:12.04/precise-updates [all])
17Conf ubuntu-keyring (2011.11.21.1 Ubuntu:12.04/precise-updates [all])
18Inst gpgv [1.4.11-3ubuntu2] (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64])
19Conf gpgv (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64])
20Inst gnupg [1.4.11-3ubuntu2] (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64])
21Conf gnupg (1.4.11-3ubuntu2.1 Ubuntu:12.04/precise-security [amd64])
22Inst apt [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
23Conf apt (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
24Inst libssl1.0.0 [1.0.1-4ubuntu5.3] (1.0.1-4ubuntu5.5 Ubuntu:12.04/precise-updates [amd64])
25Conf libssl1.0.0 (1.0.1-4ubuntu5.5 Ubuntu:12.04/precise-updates [amd64])
26Inst libapt-inst1.4 [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
27Inst resolvconf [1.63ubuntu15] (1.63ubuntu16 Ubuntu:12.04/precise-updates [all])
28Inst libdbus-1-3 [1.4.18-1ubuntu1] (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64])
29Inst libxml2 [2.7.8.dfsg-5.1ubuntu4.1] (2.7.8.dfsg-5.1ubuntu4.2 Ubuntu:12.04/precise-security [amd64])
30Inst multiarch-support [2.15-0ubuntu10] (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
31Conf multiarch-support (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
32Inst apt-utils [0.8.16~exp12ubuntu10.2] (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
33Inst isc-dhcp-client [4.1.ESV-R4-0ubuntu5.2] (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64]) []
34Inst isc-dhcp-common [4.1.ESV-R4-0ubuntu5.2] (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64])
35Inst dbus [1.4.18-1ubuntu1] (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64])
36Inst linux-firmware [1.79] (1.79.1 Ubuntu:12.04/precise-updates [all])
37Inst xserver-common [2:1.11.4-0ubuntu10.7] (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [all])
38Inst xserver-xorg-core [2:1.11.4-0ubuntu10.7] (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [amd64])
39Inst xserver-xorg-input-synaptics [1.6.2-1ubuntu1~precise1] (1.6.2-1ubuntu1~precise2 Ubuntu:12.04/precise-updates [amd64])
40Conf libc-dev-bin (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
41Conf linux-libc-dev (3.2.0-31.50 Ubuntu:12.04/precise-security [amd64])
42Conf libc6-dev (2.15-0ubuntu10.2 Ubuntu:12.04/precise-security [amd64])
43Conf libapt-inst1.4 (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
44Conf resolvconf (1.63ubuntu16 Ubuntu:12.04/precise-updates [all])
45Conf libdbus-1-3 (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64])
46Conf libxml2 (2.7.8.dfsg-5.1ubuntu4.2 Ubuntu:12.04/precise-security [amd64])
47Conf apt-utils (0.8.16~exp12ubuntu10.3 Ubuntu:12.04/precise-updates [amd64])
48Conf isc-dhcp-common (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64])
49Conf isc-dhcp-client (4.1.ESV-R4-0ubuntu5.5 Ubuntu:12.04/precise-security [amd64])
50Conf dbus (1.4.18-1ubuntu1.1 Ubuntu:12.04/precise-security [amd64])
51Conf linux-firmware (1.79.1 Ubuntu:12.04/precise-updates [all])
52Conf xserver-common (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [all])
53Conf xserver-xorg-core (2:1.11.4-0ubuntu10.8 Ubuntu:12.04/precise-updates [amd64])
54Conf xserver-xorg-input-synaptics (1.6.2-1ubuntu1~precise2 Ubuntu:12.04/precise-updates [amd64])