#!/usr/local/bin/php
<?php
require_once 'config.inc';
require_once 'interfaces.inc';
require_once 'util.inc';
require_once 'plugins.inc.d/dpinger.inc';
$gwname = 'YOUR_GATEWAY_NAME';
$groupname = 'YOUR_GATEWAY_GROUP_NAME';
$gateways_status = dpinger_status();
if (empty($gateways_status[$gwname])) {
echo "Gateway {$gwname} status could not be determined." . PHP_EOL;
exit(1);
}
$status = $gateways_status[$gwname]['status'];
$delay = $gateways_status[$gwname]['delay'];
$loss = $gateways_status[$gwname]['loss'];
if (stristr($status, 'down') !== false) {
echo "MONITOR: {$gwname} is down, removing from routing group {$groupname}." . PHP_EOL;
exit(1);
}
echo "MONITOR: {$gwname} is up (delay {$delay}, loss {$loss}), rejoining routing group {$groupname}." . PHP_EOL;
exit(0);
