mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-13 00:07:26 +00:00
System: Gateways - kill opposite states when a gateway "up" is triggered (#8548)
This commit is contained in:
parent
6d579db491
commit
4f3db31351
@ -311,6 +311,9 @@ function dpinger_status()
|
||||
'monitor' => !empty($gwitem['monitor']) ? $gwitem['monitor'] : '~',
|
||||
'gateway' => $gwitem['gateway'] ?? '',
|
||||
'monitor_killstates' => $gwitem['monitor_killstates'] ?? '0',
|
||||
'monitor_killstates_priority' => $gwitem['monitor_killstates_priority'] ?? '0',
|
||||
'priority' => $gwitem['priority'] ?? '255',
|
||||
'ipprotocol' => $gwitem['ipprotocol'],
|
||||
'name' => $gwname,
|
||||
'stddev' => '~',
|
||||
'delay' => '~',
|
||||
|
||||
@ -35,6 +35,8 @@ require_once 'interfaces.inc';
|
||||
$gwnames = [];
|
||||
$affected_gateways = !empty($argv[1]) ? explode(',', $argv[1]) : [];
|
||||
|
||||
$metered_found_prios = ['inet' => 256, 'inet6' => 256];
|
||||
$metered_gws = ['inet' => [], 'inet6' => []];
|
||||
foreach (return_gateways_status() as $status) {
|
||||
if ($status['status'] == 'down') {
|
||||
/* try to recover monitors stuck in down state ignoring "force_down" */
|
||||
@ -42,6 +44,23 @@ foreach (return_gateways_status() as $status) {
|
||||
if (!empty($status['monitor_killstates']) && in_array($status['name'], $affected_gateways)) {
|
||||
configdp_run('filter kill gateway_states', [$status['gateway']], true);
|
||||
}
|
||||
} elseif ($status['status'] != 'force_down') {
|
||||
/* collect "metered" gateways which should be killed depending priority */
|
||||
if (!empty($status['monitor_killstates_priority'])) {
|
||||
$metered_gws[$status['ipprotocol']][] = $status;
|
||||
} elseif (in_array($status['name'], $affected_gateways)) {
|
||||
/* only trigger on "up" events to calculate highest prio */
|
||||
$metered_found_prios[$status['ipprotocol']] = min($status['priority'], $metered_found_prios[$status['ipprotocol']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($metered_found_prios as $ipproto => $metered_found_prio) {
|
||||
/* kill states for "metered" gateways */
|
||||
foreach ($metered_gws[$ipproto] as $status) {
|
||||
if ($status['priority'] > $metered_found_prio) {
|
||||
configdp_run('filter kill gateway_states', [$status['gateway']], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -63,6 +63,13 @@
|
||||
<style>monitor_opt</style>
|
||||
<help>When a monitor down event is triggered, kill all states to this gateway.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>gateway_item.monitor_killstates_priority</id>
|
||||
<label>Kill states metered</label>
|
||||
<type>checkbox</type>
|
||||
<style>monitor_opt</style>
|
||||
<help>When a monitor up event is triggered for a gateway with a higher priority (lower value) than this, kill all states to this gateway. Most common use for this switch are metered connections like LTE.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>gateway_item.monitor</id>
|
||||
<label>Monitor IP</label>
|
||||
|
||||
@ -56,6 +56,7 @@
|
||||
</monitor_disable>
|
||||
<monitor_noroute type="BooleanField"/>
|
||||
<monitor_killstates type="BooleanField"/>
|
||||
<monitor_killstates_priority type="BooleanField"/>
|
||||
<monitor type="TextField">
|
||||
<Constraints>
|
||||
<check001>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user