summaryrefslogtreecommitdiffstats
path: root/plugins-scripts
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2006-10-26 21:02:21 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2006-10-26 21:02:21 (GMT)
commit6728e60669cfa3011e5ab5f3315feccd6205668d (patch)
tree74d9596f6d37acab3fc338d642766825eb6be69b /plugins-scripts
parent287f5e29c6e91a4a7afa59158430db3f25f2eb1c (diff)
downloadmonitoring-plugins-6728e60669cfa3011e5ab5f3315feccd6205668d.tar.gz
Fixed regression where hostnames with hyphens were rejected (1581402 - Holger Weiss)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1528 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-scripts')
-rw-r--r--plugins-scripts/Makefile.am1
-rw-r--r--plugins-scripts/t/utils.t34
-rw-r--r--plugins-scripts/utils.pm.in31
3 files changed, 39 insertions, 27 deletions
diff --git a/plugins-scripts/Makefile.am b/plugins-scripts/Makefile.am
index 39291c8..6656881 100644
--- a/plugins-scripts/Makefile.am
+++ b/plugins-scripts/Makefile.am
@@ -20,6 +20,7 @@ TESTS = @SCRIPT_TEST@
20 20
21test: 21test:
22 perl -I $(top_builddir) -I $(top_srcdir) ../test.pl 22 perl -I $(top_builddir) -I $(top_srcdir) ../test.pl
23 perl -I $(top_builddir) -I $(top_srcdir) ../test.pl t/utils.t # utils.t is excluded from above, so manually ask to test
23 24
24CLEANFILES=$(libexec_SCRIPTS) 25CLEANFILES=$(libexec_SCRIPTS)
25 26
diff --git a/plugins-scripts/t/utils.t b/plugins-scripts/t/utils.t
new file mode 100644
index 0000000..469988c
--- /dev/null
+++ b/plugins-scripts/t/utils.t
@@ -0,0 +1,34 @@
1#!/usr/bin/perl -w -I ..
2#
3# utils.pm tests
4#
5# $Id$
6#
7
8#use strict;
9use Test::More;
10use NPTest;
11
12use lib "..";
13use utils;
14
15my $hostname_checks = {
16 "www.altinity.com" => 1,
17 "www.888.com" => 1,
18 "888.com" => 1,
19 "host-hyphened.com" => 1,
20 "rubbish" => 1,
21 "-start.com" => 0,
22 "endsindot." => 0,
23 "lots.of.dots.dot.org" => 1,
24 "10.20.30.40" => 1,
25 "10.20.30.40.50" => 0,
26 "10.20.30" => 0,
27 };
28
29plan tests => scalar keys %$hostname_checks;
30
31foreach my $h (sort keys %$hostname_checks) {
32 is (utils::is_hostname($h), $hostname_checks->{$h}, "$h should return ".$hostname_checks->{$h});
33}
34
diff --git a/plugins-scripts/utils.pm.in b/plugins-scripts/utils.pm.in
index d4dddae..e245835 100644
--- a/plugins-scripts/utils.pm.in
+++ b/plugins-scripts/utils.pm.in
@@ -1,32 +1,9 @@
1# Utility drawer for Nagios plugins. 1# Utility drawer for Nagios plugins.
2# $Id$ 2# $Id$
3# 3#
4# $Log$ 4# This will be deprecated soon. Please use Nagios::Plugin from CPAN
5# Revision 1.9 2006/10/19 18:44:53 tonvoon 5# for new plugins
6# Allow hostnames beginning with digits (O'Shaughnessy Evans - 1567390) 6
7#
8# Revision 1.8 2006/06/07 14:23:12 seanius
9# removed stale references to PATH_TO_NTPFOO, as it's no longer used.
10#
11# Revision 1.7 2003/04/13 04:25:36 sghosh
12# update for check_mailq - qmail support
13#
14# Revision 1.6 2003/02/03 20:29:55 sghosh
15# change ntpdc to ntpq (Jonathan Rozes,Thomas Schimpke, bug-656237 )
16#
17# Revision 1.5 2002/10/30 05:07:29 sghosh
18# monitor mailq
19#
20# Revision 1.4 2002/05/27 02:01:09 sghosh
21# new var - smbclient
22#
23# Revision 1.3 2002/05/10 03:49:22 sghosh
24# added programs to autoconf
25#
26# Revision 1.2 2002/05/08 05:10:35 sghosh
27# is_hostname added, update CODES to POSIX
28#
29#
30package utils; 7package utils;
31 8
32require Exporter; 9require Exporter;
@@ -76,7 +53,7 @@ sub usage {
76 53
77sub is_hostname { 54sub is_hostname {
78 my $host1 = shift; 55 my $host1 = shift;
79 if ($host1 && $host1 =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)$/) { 56 if ($host1 && $host1 =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z0-9][-a-zA-Z0-9]+(\.[a-zA-Z0-9][-a-zA-Z0-9]+)*)$/) {
80 return 1; 57 return 1;
81 }else{ 58 }else{
82 return 0; 59 return 0;