# HG changeset patch # User arnold # Date 1341311018 -7200 # Node ID e9180d90ed71dfa42d033aed302dc30f7a413de7 import to mercuiral diff -r 000000000000 -r e9180d90ed71 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Tue Jul 03 12:23:38 2012 +0200 @@ -0,0 +1,8 @@ +syntax: glob +*.swp +debian/files +check_scan + +syntax: regexp +(build|configure)-stamp$ +debian/nagios-plugin-scan[./] diff -r 000000000000 -r e9180d90ed71 .perltitdy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.perltitdy Tue Jul 03 12:23:38 2012 +0200 @@ -0,0 +1,2 @@ +--paren-tightness=2 +--square-bracket-tightness=2 diff -r 000000000000 -r e9180d90ed71 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Tue Jul 03 12:23:38 2012 +0200 @@ -0,0 +1,22 @@ +SCRIPTS = check_scan +CLEANFILES = ${SCRIPTS} +DESTDIR = +prefix = /usr + +plugindir = ${prefix}/lib/nagios/plugins/ius + +.PHONY: all clean install + +all: ${SCRIPTS} + +clean: + -rm -f ${CLEANFILES} + +install: all + install -d -m 0755 ${DESTDIR}/${plugindir} + install -m 0755 $(SCRIPTS) ${DESTDIR}/${plugindir}/ + +%: %.pl + @perl -c $< + @cp -f $< $@ + @chmod +x $@ diff -r 000000000000 -r e9180d90ed71 check_scan.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/check_scan.pl Tue Jul 03 12:23:38 2012 +0200 @@ -0,0 +1,182 @@ +#!/usr/bin/perl -w + +# Copyright (C) 2011 Christian Arnold +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Christian Arnold + +use 5.010; +use strict; +use File::Basename; +use Getopt::Long; +use Pod::Usage; + +delete @ENV{ grep /^LC_/ => keys %ENV }; +$ENV{LANG} = "C"; +$ENV{LC_ALL} = "C"; + +sub version($$); +sub scan($$$); +sub report(@); + +my %ERRORS = ( + OK => 0, + WARNING => 1, + CRITICAL => 2, + UNKNOWN => 3, + DEPENDENT => 4 +); + +my $ME = basename $0; +my $NAME = "SCAN"; +my $VERSION = "0.1"; + +my %opt = ( + host => "localhost", + options => "-sT -sU -r -p1-65535", + exceptions => "22/tcp" +); + +MAIN: { + Getopt::Long::Configure('bundling'); + GetOptions( + "o|options=s" => \$opt{options}, + "H|host=s" => \$opt{host}, + "e|exceptions=s" => \$opt{exceptions}, + "h|help" => sub { pod2usage( -verbose => 1, -exitval => $ERRORS{OK} ) }, + "m|man" => sub { pod2usage( -verbose => 2, -exitval => $ERRORS{OK} ) }, + "V|version" => sub { version( $ME, $VERSION ); exit $ERRORS{OK}; } + ) or pod2usage( -verbose => 1, -exitval => $ERRORS{CRITICAL} ); + + my @openports = scan( $opt{host}, $opt{options}, $opt{exceptions} ); + report(@openports); +} + +sub version($$) { + my ( $progname, $version ) = @_; + + say <<_VERSION; +$progname version $version +Copyright (C) 2012 by Christian Arnold and Schlittermann internet & unix support. + +$ME comes with ABSOLUTELY NO WARRANTY. This is free software, +and you are welcome to redistribute it under certain conditions. +See the GNU General Public Licence for details. +_VERSION +} + +sub scan($$$) { + my ( $host, $options, $exceptions ) = @_; + my @scan = grep { /^\d+\// } `nmap $options $host`; + my @openports; + my @exceptions; + + if ($exceptions) { + @exceptions = split( /,/, $exceptions ); + } + + PORTS: foreach my $port (@scan) { + foreach my $exceptions (@exceptions) { + next PORTS if ( $port =~ /^$exceptions/ ); + } + chomp($port); + $port =~ s/\s+/ /g; + push @openports, $port; + } + + return @openports; +} + +sub report(@) { + my @openports = @_; + + if (@openports) { + say "$NAME WARNING: " . join( "; ", @openports ); + exit $ERRORS{WARNING}; + } + + if ( $opt{exceptions} ) { + say "$NAME OK: no open ports (exceptions: $opt{exceptions})"; + } + else { + say "$NAME OK: no open ports"; + } + exit $ERRORS{OK}; +} + +__END__ + +=head1 NAME + +check_scan - nagios plugin to run port scan + +=head1 SYNOPSIS + +check_scan [B<-H>|B<--host>] + +check_scan [B<-o>|B<--options>] + +check_scan [B<-e>|B<--exceptions>] + +=head1 OPTIONS + +=over + +=item B<-H>|B<--host> + +Host or ip to scan. (default: localhost) + +=item B<-o>|B<--options> + +Nmap options for scan, must be specified in quotes. (default: '-sT -sU -r -p1-65535') + +=item B<-e>|B<--exceptions> + +No warning is generated if any of these ports open. Multiple ports can +be specified separated by commas (22/tcp,25/tcp,53/udp,...). (default: 22/tcp) + +=item B<-h>|B<--help> + +Print detailed help screen. + +=item B<-m>|B<--man> + +Print manual page. + +=item B<-V>|B<--version> + +Print version information. + +=back + +=head1 DESCRIPTION + +This nagios plugin scans hosts with nmap. + +=head1 VERSION + +This man page is current for version 0.1 of B. + +=head1 AUTHOR + +Written by Christian Arnold L + +=head1 COPYRIGHT + +Copyright (C) 2012 by Christian Arnold and Schlittermann internet & unix support. +This is free software, and you are welcome to redistribute it under certain conditions. +See the GNU General Public Licence for details. + +=cut diff -r 000000000000 -r e9180d90ed71 debian/changelog --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/changelog Tue Jul 03 12:23:38 2012 +0200 @@ -0,0 +1,5 @@ +nagios-plugin-scan (0.1) stable; urgency=low + + * Initial Release. + + -- Christian Arnold Tue, 03 Jul 2012 11:33:56 +0200 diff -r 000000000000 -r e9180d90ed71 debian/compat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/compat Tue Jul 03 12:23:38 2012 +0200 @@ -0,0 +1,1 @@ +7 diff -r 000000000000 -r e9180d90ed71 debian/control --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/control Tue Jul 03 12:23:38 2012 +0200 @@ -0,0 +1,14 @@ +Source: nagios-plugin-scan +Section: net +Priority: extra +Maintainer: Christian Arnold +Build-Depends: debhelper (>= 7.0.50~) +Standards-Version: 3.8.4 +Homepage: https://keller.schlittermann.de/hg/ius/nagios/nagios-plugin-scan/ + +Package: nagios-plugin-scan +Architecture: all +Depends: nmap +Suggests: perl-doc +Description: nagios plugin to run port scan + This nagios plugin scans hosts with nmap. diff -r 000000000000 -r e9180d90ed71 debian/copyright --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/copyright Tue Jul 03 12:23:38 2012 +0200 @@ -0,0 +1,39 @@ +This work was packaged for Debian by: + + Christian Arnold on Tue, 03 Jul 2012 11:33:56 +0200 + +It was downloaded from: + + https://keller.schlittermann.de/hg/ius/nagios/nagios-plugin-scan/ + +Upstream Author(s): + + Christian Arnold + +Copyright: + + Copyright (C) 2011 Schlittermann internet & unix support + +License: + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This package is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +On Debian systems, the complete text of the GNU General +Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". + +The Debian packaging is: + + Copyright (C) 2012 Christian Arnold + +and is licensed under the GPL version 3, see above. diff -r 000000000000 -r e9180d90ed71 debian/rules --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/rules Tue Jul 03 12:23:38 2012 +0200 @@ -0,0 +1,13 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +%: + dh $@ diff -r 000000000000 -r e9180d90ed71 debian/source/format --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debian/source/format Tue Jul 03 12:23:38 2012 +0200 @@ -0,0 +1,1 @@ +3.0 (native)