From 69eefb500b9c821715b5d3189368b91cec5744d2 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Thu, 10 Dec 2015 18:48:11 -0200 Subject: Ticket #5624: Welcome dpinger! --- src/etc/inc/gwlb.inc | 436 ++++++++++++----------------- src/etc/inc/service-utils.inc | 11 +- src/etc/inc/system.inc | 6 +- src/sbin/dhclient-script | 2 +- src/usr/local/www/diag_logs_settings.php | 10 +- src/usr/local/www/shortcuts.inc | 2 +- src/usr/local/www/status.php | 6 - src/usr/local/www/system_advanced_misc.php | 25 -- src/usr/local/www/system_gateways_edit.php | 145 ++++------ 9 files changed, 260 insertions(+), 383 deletions(-) (limited to 'src') diff --git a/src/etc/inc/gwlb.inc b/src/etc/inc/gwlb.inc index 9880cdc..b01d87f 100644 --- a/src/etc/inc/gwlb.inc +++ b/src/etc/inc/gwlb.inc @@ -26,135 +26,136 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - pfSense_BUILDER_BINARIES: /sbin/route /usr/local/sbin/apinger pfSense_MODULE: routing */ require_once("config.inc"); require_once("rrd.inc"); -/* Returns an array of default values used for apinger.conf */ -function return_apinger_defaults() { +/* Returns an array of default values used for dpinger */ +function return_dpinger_defaults() { return array( "latencylow" => "200", "latencyhigh" => "500", "losslow" => "10", "losshigh" => "20", - "interval" => "1", - "down" => "10", - "avg_delay_samples" => "10", - "avg_loss_samples" => "50", - "avg_loss_delay_samples" => "20"); + "interval" => "250", + "loss_interval" => "500", + "time_period" => "25000", + "alert_interval" => "1000"); } -/* - * Creates monitoring configuration file and - * adds appropriate static routes. - */ -function setup_gateways_monitor() { - global $config, $g; +function running_dpinger_processes() { + global $g; - $gateways_arr = return_gateways_array(); - if (!is_array($gateways_arr)) { - log_error("No gateways to monitor. Apinger will not be run."); - killbypid("{$g['varrun_path']}/apinger.pid"); - @unlink("{$g['varrun_path']}/apinger.status"); - return; - } + $pidfiles = glob("{$g['varrun_path']}/dpinger_*.pid"); - $apinger_debug = ""; - if (isset($config['system']['apinger_debug'])) { - $apinger_debug = "debug on"; + $result = array(); + if ($pidfiles === FALSE) { + return $result; } - $apinger_default = return_apinger_defaults(); - $apingerconfig = << $gateway) { + foreach ($gateways_arr as $gwname => $gateway) { /* Do not monitor if such was requested */ if (isset($gateway['monitor_disable'])) { continue; @@ -172,7 +173,7 @@ EOD; continue; } - /* Interface ip is needed since apinger will bind a socket to it. + /* Interface ip is needed since dpinger will bind a socket to it. * However the config GUI should already have checked this and when * PPoE is used the IP address is set to "dynamic". So using is_ipaddrv4 * or is_ipaddrv6 to identify packet type would be wrong, especially as @@ -262,176 +263,111 @@ EOD; } $monitor_ips[] = $gateway['monitor']; - $apingercfg = "target \"{$gateway['monitor']}\" {\n"; - $apingercfg .= " description \"{$name}\"\n"; - $apingercfg .= " srcip \"{$gwifip}\"\n"; - - ## How often the probe should be sent - if (!empty($gateway['interval']) && is_numeric($gateway['interval'])) { - $interval = intval($gateway['interval']); # Restrict to Integer - if ($interval < 1) { - $interval = 1; # Minimum - } - if ($interval != $apinger_default['interval']) { # If not default value - $apingercfg .= " interval " . $interval . "s\n"; - } - } + $gateways_arr[$gwname]['enable_dpinger'] = true; + $gateways_arr[$gwname]['gwifip'] = $gwifip; + } - ## How many replies should be used to compute average delay - ## for controlling "delay" alarms - if (!empty($gateway['avg_delay_samples']) && is_numeric($gateway['avg_delay_samples'])) { - $avg_delay_samples = intval($gateway['avg_delay_samples']); # Restrict to Integer - if ($avg_delay_samples < 1) { - $avg_delay_samples = 1; # Minimum - } - if ($avg_delay_samples != $apinger_default['avg_delay_samples']) { # If not default value - $apingercfg .= " avg_delay_samples " . $avg_delay_samples . "\n"; - } - } + stop_dpinger(); - ## How many probes should be used to compute average loss - if (!empty($gateway['avg_loss_samples']) && is_numeric($gateway['avg_loss_samples'])) { - $avg_loss_samples = intval($gateway['avg_loss_samples']); # Restrict to Integer - if ($avg_loss_samples < 1) { - $avg_loss_samples = 1; # Minimum - } - if ($avg_loss_samples != $apinger_default['avg_loss_samples']) { # If not default value - $apingercfg .= " avg_loss_samples " . $avg_loss_samples . "\n"; - } + /* Start new processes */ + foreach ($gateways_arr as $gateway) { + if (isset($gateway['enable_dpinger'])) { + start_dpinger($gateway); } + } - ## The delay (in samples) after which loss is computed - ## without this delays larger than interval would be treated as loss - if (!empty($gateway['avg_loss_delay_samples']) && is_numeric($gateway['avg_loss_delay_samples'])) { - $avg_loss_delay_samples = intval($gateway['avg_loss_delay_samples']); # Restrict to Integer - if ($avg_loss_delay_samples < 1) { - $avg_loss_delay_samples = 1; # Minimum - } - if ($avg_loss_delay_samples != $apinger_default['avg_loss_delay_samples']) { # If not default value - $apingercfg .= " avg_loss_delay_samples " . $avg_loss_delay_samples . "\n"; - } - } + return 0; +} - $alarms = ""; - $alarmscfg = ""; - $override = false; - if (!empty($gateway['losslow'])) { - $alarmscfg .= "alarm loss \"{$name}loss\" {\n"; - $alarmscfg .= "\tpercent_low {$gateway['losslow']}\n"; - $alarmscfg .= "\tpercent_high {$gateway['losshigh']}\n"; - $alarmscfg .= "}\n"; - $alarms .= "\"{$name}loss\""; - $override = true; - } else { - if ($override == true) { - $alarms .= ","; - } - $alarms .= "\"loss\""; - $override = true; - } - if (!empty($gateway['latencylow'])) { - $alarmscfg .= "alarm delay \"{$name}delay\" {\n"; - $alarmscfg .= "\tdelay_low {$gateway['latencylow']}ms\n"; - $alarmscfg .= "\tdelay_high {$gateway['latencyhigh']}ms\n"; - $alarmscfg .= "}\n"; - if ($override == true) { - $alarms .= ","; - } - $alarms .= "\"{$name}delay\""; - $override = true; - } else { - if ($override == true) { - $alarms .= ","; - } - $alarms .= "\"delay\""; - $override = true; - } - if (!empty($gateway['down'])) { - $alarmscfg .= "alarm down \"{$name}down\" {\n"; - $alarmscfg .= "\ttime {$gateway['down']}s\n"; - $alarmscfg .= "}\n"; - if ($override == true) { - $alarms .= ","; - } - $alarms .= "\"{$name}down\""; - $override = true; - } else { - if ($override == true) { - $alarms .= ","; - } - $alarms .= "\"down\""; - $override = true; - } - if ($override == true) { - $apingercfg .= "\talarms override {$alarms};\n"; - } +function get_dpinger_status($gwname) { + global $g; - if (isset($gateway['force_down'])) { - $apingercfg .= "\tforce_down on\n"; - } + $socket = "{$g['varrun_path']}/dpinger_{$gwname}.sock"; - $apingercfg .= " rrd file \"{$g['vardb_path']}/rrd/{$gateway['name']}-quality.rrd\"\n"; - $apingercfg .= "}\n"; - $apingercfg .= "\n"; + if (!file_exists($socket)) { + log_error("dpinger: status socket {$socket} not found"); + return false; + } - $apingerconfig .= $alarmscfg; - $apingerconfig .= $apingercfg; + $fp = stream_socket_client("unix://{$socket}", $errno, $errstr, 10); + if (!$fp) { + log_error("dpinger: cannot connect to status socket {$socket} - $errstr ($errno)"); + return false; + } - # Create gateway quality RRD with settings more suitable for pfSense graph set, - # since apinger uses default step (300; 5 minutes) and other settings that don't - # match the pfSense gateway quality graph set. - create_gateway_quality_rrd("{$g['vardb_path']}/rrd/{$gateway['name']}-quality.rrd"); + $status = ''; + while (!feof($fp)) { + $status .= fgets($fp, 1024); } - @file_put_contents("{$g['varetc_path']}/apinger.conf", $apingerconfig); - unset($apingerconfig); + fclose($fp); + + $r = array(); + list( + $r['latency_avg'], + $r['latency_stddev'], + $r['loss'], + $r['alarm_on'], + $r['srcip'], + $r['targetip'] + ) = explode(' ', preg_replace('/\n/', '', $status)); - /* Restart apinger process */ - if (isvalidpid("{$g['varrun_path']}/apinger.pid")) { - sigkillbypid("{$g['varrun_path']}/apinger.pid", "HUP"); - } else { - /* start a new apinger process */ - @unlink("{$g['varrun_path']}/apinger.status"); - sleep(1); - mwexec_bg("/usr/local/sbin/apinger -c {$g['varetc_path']}/apinger.conf"); - sleep(1); - sigkillbypid("{$g['varrun_path']}/apinger.pid", "USR1"); + $gateways_arr = return_gateways_array(); + unset($gw); + if (isset($gateways_arr[$gwname])) { + $gw = $gateways_arr[$gwname]; } - return 0; + $r['status'] = "none"; + if (isset($gw) && isset($gw['force_down'])) { + $r['status'] = "force_down"; + } else if ($r['alarm_on'] == 1) { + $r['status'] = "down"; + } else if (isset($gw)) { + if (isset($gw['latencylow']) && + is_numeric($gw['latencylow']) && + ($r['latency_avg'] > $gw['latencylow'])) { + $r['status'] = "delay"; + } else if (isset($gw['losslow']) && + is_numeric($gw['losslow']) && + ($r['loss'] > $gw['losslow'])) { + $r['status'] = "loss"; + } + } + + $r['latency_avg'] = round($r['latency_avg']/1000, 3); + $r['latency_stddev'] = round($r['latency_stddev']/1000, 3); + + return $r; } -/* return the status of the apinger targets as a array */ +/* return the status of the dpinger targets as a array */ function return_gateways_status($byname = false) { global $config, $g; - $apingerstatus = array(); - /* Always get the latest status from apinger */ - if (file_exists("{$g['varrun_path']}/apinger.pid")) { - sigkillbypid("{$g['varrun_path']}/apinger.pid", "USR1"); - } - if (file_exists("{$g['varrun_path']}/apinger.status")) { - $apingerstatus = file("{$g['varrun_path']}/apinger.status"); - } else { - $apingerstatus = array(); - } - + $dpinger_gws = running_dpinger_processes(); $status = array(); - foreach ($apingerstatus as $line) { - $info = explode("|", $line); + + $gateways_arr = return_gateways_array(); + + foreach ($dpinger_gws as $gwname) { + $dpinger_status = get_dpinger_status($gwname); + if ($dpinger_status === false) { + continue; + } + if ($byname == false) { - $target = $info[0]; + $target = $dpinger_status['targetip']; } else { - $target = $info[2]; + $target = $gwname; } $status[$target] = array(); - $status[$target]['monitorip'] = $info[0]; - $status[$target]['srcip'] = $info[1]; - $status[$target]['name'] = $info[2]; - $status[$target]['lastcheck'] = $info[5] ? date('r', $info[5]) : date('r'); - $status[$target]['delay'] = empty($info[6]) ? "0ms" : round($info[6], 1) ."ms" ; - $status[$target]['loss'] = empty($info[7]) ? "0.0%" : round($info[7], 1) . "%"; - $status[$target]['status'] = trim($info[8]); + $status[$target]['monitorip'] = $dpinger_status['targetip']; + $status[$target]['srcip'] = $dpinger_status['srcip']; + $status[$target]['name'] = $gwname; + $status[$target]['delay'] = empty($dpinger_status['latency_avg']) ? "0ms" : $dpinger_status['latency_avg'] ."ms"; + $status[$target]['loss'] = empty($dpinger_status['loss']) ? "0.0%" : round($dpinger_status['loss'], 1) . "%"; + $status[$target]['status'] = $dpinger_status['status']; } /* tack on any gateways that have monitoring disabled @@ -441,7 +377,7 @@ function return_gateways_status($byname = false) { if (!isset($gwitem['monitor_disable'])) { continue; } - if (!is_ipaddr($gwitem['monitorip'])) { + if (!is_ipaddr($gwitem['monitor'])) { $realif = $gwitem['interface']; $tgtip = get_interface_gateway($realif); if (!is_ipaddr($tgtip)) { @@ -449,7 +385,7 @@ function return_gateways_status($byname = false) { } $srcip = find_interface_ip($realif); } else { - $tgtip = $gwitem['monitorip']; + $tgtip = $gwitem['monitor']; $srcip = find_interface_ip($realif); } if ($byname == true) { @@ -462,7 +398,6 @@ function return_gateways_status($byname = false) { if ($target == "none") { $target = $gwitem['name']; $status[$target]['name'] = $gwitem['name']; - $status[$target]['lastcheck'] = date('r'); $status[$target]['delay'] = "0.0ms"; $status[$target]['loss'] = "100.0%"; $status[$target]['status'] = "down"; @@ -470,7 +405,6 @@ function return_gateways_status($byname = false) { $status[$target]['monitorip'] = $tgtip; $status[$target]['srcip'] = $srcip; $status[$target]['name'] = $gwitem['name']; - $status[$target]['lastcheck'] = date('r'); $status[$target]['delay'] = "0.0ms"; $status[$target]['loss'] = "0.0%"; $status[$target]['status'] = "none"; @@ -1249,4 +1183,4 @@ function gateway_is_gwgroup_member($name) { return $members; } -?> \ No newline at end of file +?> diff --git a/src/etc/inc/service-utils.inc b/src/etc/inc/service-utils.inc index c97c7c9..f4d355d 100644 --- a/src/etc/inc/service-utils.inc +++ b/src/etc/inc/service-utils.inc @@ -322,7 +322,7 @@ function get_services() { $gateways_arr = return_gateways_array(); if (is_array($gateways_arr)) { $pconfig = array(); - $pconfig['name'] = "apinger"; + $pconfig['name'] = "dpinger"; $pconfig['description'] = gettext("Gateway Monitoring Daemon"); $services[] = $pconfig; } @@ -609,7 +609,7 @@ function service_control_start($name, $extras) { case 'openntpd': system_ntp_configure(); break; - case 'apinger': + case 'dpinger': setup_gateways_monitor(); break; case 'bsnmpd': @@ -678,8 +678,8 @@ function service_control_stop($name, $extras) { case 'openntpd': killbyname("openntpd"); break; - case 'apinger': - killbypid("{$g['varrun_path']}/apinger.pid"); + case 'dpinger': + stop_dpinger(); break; case 'bsnmpd': killbypid("{$g['varrun_path']}/snmpd.pid"); @@ -748,8 +748,7 @@ function service_control_restart($name, $extras) { case 'openntpd': system_ntp_configure(); break; - case 'apinger': - killbypid("{$g['varrun_path']}/apinger.pid"); + case 'dpinger': setup_gateways_monitor(); break; case 'bsnmpd': diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index 196f810..9cbc534 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -838,7 +838,7 @@ function system_syslogd_start() { $syslogd_extra = ""; if (isset($syslogcfg)) { - $separatelogfacilities = array('ntp', 'ntpd', 'ntpdate', 'charon', 'ipsec_starter', 'openvpn', 'pptps', 'poes', 'l2tps', 'relayd', 'hostapd', 'dnsmasq', 'filterdns', 'unbound', 'dhcpd', 'dhcrelay', 'dhclient', 'dhcp6c', 'apinger', 'radvd', 'routed', 'olsrd', 'zebra', 'ospfd', 'bgpd', 'miniupnpd', 'filterlog'); + $separatelogfacilities = array('ntp', 'ntpd', 'ntpdate', 'charon', 'ipsec_starter', 'openvpn', 'pptps', 'poes', 'l2tps', 'relayd', 'hostapd', 'dnsmasq', 'filterdns', 'unbound', 'dhcpd', 'dhcrelay', 'dhclient', 'dhcp6c', 'dpinger', 'radvd', 'routed', 'olsrd', 'zebra', 'ospfd', 'bgpd', 'miniupnpd', 'filterlog'); $syslogconf = ""; if ($config['installedpackages']['package']) { foreach ($config['installedpackages']['package'] as $package) { @@ -898,11 +898,11 @@ function system_syslogd_start() { $syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*"); } - $syslogconf .= "!apinger\n"; + $syslogconf .= "!dpinger\n"; if (!isset($syslogcfg['disablelocallogging'])) { $syslogconf .= "*.* {$log_directive}{$g['varlog_path']}/gateways.log\n"; } - if (isset($syslogcfg['apinger'])) { + if (isset($syslogcfg['dpinger'])) { $syslogconf .= system_syslogd_get_remote_servers($syslogcfg, "*.*"); } diff --git a/src/sbin/dhclient-script b/src/sbin/dhclient-script index d8199cb..0695eff 100755 --- a/src/sbin/dhclient-script +++ b/src/sbin/dhclient-script @@ -110,7 +110,7 @@ add_new_address() { $LOGGER "New Routers ($interface): $new_routers" - # This is necessary otherwise apinger will try to ping all 1s address + # This is necessary otherwise dpinger will try to ping all 1s address if [ -n "$new_routers" ] && [ "$new_routers" != "255.255.255.255" ]; then echo $new_routers > /tmp/${interface}_router fi diff --git a/src/usr/local/www/diag_logs_settings.php b/src/usr/local/www/diag_logs_settings.php index 292021c..0f56b44 100644 --- a/src/usr/local/www/diag_logs_settings.php +++ b/src/usr/local/www/diag_logs_settings.php @@ -83,7 +83,7 @@ $pconfig['filter'] = isset($config['syslog']['filter']); $pconfig['dhcp'] = isset($config['syslog']['dhcp']); $pconfig['portalauth'] = isset($config['syslog']['portalauth']); $pconfig['vpn'] = isset($config['syslog']['vpn']); -$pconfig['apinger'] = isset($config['syslog']['apinger']); +$pconfig['dpinger'] = isset($config['syslog']['dpinger']); $pconfig['relayd'] = isset($config['syslog']['relayd']); $pconfig['hostapd'] = isset($config['syslog']['hostapd']); $pconfig['logall'] = isset($config['syslog']['logall']); @@ -156,7 +156,7 @@ if ($_POST['resetlogs'] == gettext("Reset Log Files")) { $config['syslog']['dhcp'] = $_POST['dhcp'] ? true : false; $config['syslog']['portalauth'] = $_POST['portalauth'] ? true : false; $config['syslog']['vpn'] = $_POST['vpn'] ? true : false; - $config['syslog']['apinger'] = $_POST['apinger'] ? true : false; + $config['syslog']['dpinger'] = $_POST['dpinger'] ? true : false; $config['syslog']['relayd'] = $_POST['relayd'] ? true : false; $config['syslog']['hostapd'] = $_POST['hostapd'] ? true : false; $config['syslog']['logall'] = $_POST['logall'] ? true : false; @@ -441,10 +441,10 @@ $group->add(new Form_MultiCheckbox( )); $group->add(new Form_MultiCheckbox( - 'apinger', + 'dpinger', null, 'Gateway Monitor events', - $pconfig['apinger'] + $pconfig['dpinger'] )); $group->add(new Form_MultiCheckbox( @@ -506,7 +506,7 @@ events.push(function(){ disableInput('dhcp', hide); disableInput('portalauth', hide); disableInput('vpn', hide); - disableInput('apinger', hide); + disableInput('dpinger', hide); disableInput('relayd', hide); disableInput('hostapd', hide); } diff --git a/src/usr/local/www/shortcuts.inc b/src/usr/local/www/shortcuts.inc index 350733d..d21c171 100644 --- a/src/usr/local/www/shortcuts.inc +++ b/src/usr/local/www/shortcuts.inc @@ -241,7 +241,7 @@ $shortcuts['gateways'] = array(); $shortcuts['gateways']['main'] = "system_gateways.php"; $shortcuts['gateways']['log'] = "diag_logs.php?logfile=gateways"; $shortcuts['gateways']['status'] = "status_gateways.php"; -$shortcuts['gateways']['service'] = "apinger"; +$shortcuts['gateways']['service'] = "dpinger"; $shortcuts['gateway-groups'] = array(); $shortcuts['gateway-groups']['main'] = "system_gateway_groups.php"; diff --git a/src/usr/local/www/status.php b/src/usr/local/www/status.php index 1722099..b4bbd44 100755 --- a/src/usr/local/www/status.php +++ b/src/usr/local/www/status.php @@ -255,12 +255,6 @@ if (file_exists("/boot/loader.conf")) { if (file_exists("/boot/loader.conf.local")) { defCmdT("Loader Configuration (Local)", "/bin/cat /boot/loader.conf.local"); } -if (file_exists("/var/run/apinger.status")) { - defCmdT("Gateway Status", "/bin/cat /var/run/apinger.status"); -} -if (file_exists("/var/etc/apinger.conf")) { - defCmdT("Gateway Monitoring Config", "/bin/cat /var/etc/apinger.conf"); -} if (file_exists("/var/etc/filterdns.conf")) { defCmdT("Filter DNS Daemon Config", "/bin/cat /var/etc/filterdns.conf"); } diff --git a/src/usr/local/www/system_advanced_misc.php b/src/usr/local/www/system_advanced_misc.php index b462849..422ca6f 100644 --- a/src/usr/local/www/system_advanced_misc.php +++ b/src/usr/local/www/system_advanced_misc.php @@ -88,7 +88,6 @@ $pconfig['thermal_hardware'] = $config['system']['thermal_hardware']; $pconfig['schedule_states'] = isset($config['system']['schedule_states']); $pconfig['kill_states'] = isset($config['system']['kill_states']); $pconfig['skip_rules_gw_down'] = isset($config['system']['skip_rules_gw_down']); -$pconfig['apinger_debug'] = isset($config['system']['apinger_debug']); $pconfig['use_mfs_tmpvar'] = isset($config['system']['use_mfs_tmpvar']); $pconfig['use_mfs_tmp_size'] = $config['system']['use_mfs_tmp_size']; $pconfig['use_mfs_var_size'] = $config['system']['use_mfs_var_size']; @@ -261,19 +260,6 @@ if ($_POST) { unset($config['system']['skip_rules_gw_down']); } - $need_apinger_restart = false; - if ($_POST['apinger_debug'] == "yes") { - if (!isset($config['system']['apinger_debug'])) { - $need_apinger_restart = true; - } - $config['system']['apinger_debug'] = true; - } else { - if (isset($config['system']['apinger_debug'])) { - $need_apinger_restart = true; - } - unset($config['system']['apinger_debug']); - } - if ($_POST['use_mfs_tmpvar'] == "yes") { $config['system']['use_mfs_tmpvar'] = true; } else { @@ -309,9 +295,6 @@ if ($_POST) { if ($need_relayd_restart) { relayd_configure(); } - if ($need_apinger_restart) { - setup_gateways_monitor(); - } } } @@ -519,14 +502,6 @@ $section->addInput(new Form_Checkbox( 'down, the rule is created omitting the gateway. This option overrides that '. 'behavior by omitting the entire rule instead.'); -$section->addInput(new Form_Checkbox( - 'apinger_debug', - 'Gateway monitoring logging', - 'Enable debug logging', - $pconfig['apinger_debug'] -))->setHelp('Enable this setting to log debug information from the gateway '. - 'monitoring process to the system logs.'); - $form->add($section); $section = new Form_Section('RAM Disk Settings (Reboot to Apply Changes)'); diff --git a/src/usr/local/www/system_gateways_edit.php b/src/usr/local/www/system_gateways_edit.php index 712bb55..5519bfc 100644 --- a/src/usr/local/www/system_gateways_edit.php +++ b/src/usr/local/www/system_gateways_edit.php @@ -102,9 +102,9 @@ if (isset($id) && $a_gateways[$id]) { $pconfig['name'] = $a_gateways[$id]['name']; $pconfig['weight'] = $a_gateways[$id]['weight']; $pconfig['interval'] = $a_gateways[$id]['interval']; - $pconfig['avg_delay_samples'] = $a_gateways[$id]['avg_delay_samples']; - $pconfig['avg_loss_samples'] = $a_gateways[$id]['avg_loss_samples']; - $pconfig['avg_loss_delay_samples'] = $a_gateways[$id]['avg_loss_delay_samples']; + $pconfig['loss_interval'] = $a_gateways[$id]['loss_interval']; + $pconfig['alert_interval'] = $a_gateways[$id]['alert_interval']; + $pconfig['time_period'] = $a_gateways[$id]['time_period']; $pconfig['interface'] = $a_gateways[$id]['interface']; $pconfig['friendlyiface'] = $a_gateways[$id]['friendlyiface']; $pconfig['ipprotocol'] = $a_gateways[$id]['ipprotocol']; @@ -118,7 +118,6 @@ if (isset($id) && $a_gateways[$id]) { $pconfig['latencyhigh'] = $a_gateways[$id]['latencyhigh']; $pconfig['losslow'] = $a_gateways[$id]['losslow']; $pconfig['losshigh'] = $a_gateways[$id]['losshigh']; - $pconfig['down'] = $a_gateways[$id]['down']; $pconfig['monitor'] = $a_gateways[$id]['monitor']; $pconfig['monitor_disable'] = isset($a_gateways[$id]['monitor_disable']); $pconfig['nonlocalgateway'] = isset($a_gateways[$id]['nonlocalgateway']); @@ -400,57 +399,49 @@ if ($_POST) { } } - if ($_POST['down']) { - if (!is_numeric($_POST['down'])) { - $input_errors[] = gettext("The down time setting needs to be a numeric value."); - } else if ($_POST['down'] < 1) { - $input_errors[] = gettext("The down time setting needs to be positive."); + if ($_POST['loss_interval']) { + if (!is_numeric($_POST['loss_interval'])) { + $input_errors[] = gettext("The loss interval needs to be a numeric value."); + } else if ($_POST['loss_interval'] < 1) { + $input_errors[] = gettext("The loss interval setting needs to be positive."); } } - if (($_POST['interval']) && ($_POST['down'])) { + if (($_POST['interval']) && ($_POST['loss_interval'])) { if ((is_numeric($_POST['interval'])) && - (is_numeric($_POST['down'])) && - ($_POST['interval'] > $_POST['down'])) { - $input_errors[] = gettext("The probe interval needs to be less than the down time setting."); + (is_numeric($_POST['loss_interval'])) && + ($_POST['interval'] > $_POST['loss_interval'])) { + $input_errors[] = gettext("The probe interval needs to be less than the loss interval setting."); } } else if ($_POST['interval']) { if (is_numeric($_POST['interval']) && - ($_POST['interval'] > $dpinger_default['down'])) { + ($_POST['interval'] > $dpinger_default['loss_interval'])) { $input_errors[] = gettext(sprintf( - "The probe interval needs to be less than the default down time setting (%d)", - $dpinger_default['down'])); + "The probe interval needs to be less than the default loss interval setting (%d)", + $dpinger_default['loss_interval'])); } - } else if ($_POST['down']) { - if (is_numeric($_POST['down']) && - ($_POST['down'] < $dpinger_default['interval'])) { + } else if ($_POST['loss_interval']) { + if (is_numeric($_POST['loss_interval']) && + ($_POST['loss_interval'] < $dpinger_default['interval'])) { $input_errors[] = gettext(sprintf( - "The down time setting needs to be higher than the default probe interval (%d)", + "The loss interval setting needs to be higher than the default probe interval (%d)", $dpinger_default['interval'])); } } - if ($_POST['avg_delay_samples']) { - if (!is_numeric($_POST['avg_delay_samples'])) { - $input_errors[] = gettext("The average delay replies qty needs to be a numeric value."); - } else if ($_POST['avg_delay_samples'] < 1) { - $input_errors[] = gettext("The average delay replies qty needs to be positive."); + if ($_POST['time_period']) { + if (!is_numeric($_POST['time_period'])) { + $input_errors[] = gettext("The time period over which results are averaged needs to be a numeric value."); + } else if ($_POST['time_period'] < 1) { + $input_errors[] = gettext("The time period over which results are averaged needs to be positive."); } } - if ($_POST['avg_loss_samples']) { - if (!is_numeric($_POST['avg_loss_samples'])) { - $input_errors[] = gettext("The average packet loss probes qty needs to be a numeric value."); - } else if ($_POST['avg_loss_samples'] < 1) { - $input_errors[] = gettext("The average packet loss probes qty needs to be positive."); - } - } - - if ($_POST['avg_loss_delay_samples']) { - if (!is_numeric($_POST['avg_loss_delay_samples'])) { - $input_errors[] = gettext("The lost probe delay needs to be a numeric value."); - } else if ($_POST['avg_loss_delay_samples'] < 1) { - $input_errors[] = gettext("The lost probe delay needs to be positive."); + if ($_POST['alert_interval']) { + if (!is_numeric($_POST['alert_interval'])) { + $input_errors[] = gettext("The alert interval needs to be a numeric value."); + } else if ($_POST['alert_interval'] < 1) { + $input_errors[] = gettext("The alert interval needs to be positive."); } } @@ -471,11 +462,16 @@ if ($_POST) { $gateway['name'] = $_POST['name']; $gateway['weight'] = $_POST['weight']; $gateway['ipprotocol'] = $_POST['ipprotocol']; - $gateway['interval'] = $_POST['interval']; + if ($_POST['interval']) { + $gateway['interval'] = $_POST['interval']; + } - $gateway['avg_delay_samples'] = $_POST['avg_delay_samples']; - $gateway['avg_loss_samples'] = $_POST['avg_loss_samples']; - $gateway['avg_loss_delay_samples'] = $_POST['avg_loss_delay_samples']; + if ($_POST['time_period']) { + $gateway['time_period'] = $_POST['time_period']; + } + if ($_POST['alert_interval']) { + $gateway['alert_interval'] = $_POST['alert_interval']; + } $gateway['descr'] = $_POST['descr']; if ($_POST['monitor_disable'] == "yes") { @@ -538,8 +534,8 @@ if ($_POST) { if ($_POST['losshigh']) { $gateway['losshigh'] = $_POST['losshigh']; } - if ($_POST['down']) { - $gateway['down'] = $_POST['down']; + if ($_POST['loss_interval']) { + $gateway['loss_interval'] = $_POST['loss_interval']; } if (isset($_POST['disabled'])) { @@ -713,7 +709,7 @@ $section->addInput(new Form_Input( if (!(!empty($pconfig['latencylow']) || !empty($pconfig['latencyhigh']) || !empty($pconfig['losslow']) || !empty($pconfig['losshigh']) || (isset($pconfig['weight']) && $pconfig['weight'] > 1) || (isset($pconfig['interval']) && ($pconfig['interval'] > $dpinger_default['interval'])) || - (isset($pconfig['down']) && !($pconfig['down'] == $dpinger_default['down'])))) { + (isset($pconfig['loss_interval']) && !($pconfig['loss_interval'] == $dpinger_default['loss_interval'])))) { $btnadvanced = new Form_Button( 'toggle-advanced', @@ -795,67 +791,46 @@ $section->addInput(new Form_Input( 'placeholder' => $dpinger_default['interval'], 'max' => 86400 ] -))->setHelp('How often an ICMP probe will be sent in seconds. Default is %d.'. +))->setHelp('How often an ICMP probe will be sent in milliseconds. Default is %d.'. 'NOTE: The quality graph is averaged over seconds, not intervals, so as '. 'the probe interval is increased the accuracy of the quality graph is '. 'decreased.', [$dpinger_default['interval']]); $section->addInput(new Form_Input( - 'down', - 'Down', - 'number', - $pconfig['down'], - ['placeholder' => $dpinger_default['down']] -))->setHelp('The number of seconds of failed probes before the alarm '. - 'will fire. Default is %d.', [$dpinger_default['down']]); - -$group = new Form_Group('Avg. Delay Replies Qty'); -$group->add(new Form_Input( - 'avg_delay_samples', - null, + 'loss_interval', + 'Loss Interval', 'number', - $pconfig['avg_delay_samples'], - [ - 'placeholder' => $dpinger_default['avg_delay_samples'], - 'max' => 100 - ] -)); -$group->setHelp('How many replies should be used to compute average delay for '. - 'controlling "delay" alarms? Default is %d.', - [$dpinger_default['avg_delay_samples']]); -$section->add($group); + $pconfig['loss_interval'], + ['placeholder' => $dpinger_default['loss_interval']] +))->setHelp('Time interval in milliseconds before packets are treated as lost. '. + 'Default is %d.', [$dpinger_default['down']]); -$group = new Form_Group('Avg. Packet Loss Probes'); +$group = new Form_Group('Time Period'); $group->add(new Form_Input( - 'avg_loss_samples', + 'time_period', null, 'number', - $pconfig['avg_loss_samples'], + $pconfig['time_period'], [ - 'placeholder' => $dpinger_default['avg_loss_samples'], - 'max' => 1000 + 'placeholder' => $dpinger_default['time_period'] ] )); -$group->setHelp('How many probes should be useds to compute average packet loss? '. - 'Default is %d.', - [$dpinger_default['avg_loss_samples']]); +$group->setHelp('time period in milliseconds over which results are averaged. Default is %d.', + [$dpinger_default['time_period']]); $section->add($group); -$group = new Form_Group('Lost Probe Delay'); +$group = new Form_Group('Alert interval'); $group->add(new Form_Input( - 'avg_loss_delay_samples', + 'alert_interval', null, 'number', - $pconfig['avg_loss_delay_samples'], + $pconfig['alert_interval'], [ - 'placeholder' => $dpinger_default['avg_loss_delay_samples'], - 'max' => 200 + 'placeholder' => $dpinger_default['alert_interval'] ] )); -$group->setHelp('The delay (in qty of probe samples) after which loss is '. - 'computed. Without this, delays longer than the probe interval would be '. - 'treated as packet loss. Default is %d.', - [$dpinger_default['avg_loss_delay_samples']]); +$group->setHelp('time interval in milliseconds between alerts. Default is %d.', + [$dpinger_default['alert_interval']]); $section->add($group); $section->addInput(new Form_StaticText( -- cgit v1.1