mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-14 08:34:39 +00:00
system: merge dpinger loop 1 and 2 #2396
Essentially, the first loop configures apinger targets and later it starts them. Emulate the same for dpinger by not going through the loop again with maybe differing abort conditions.
This commit is contained in:
parent
4bbb00296f
commit
9ddc810f16
@ -87,8 +87,8 @@ function setup_gateways_monitor($verbose = false, $gwname = null)
|
||||
|
||||
$gateways_arr_all = return_gateways_array(true);
|
||||
$monitor_ips = array();
|
||||
$listen_ips = array();
|
||||
|
||||
$dpinger_default = return_dpinger_defaults();
|
||||
$apinger_default = return_apinger_defaults();
|
||||
$apingerconfig = <<<EOD
|
||||
|
||||
@ -281,7 +281,6 @@ EOD;
|
||||
}
|
||||
|
||||
$monitor_ips[] = $gateway['monitor'];
|
||||
$listen_ips[$name] = $gwifip;
|
||||
|
||||
$apingercfg = "target \"{$gateway['monitor']}\" {\n";
|
||||
$apingercfg .= " description \"{$name}\"\n";
|
||||
@ -409,95 +408,81 @@ EOD;
|
||||
"/var/db/rrd/{$gateway['name']}-quality.rrd",
|
||||
!isset($config['system']['prefer_dpinger'])
|
||||
);
|
||||
|
||||
if (!isset($config['system']['prefer_dpinger'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* log warnings via syslog */
|
||||
$params = '-S ';
|
||||
|
||||
/* disable unused reporting thread */
|
||||
$params .= '-r 0 ';
|
||||
|
||||
/* identifier */
|
||||
$params .= exec_safe('-i %s ', $name);
|
||||
|
||||
/* bind src address */
|
||||
$params .= exec_safe('-B %s ', $gwifip);
|
||||
|
||||
/* PID filename */
|
||||
$params .= exec_safe('-p %s ', "/var/run/dpinger_{$name}.pid");
|
||||
|
||||
/* status socket */
|
||||
$params .= exec_safe('-u %s ', "/var/run/dpinger_{$name}.sock");
|
||||
|
||||
if (empty($gateway['action_disable'])) {
|
||||
/* command to run on alarm */
|
||||
$params .= '-C /usr/local/etc/rc.monitor ';
|
||||
}
|
||||
|
||||
$params .= exec_safe(
|
||||
'-d %s ',
|
||||
isset($gateway['data_payload']) && is_numeric($gateway['data_payload']) ?
|
||||
$gateway['data_payload'] : $dpinger_default['data_payload']
|
||||
);
|
||||
|
||||
$params .= exec_safe(
|
||||
'-s %ss ',
|
||||
isset($gateway['interval']) && is_numeric($gateway['interval']) ?
|
||||
$gateway['interval'] : $dpinger_default['interval']
|
||||
);
|
||||
|
||||
$params .= exec_safe(
|
||||
'-l %ss ',
|
||||
isset($gateway['loss_interval']) && is_numeric($gateway['loss_interval']) ?
|
||||
$gateway['loss_interval'] : $dpinger_default['loss_interval']
|
||||
);
|
||||
|
||||
$params .= exec_safe(
|
||||
'-t %ss ',
|
||||
isset($gateway['time_period']) && is_numeric($gateway['time_period']) ?
|
||||
$gateway['time_period'] : $dpinger_default['time_period']
|
||||
);
|
||||
|
||||
$params .= exec_safe(
|
||||
'-A %ss ',
|
||||
isset($gateway['alert_interval']) && is_numeric($gateway['alert_interval']) ?
|
||||
$gateway['alert_interval'] : $dpinger_default['alert_interval']
|
||||
);
|
||||
|
||||
$params .= exec_safe(
|
||||
'-D %s ',
|
||||
isset($gateway['latencyhigh']) && is_numeric($gateway['latencyhigh']) ?
|
||||
$gateway['latencyhigh'] : $dpinger_default['latencyhigh']
|
||||
);
|
||||
|
||||
$params .= exec_safe(
|
||||
'-L %s ',
|
||||
isset($gateway['losshigh']) && is_numeric($gateway['losshigh']) ?
|
||||
$gateway['losshigh'] : $dpinger_default['losshigh']
|
||||
);
|
||||
|
||||
/* daemonises forground mode because background mode does not work? */
|
||||
mwexecf_bg("/usr/local/bin/dpinger -f {$params} %s", array($gateway['monitor']));
|
||||
}
|
||||
|
||||
if (isset($config['system']['prefer_dpinger'])) {
|
||||
$dpinger_defaults = return_dpinger_defaults();
|
||||
|
||||
/* XXX normally this should iterate over monitor_ips */
|
||||
foreach ($gateways_arr_all as $name => $gateway) {
|
||||
if (!empty($gwname) && $gwname != $name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($gateway['disabled']) || isset($gateway['monitor_disable'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($listen_ips[$name])) {
|
||||
log_error("Failed to aquire listen IP for gateway $name");
|
||||
continue;
|
||||
}
|
||||
|
||||
/* log warnings via syslog */
|
||||
$params = '-S ';
|
||||
|
||||
/* disable unused reporting thread */
|
||||
$params .= '-r 0 ';
|
||||
|
||||
/* identifier */
|
||||
$params .= exec_safe('-i %s ', $name);
|
||||
|
||||
/* bind src address */
|
||||
$params .= exec_safe('-B %s ', $listen_ips[$name]);
|
||||
|
||||
/* PID filename */
|
||||
$params .= exec_safe('-p %s ', "/var/run/dpinger_{$name}.pid");
|
||||
|
||||
/* status socket */
|
||||
$params .= exec_safe('-u %s ', "/var/run/dpinger_{$name}.sock");
|
||||
|
||||
if (empty($gateway['action_disable'])) {
|
||||
/* command to run on alarm */
|
||||
$params .= '-C /usr/local/etc/rc.monitor ';
|
||||
}
|
||||
|
||||
$params .= exec_safe(
|
||||
'-d %s ',
|
||||
isset($gateway['data_payload']) && is_numeric($gateway['data_payload']) ?
|
||||
$gateway['data_payload'] : $dpinger_defaults['data_payload']
|
||||
);
|
||||
|
||||
$params .= exec_safe(
|
||||
'-s %ss ',
|
||||
isset($gateway['interval']) && is_numeric($gateway['interval']) ?
|
||||
$gateway['interval'] : $dpinger_defaults['interval']
|
||||
);
|
||||
|
||||
$params .= exec_safe(
|
||||
'-l %ss ',
|
||||
isset($gateway['loss_interval']) && is_numeric($gateway['loss_interval']) ?
|
||||
$gateway['loss_interval'] : $dpinger_defaults['loss_interval']
|
||||
);
|
||||
|
||||
$params .= exec_safe(
|
||||
'-t %ss ',
|
||||
isset($gateway['time_period']) && is_numeric($gateway['time_period']) ?
|
||||
$gateway['time_period'] : $dpinger_defaults['time_period']
|
||||
);
|
||||
|
||||
$params .= exec_safe(
|
||||
'-A %ss ',
|
||||
isset($gateway['alert_interval']) && is_numeric($gateway['alert_interval']) ?
|
||||
$gateway['alert_interval'] : $dpinger_defaults['alert_interval']
|
||||
);
|
||||
|
||||
$params .= exec_safe(
|
||||
'-D %s ',
|
||||
isset($gateway['latencyhigh']) && is_numeric($gateway['latencyhigh']) ?
|
||||
$gateway['latencyhigh'] : $dpinger_defaults['latencyhigh']
|
||||
);
|
||||
|
||||
$params .= exec_safe(
|
||||
'-L %s ',
|
||||
isset($gateway['losshigh']) && is_numeric($gateway['losshigh']) ?
|
||||
$gateway['losshigh'] : $dpinger_defaults['losshigh']
|
||||
);
|
||||
|
||||
/* daemonises forground mode because background mode does not work? */
|
||||
mwexecf_bg("/usr/local/bin/dpinger -f {$params} %s", array($gateway['monitor']));
|
||||
}
|
||||
} else {
|
||||
if (!isset($config['system']['prefer_dpinger'])) {
|
||||
$gateways_arr = return_gateways_array();
|
||||
if (!is_array($gateways_arr)) {
|
||||
log_error("No gateways to monitor. Apinger will not be run.");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user