Skip to main content

Hello,

I’d like to know if collections can be used to perform the following request

  1. Connect on https://mxtoolbox.com/
  2. Write spf:google.com on the ‘Domain Name’ box
  3. Read the line ‘v=spf1 include:_spf.google.com ~all’
  4. At the end, the Centreon measurement will compare this result with the expected value

Thanks,

 

Hello

you don’t want to check from mxtoolbox as it’s a third party website and I’m not sure if they provide a way to get the result

what you want is a simple dns query to a dns server and parse the output, here is a perl script  that will do that for you, I had something like that lying around

 

#!/bin/perl
use Getopt::Long;
my $domain="";
my $testspf="";
my $printhelp;
$result = GetOptions ("domain=s" => \$domain,
"testspf=s" => \$testspf,
"help" => \$printhelp)
or usage();

my $dig = `which dig 2>/dev/null`;
if ($? != 0){
print "UNKNOWN - dig command not found, please install bind-utils ";
exit 3;
}

usage() if $printhelp;
if($domain eq "") { usage() };
if($testspf eq "") { usage() };

sub usage { print("Usage: $0 --domain=<DNS DOMAIN> --testspf=\"<spf string>\"\n"); exit 3;}


my $spf = "";

$spf = `dig -t txt ${domain} +short |grep spf1`;

$spf =~ s/\R//g;
$spf =~ s/"//g;

if ($spf eq ""){
print "UNKNOWN - unable to find spf record for domain $domain";
exit 3;
}


if($spf eq $testspf){
print "OK - SPF record is matching expected value ";
exit 0;
}

print "CRITICAL - SPF record does not match expected value\n";
print "Additional information : \n";
print " expected : $testspf -\n";
print " spf found: $spf -\n";
exit 2;

 

copy this script, save it on your poller in the plugin directory, it should be 

/usr/lib64/nagios/plugins/ (or /usr/lib/nagios/plugins/, there should be a file here called “check_icmp”)

 

call the file “check_spf.pl” and do a “chmod +x check_spf.pl”

this script has a pre-requisite, you need the “dig” command, usually provided by the package “bind-utils” 

once you have the dig command installed, you can check a domain spf with “dig -t txt google.com” and it will list you the txt record for that domain.

 

once it works the script usage is 

./check_spf.pl --domain=google.com --testspf='v=spf1 include:_spf.google.com ~all'

notice the quotes around the spf.

 

now you need to create a “command” in centreon, configuration menu->commands->check, add a new command

call it “Check-SPF” or whatever you want

and input that in the command line

$USER1$/check_spf.pl --domain=$_SERVICEDOMAIN$ --testspf='$_SERVICETESTSPF$'

 

once that is done, create a service template

call it how you want, check-spf for example, set the template to the generic active service and select the command you created, you will see the 2 MACRO appear automatically once the command is selected

 

you can stop here, and use this service template to create new services on an existing host if you already have host that could be linked to that service, but what host would you use to represent a domain … 

my solution is to use dummy host, this will allow you to have a host with no “check” on the host, and not needing an ip, or a server to attach the service

you can either create a single dummy host, with all the spf check you want, or have 1 host by service.

to do that, create a host template, again name it how you want, and use the dummy host parent template

and then add the service template in the relation tab

 

now you can simply create new host, give a name, add the check-spf host template and say yes to deploy the service associated, and for each service

 

all that is tweakable and you can adapt to your need

hope that helps


Many thanks Christophe, for your detailed and clear answer ! It’s exactly what I was looking for


Please find here the result, exactly as you described it.

 

Now I’m able to monitor SPF records.


Reply