diff --git a/nagios/files/check_tftp b/nagios/files/check_tftp new file mode 100755 index 0000000..de7cb56 --- /dev/null +++ b/nagios/files/check_tftp @@ -0,0 +1,31 @@ +#!/usr/bin/perl -w + +use strict; +use Getopt::Long qw(:config no_ignore_case); + +sub usage() { + print "Usage: check_tftp -H -f \n"; +} + +my ($host, $file); +my $result = GetOptions( + "H|host=s" => \$host, + "f|file=s" => \$file, + ); + +if (!$host || !$file) { + usage(); + exit(3); +} + +$result = `echo -e 'timeout 1\nverbose\nget $file /dev/null' | tftp $host`; +my @splitted = split(/\n/, $result); +$result = $splitted[5]; + +if ($result =~ /Received \d+ bytes in [\d\.]+ seconds/) { + print "TFTP OK: $result"; + exit(0); +} else { + print "TFTP CRITICAL: $result"; + exit(2); +} diff --git a/nagios/files/commands.cfg b/nagios/files/commands.cfg index 4093126..d03f167 100644 --- a/nagios/files/commands.cfg +++ b/nagios/files/commands.cfg @@ -225,6 +225,13 @@ define command{ } +# 'check_tftp' command definition +define command{ + command_name check_tftp + command_line $USER1$/check_tftp -H $HOSTADDRESS$ -f $ARG1$ + } + + # 'check_tcp' command definition define command{ command_name check_tcp diff --git a/nagios/manifests/init.pp b/nagios/manifests/init.pp index bc9c95a..147fbe3 100644 --- a/nagios/manifests/init.pp +++ b/nagios/manifests/init.pp @@ -294,6 +294,15 @@ class nagios::server::manual inherits nagios::common { require => Package["nagios"], before => Service["nagios"], } + file { "${nagios::common::libdir}/check_tftp": + ensure => present, + mode => "0755", + owner => "root", + group => "root", + source => "puppet:///modules/nagios/check_tftp", + require => Package["nagios"], + before => Service["nagios"], + } } diff --git a/nagios/manifests/target.pp b/nagios/manifests/target.pp index 03a582a..9db0de0 100644 --- a/nagios/manifests/target.pp +++ b/nagios/manifests/target.pp @@ -313,6 +313,23 @@ class nagios::target::submission inherits nagios::target { } +# Configure tftp service target. +# +# === Parameters +# +# $file: +# Filename to fetch from TFTP server +# +class nagios::target::tftp($file) inherits nagios::target { + + @@nagios::service { "${::homename}_tftp": + command => "check_tftp!${file}", + description => "TFTP", + } + +} + + # Configure tcp connect service target. # # === Parameters