Skip to main content

IPv6 Nagios plugin in TCL

Posted in
Table of Contents

Intro

Often IPv6 is used via dialup line and/or tunnel brookers. Sometimes the dialup fails, the tunnel is unavailable or not connected properly. With monitoring remote systems, it makes sense not only to check if the system is up and running, but also, in case of an error, to check if the connection from the monitoring system to the monitored system is valid.

To accomplish this, you can se a “parent” to the monitored system, and use a “gateway” as parent. The gateway is not checked directly, that means it is out of interest if the gateway is up and running (ping-able). Instead, the proper function of the gateway is checked. And this function is: “connect me to the internet”. In case this function is given, you can tell that a remote host which is not up has a problem, and not your internet/IPv6 connection.

This Nagios plugin enables an IPv6 general connection check, it shows if the host it is running on has a valid connection to the IPv6 network. Please note that the ping6 binary is required.

The Plugin

You can download the plugin from gitweb

#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" ${1+"$@"}
# check_internet.tcl --
#
###Abstract
# This file checks if an ipv6 connection is valid
#
# Author: Erik Beckers
 
### Package Definition
package require cmdline
 
# states from Nagios
set STATE_OK 0
set STATE_WARNING 1
set STATE_CRITICAL 2
set STATE_UNKNOWN 3
set STATE_DEPENDENT 4
 
# Replacement for puts: Output depends on set errorlevel
proc dputs {level args} {
    global debuglevel
        if { $debuglevel >= $level} {
            puts stderr $args
        }
}
 
#    #   ##   # #    #
##  ##  #  #  # ##   #
# ## # #    # # # #  #
#    # ###### # #  # #
#    # #    # # #   ##
#    # #    # # #    #
 
set options {
    {f.arg   ""   "value: Full path and name to servers file."}
    {d.arg   0    "debug level"}
}
 
array set params [::cmdline::getoptions argv $options]
 
# set optional
set debuglevel $params(d)
 
# Verify required parameters
set requiredParameters {f}
foreach parameter $requiredParameters {
    if {$params($parameter) == ""} {
        puts stderr "This script checks if the Internet connection is still"
        puts stderr "up by pinging specified hosts. For a command line test,"
        puts stderr "start with \"-d 1\""
        puts stderr "Missing required parameter: -$parameter"
        puts stderr [::cmdline::usage $options]
        exit 1
    }
}
 
# verify if the server file exists
if {[file exists $params(f)] && [file readable $params(f)]} {
    source $params(f)
} else {
    puts stderr "$params(f) does not exist or is not readable"
    exit 1
}
 
foreach target $servers {
    dputs 1 "Server: $target"
    set status [catch { exec ping6 -t 10 -c 3 $target } result]
    # ping answer gives status 0
    # host unknown and no route give status 1
    dputs 1 "status: $status"
    if {$status == 0} {
        dputs 1 "result: $result"
        puts "OK - Connection up: $target"
        exit $STATE_OK
    }
}
 
puts "CRITICAL - Connection up: $target"
exit $STATE_CRITICAL

Installation

Please adjust the paths below to fit your needs.

  • Download the plugin and copy it to /usr/lib/nagios/plugins/check_internet6.tcl
  • Make shure your “Nagios” user can excute the script
  • Create the file ”/usr/lib/nagios/plugins/internetservers6”, see example below
set servers "ipv6.google.com www.six.heise.de ipv6.he.net"
  • Add the command definition to Nagios:
# 'check_internet6' command definition
define command{
       command_name    check_internet6
       command_line    /usr/lib/nagios/plugins/check_internet6.tcl -f /usr/lib/nagios/plugins/internetservers6
}
  • Create the gateway host definition
# a host definition for the gateway of the default route
define host {
        host_name   gateway6
        alias       IPv6 Default Gateway
        address     <ENTER GWs IPV6 ADDRESS HERE>
        use         generic-host
        parents     localhost
        check_command check_internet6
        }

Now you can set “gateway6” as parent for your ipv6 capable servers. Remember to restart Nagios.