From 44762d64436c633a2c7d14bcb9867a5b9417ed48 Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Tue, 23 Feb 2021 22:37:16 +0100 Subject: [PATCH] Added support for IPv6 checks --- check_nmap.sh | 6 +++++- command_nmap.conf | 2 +- service_nmap.conf | 22 ++++++++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/check_nmap.sh b/check_nmap.sh index cc9df12..b4e1fff 100755 --- a/check_nmap.sh +++ b/check_nmap.sh @@ -9,12 +9,15 @@ DEBUG=false PORT_RANGE="1-65535" NMAP_ARGS="" KNOWN_PORTS=() +IPv="" while [[ $# -gt 0 ]]; do case $1 in -h|--host) HOST="$2"; shift;; -p|--portrange) PORT_RANGE="$2"; shift;; -k|--known) KNOWN_PORTS+=($2); shift;; -d|--debug) DEBUG=true;; + -4|--ipv4) IPv="";; + -6|--ipv6) IPv="-6";; -i|--input) INPUT="$2" if [ ! -f "$INPUT" ]; then @@ -28,6 +31,7 @@ while [[ $# -gt 0 ]]; do echo "--host HOSTNAME/IP: Host that shall be scanned by nmap" echo "--portrange RANGE: Ports that shall be scanned (nmap format)" echo "--known PORTNUMBER: Port number that is expected to be open" + echo "--ipv6: Use IPv6 for the scan (IPv4 if not specified)" exit 0 ;; *) @@ -74,7 +78,7 @@ function runNmap { done < $INPUT else local $cmd - cmd="nmap $portrange $NMAP_ARGS -- $HOST" + cmd="nmap $portrange $IPv $NMAP_ARGS -- $HOST" log "$cmd" while read -r line; do parseLine "$line" diff --git a/command_nmap.conf b/command_nmap.conf index 82d006c..6ad584d 100644 --- a/command_nmap.conf +++ b/command_nmap.conf @@ -2,7 +2,7 @@ object CheckCommand "nmap" { import "ipv4-or-ipv6" command = [ "/home/nagios/check_nmap.sh/check_nmap.sh" ] - timeout = 10m + timeout = 12h arguments = { "--host" = { diff --git a/service_nmap.conf b/service_nmap.conf index 47fbca0..afe2dd5 100644 --- a/service_nmap.conf +++ b/service_nmap.conf @@ -1,13 +1,31 @@ -apply Service "nmap" { +apply Service "nmap4" { import "generic-service" check_command = "nmap" check_interval = 24h retry_interval = 2h + vars.notification_interval = 1d + vars.nmap_ipv4 = true for (k => v in host.vars.nmap) { vars["nmap_" + k] = v } - assign where host.vars.nmap != null + assign where host.vars.nmap != null && (host.vars.nmap.ipv6_only == null || host.vars.nmap.ipv6_only == false) +} + +apply Service "nmap6" { + import "generic-service" + + check_command = "nmap" + check_interval = 24h + retry_interval = 2h + vars.notification_interval = 1d + vars.nmap_ipv6 = true + + for (k => v in host.vars.nmap) { + vars["nmap_" + k] = v + } + + assign where host.vars.nmap != null && (host.vars.nmap.ipv4_only == null || host.vars.nmap.ipv4_only == false) }