Last active
May 6, 2016 13:07
-
-
Save danmilleruk/6216055 to your computer and use it in GitHub Desktop.
senderbase.org nagios plugin via PHP CLI. ./senderbase <ipaddress>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
# Senderbase Monitoring Plugin for Nagios | |
# Dan Miller <[email protected]> | |
error_reporting(E_ERROR | E_PARSE); | |
# Function to swap the octets of an IP... | |
# ..address around in to ARPA formatting. | |
function ipToArpa($address) { | |
$raw = explode(".", $address); | |
return "{$raw[3]}.{$raw[2]}.{$raw[1]}.{$raw[0]}"; | |
} | |
$ip = $argv[1]; # IP address argument | |
$ar = ipToArpa($ip); # Convert the IP to ARPA formatting | |
$server = "rf.senderbase.org"; # What we append to the end of our query | |
# Let's check whether the IP address is valid. | |
$check = filter_var($ip, FILTER_VALIDATE_IP); | |
if(!$check) { | |
die("[ERROR] No IP address given\n"); | |
} | |
$result = dns_get_record("{$ar}.{$server}", DNS_TXT); # Init query. | |
$reputation = $result[0]['entries'][0]; # Reputation score | |
# If the array returns nothing, just die. | |
if($reputation == "") { | |
echo "[ERROR] No results given\n"; | |
exit(0); # Exit with an OK for now, as not to clog up nagios. | |
} | |
echo "REPUTATION STATUS: "; | |
# Check against the results we've received. | |
if($reputation > 0) { | |
echo "GOOD ({$reputation})\n"; | |
exit(0); # OK | |
} elseif($reputation >= -0.1) { | |
echo "NEUTRAL ({$reputation})\n"; | |
exit(0); # OK | |
} elseif($reputation < 0) { | |
echo "POOR ({$reputation})\n"; | |
exit(1); #WARNING | |
} else { | |
echo "UNKNOWN ({$reputation})\n"; | |
exit(3); # UNKNOWN | |
# We should never get to this state, just in case we do... | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment