summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 287f5e2)
raw | patch | inline | side by side (parent: 287f5e2)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Thu, 26 Oct 2006 21:02:21 +0000 (21:02 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Thu, 26 Oct 2006 21:02:21 +0000 (21:02 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1528 f882894a-f735-0410-b71e-b25c423dba1c
plugins-scripts/Makefile.am | patch | blob | history | |
plugins-scripts/t/utils.t | [new file with mode: 0644] | patch | blob |
plugins-scripts/utils.pm.in | patch | blob | history |
index 39291c8063b190f89c3a3cf9158f8855800c2572..6656881db07710b3eb3cf311a7d207bbda583e70 100644 (file)
test:
perl -I $(top_builddir) -I $(top_srcdir) ../test.pl
+ perl -I $(top_builddir) -I $(top_srcdir) ../test.pl t/utils.t # utils.t is excluded from above, so manually ask to test
CLEANFILES=$(libexec_SCRIPTS)
diff --git a/plugins-scripts/t/utils.t b/plugins-scripts/t/utils.t
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/perl -w -I ..
+#
+# utils.pm tests
+#
+# $Id$
+#
+
+#use strict;
+use Test::More;
+use NPTest;
+
+use lib "..";
+use utils;
+
+my $hostname_checks = {
+ "www.altinity.com" => 1,
+ "www.888.com" => 1,
+ "888.com" => 1,
+ "host-hyphened.com" => 1,
+ "rubbish" => 1,
+ "-start.com" => 0,
+ "endsindot." => 0,
+ "lots.of.dots.dot.org" => 1,
+ "10.20.30.40" => 1,
+ "10.20.30.40.50" => 0,
+ "10.20.30" => 0,
+ };
+
+plan tests => scalar keys %$hostname_checks;
+
+foreach my $h (sort keys %$hostname_checks) {
+ is (utils::is_hostname($h), $hostname_checks->{$h}, "$h should return ".$hostname_checks->{$h});
+}
+
index d4dddae990d4aee1b3977aa952bbc715d32f56a8..e245835924cc32a3a8aa374bec3eaaed51d2809a 100644 (file)
# Utility drawer for Nagios plugins.
# $Id$
#
-# $Log$
-# Revision 1.9 2006/10/19 18:44:53 tonvoon
-# Allow hostnames beginning with digits (O'Shaughnessy Evans - 1567390)
-#
-# Revision 1.8 2006/06/07 14:23:12 seanius
-# removed stale references to PATH_TO_NTPFOO, as it's no longer used.
-#
-# Revision 1.7 2003/04/13 04:25:36 sghosh
-# update for check_mailq - qmail support
-#
-# Revision 1.6 2003/02/03 20:29:55 sghosh
-# change ntpdc to ntpq (Jonathan Rozes,Thomas Schimpke, bug-656237 )
-#
-# Revision 1.5 2002/10/30 05:07:29 sghosh
-# monitor mailq
-#
-# Revision 1.4 2002/05/27 02:01:09 sghosh
-# new var - smbclient
-#
-# Revision 1.3 2002/05/10 03:49:22 sghosh
-# added programs to autoconf
-#
-# Revision 1.2 2002/05/08 05:10:35 sghosh
-# is_hostname added, update CODES to POSIX
-#
-#
+# This will be deprecated soon. Please use Nagios::Plugin from CPAN
+# for new plugins
+
package utils;
require Exporter;
sub is_hostname {
my $host1 = shift;
- if ($host1 && $host1 =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)$/) {
+ 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]+)*)$/) {
return 1;
}else{
return 0;