Add test for open ports

mr3.2.1
Michael Prokop 14 years ago
parent da263e7a7c
commit e7e41d0a4f

2
debian/copyright vendored

@ -3,7 +3,7 @@ Upstream-Name: ngcp-system-tests
Source: http://github.com/sipwise/system-tests/
Upstream-Contact: Michael Prokop <mprokop@sipwise.com>
Files: {ce,pro}/01_hostname-and-interfaces.t ce/01_running-processes.t ce/02_disk-free.t
Files: {ce,pro}/01_hostname-and-interfaces.t ce/01_running-processes.t ce/02_disk-free.t pro/03_open-ports.t
Copyright: Jozef Kutej <jozef@kutej.net>
License: Artistic or GPL-1+

@ -0,0 +1,158 @@
#!/usr/bin/perl
=head1 NAME
sites-ok.t - check web sites
=head SYNOPSIS
cat >> test-server.yaml << __YAML_END__
open-ports:
connect:
localhost:
22: ssh
bratislava.pm.org:
80: http
camel.cle.sk:
443: https
__YAML_END__
=cut
use strict;
use warnings;
use Test::More;
use Test::Differences;
use Test::Exception;
use Test::Net::Service;
use YAML::Syck 'LoadFile';
use FindBin '$Bin';
eval "use IO::Socket::INET";
plan 'skip_all' => "need IO::Socket::INET to run ports open tests" if $@;
my $config = LoadFile($Bin.'/test-server.yaml');
plan 'skip_all' => "no configuration sections for 'open-ports'"
if (not $config or not $config->{'open-ports'});
exit main();
sub main {
my $connect = $config->{'open-ports'}->{'connect'};
# count the tests and plan them
my $number_of_tests = 0;
foreach my $host (keys %$connect) {
foreach my $port (keys %{$connect->{$host}}) {
# port connection test
$number_of_tests ++;
# service check for all besides closed ports
$number_of_tests ++
if not (($connect->{$host}->{$port} || '') eq 'closed');
}
}
plan 'tests' => $number_of_tests;
# loop through ports that needs to be working
foreach my $host (keys %$connect) {
my $net_service = Test::Net::Service->new(
'host' => $host
);
foreach my $port (keys %{$connect->{$host}}) {
my $service = $connect->{$host}->{$port} || '';
my $proto = 'tcp';
my $socket = IO::Socket::INET->new(
PeerAddr => $host,
PeerPort => $port,
Proto => $proto,
);
# check for closed ports
if ($service eq 'closed') {
ok(
!$socket,
'connect to '
.$host
.' port '
.$port
.'/'
.$proto
.' filtered'
);
next;
}
ok(
$socket,
'connect to '
.$host
.' port '
.$port
.'/'
.$proto
);
# skip rest if we failed to connect
if (not defined $socket) {
SKIP: {
skip 'skipping service check if port open failed', 1;
}
next;
}
# skip rest if servis was not specified
if (not $service) {
SKIP: {
skip 'skipping service check no service defined', 1;
}
next;
}
# skip rest if there is no test_function for the service
if (not $net_service->can('test_'.$service)) {
SKIP: {
skip 'unknown service '.$service.'!!!', 1;
}
next;
}
# check the service
lives_ok(
sub {
$net_service->test(
'socket' => $socket,
'host' => $host,
'service' => $service
)
},
'check '
.$service
.' service default response with proto '
.$proto
.' port '
.$port
.' on host '
);
}
}
return 0;
}
__END__
=head1 NOTE
Port checking depends on L<IO::Socket::INET>.
=head1 AUTHOR
Jozef Kutej
=cut

@ -42,3 +42,49 @@ running-processes:
- /usr/sbin/sems
- /usr/sbin/snmpd
- /usr/sbin/sshd
open-ports:
connect:
localhost:
22: ssh
25: exim4
80: http
# 23: ntpd # TODO udp
# 161: snmpd TODO udp
443: https
# 694: heartbeat # TODO udp
1443: https
# 2222: mediaproxy # TODO udp
# 2223: mediaproxy # TODO udp
2443: https
2812: monit
3306: mysqld
# 4569: asterisk # TODO udp
# 5040: sems # TODO udp
5062: kamailio
# 5070: asterisk # TODO udp
# 5080: sems # TODO udp
6996: glusterfs
8000: kamailio
8090: sems
# 25826: collectd + kamailio # TODO udp
# 40297: collectd # TODO udp
# 45673: heartbeat # TODO udp
# 48296: collectd + kamailio # TODO udp
# 50474: heartbeat # TODO udp
192.168.255.251:
22: ssh
80: http
443: https
1443: https
3306: mysql
6379: redis-server
192.168.255.252:
22: ssh
80: http
443: https
1443: https
3306: mysql
6379: redis-server
deb.sipwise.com:
80: http

Loading…
Cancel
Save