Project

General

Profile

« Previous | Next » 

Revision 04a72a97

Added by Vladimir Voskoboynikov almost 5 years ago

Add gateway substatus. Fixes #10546

Update return_gateways_status to return a substatus as well as the existing status.

status changed to be one of online or down.
substatus can be one of none, down, highloss, highlatency, loss, latency, or force_down

Edit status pages, gateway widget, and gateway group code accordingly.

View differences:

src/etc/inc/gwlb.inc
316 316
	return;
317 317
}
318 318

  
319
function get_dpinger_status($gwname, $detailed = false, $gways = false) {
319
function get_dpinger_status($gwname, $gways = false, $action_disable = false) {
320 320
	global $g;
321 321

  
322 322
	$running_processes = running_dpinger_processes();
......
389 389
	$r['latency_avg'] = round($r['latency_avg']/1000, 3);
390 390
	$r['latency_stddev'] = round($r['latency_stddev']/1000, 3);
391 391

  
392
	$r['status'] = "none";
392
	$r['status'] = "online";
393
	$r['substatus'] = "none";
393 394
	if (isset($gw) && isset($gw['force_down'])) {
394
		$r['status'] = "force_down";
395
		$r['status'] = "down";
396
		$r['substatus'] = "force_down";
395 397
	} else if (isset($gw)) {
396 398
		$settings = return_dpinger_defaults();
397 399

  
......
410 412
		}
411 413

  
412 414
		if ($r['latency_avg'] > $settings['latencyhigh']) {
413
			if ($detailed) {
414
				$r['status'] = "highdelay";
415
			} else {
415
			if (!$action_disable) {
416 416
				$r['status'] = "down";
417 417
			}
418
			$r['substatus'] = "highdelay";
418 419
		} else if ($r['loss'] > $settings['losshigh']) {
419
			if ($detailed) {
420
				$r['status'] = "highloss";
421
			} else {
420
			if (!$action_disable) {
422 421
				$r['status'] = "down";
423 422
			}
423
			$r['substatus'] = "highloss";
424 424
		} else if ($r['latency_avg'] > $settings['latencylow']) {
425
			$r['status'] = "delay";
425
			$r['substatus'] = "delay";
426 426
		} else if ($r['loss'] > $settings['losslow']) {
427
			$r['status'] = "loss";
427
			$r['substatus'] = "loss";
428 428
		}
429 429
	}
430 430

  
......
448 448
		// If action is disabled for this gateway, then we want a detailed status.
449 449
		// That reports "highdelay" or "highloss" rather than just "down".
450 450
		// Because reporting the gateway down would be misleading (gateway action is disabled)
451
		$detailed = $gateways_arr[$gwname]['action_disable'];
452
		$dpinger_status = get_dpinger_status($gwname, $detailed);
451
		$action_disable = $gateways_arr[$gwname]['action_disable'];
452
		$dpinger_status = get_dpinger_status($gwname, $action_disable);
453 453
		if ($dpinger_status === false) {
454 454
			continue;
455 455
		}
......
468 468
		$status[$target]['stddev'] = empty($dpinger_status['latency_stddev']) ? "0ms" : $dpinger_status['latency_stddev'] . "ms";
469 469
		$status[$target]['loss'] = empty($dpinger_status['loss']) ? "0.0%" : round($dpinger_status['loss'], 1) . "%";
470 470
		$status[$target]['status'] = $dpinger_status['status'];
471
		$status[$target]['substatus'] = $dpinger_status['substatus'];
471 472
	}
472 473

  
473 474
	/* tack on any gateways that have monitoring disabled
......
501 502
			$status[$target]['delay'] = "0.0ms";
502 503
			$status[$target]['loss'] = "100.0%";
503 504
			$status[$target]['status'] = "down";
505
			$status[$target]['substatus'] = "down";
504 506
		} else {
505 507
			$status[$target]['monitorip'] = $tgtip;
506 508
			$status[$target]['srcip'] = $srcip;
507 509
			$status[$target]['name'] = $gwitem['name'];
508 510
			$status[$target]['delay'] = "";
509 511
			$status[$target]['loss'] = "";
510
			$status[$target]['status'] = "none";
512
			$status[$target]['status'] = "online";
513
			$status[$target]['substatus'] = "none";
511 514
		}
512 515

  
513 516
		$status[$target]['monitor_disable'] = true;
......
528 531
				'delay' => "Delay",
529 532
				'stddev' => "StdDev",
530 533
				'loss' => "Loss",
531
				'status' => "Status");
534
				'status' => "Status",
535
				'substatus' => "Substatus");
532 536
	}
533 537
	foreach ($gwstat as $gw) {
534 538
		foreach ($gw as $gwdidx => $gwdata) {
......
1237 1241
			$status = $gateways_status[$gwname];
1238 1242
			$gwdown = false;
1239 1243
			if (stristr($status['status'], "down")) {
1240
				$msg = sprintf(gettext('MONITOR: %1$s is down, omitting from routing group %2$s'), $gwname, $group['name']);
1241
				$gwdown = true;
1242
			} else if (stristr($status['status'], "loss") && strstr($group['trigger'], "loss")) {
1243
				/* packet loss */
1244
				$msg = sprintf(gettext('MONITOR: %1$s has packet loss, omitting from routing group %2$s'), $gwname, $group['name']);
1245
				$gwdown = true;
1246
			} else if (stristr($status['status'], "delay") && strstr($group['trigger'] , "latency")) {
1247
				/* high latency */
1248
				$msg = sprintf(gettext('MONITOR: %1$s has high latency, omitting from routing group %2$s'), $gwname, $group['name']);
1249 1244
				$gwdown = true;
1250
			}
1245
				switch ($status['substatus']) {
1246
					case "highloss":
1247
						$msg = sprintf(gettext('MONITOR: %1$s has packet loss, omitting from routing group %2$s'), $gwname, $group['name']);
1248
						break;
1249
					case "highdelay":
1250
						$msg = sprintf(gettext('MONITOR: %1$s has high latency, omitting from routing group %2$s'), $gwname, $group['name']);
1251
						break;
1252
					default:
1253
						$msg = sprintf(gettext('MONITOR: %1$s is down, omitting from routing group %2$s'), $gwname, $group['name']);
1254
				}
1255
			} 
1251 1256
			$statuschanged = false;
1252 1257
			$pluginparams = array();
1253 1258
			$pluginparams['type'] = 'gateway';
src/usr/local/www/status_gateway_groups.php
114 114
									while ($c <= $priority_count) {
115 115
										$monitor = lookup_gateway_monitor_ip_by_name($member);
116 116
										if ($p == $c) {
117
											$status = $gateways_status[$monitor]['status'];
118
											if (stristr($status, "down")) {
119
													$online = gettext("Offline");
120
													$bgcolor = "bg-danger";
121
											} elseif (stristr($status, "loss")) {
122
													$online = gettext("Warning, Packetloss");
123
													$bgcolor = "bg-warning";
124
											} elseif (stristr($status, "delay")) {
125
													$online = gettext("Warning, Latency");
126
													$bgcolor = "bg-warning";
127
											} elseif ($status == "none") {
128
													$online = gettext("Online");
129
													$bgcolor = "bg-success";
117
											$status = $gateways_status[$monitor];
118
											if (stristr($status['status'], "online")) {
119
												switch ($status['substatus']) {
120
													case "highloss":
121
														$online = gettext("Danger, Packetloss") . ': ' . $status['loss'];
122
														$bgcolor = "bg-danger";
123
														break;
124
													case "highdelay":
125
														$online = gettext("Danger, Latency") . ': ' . $status['delay'];
126
														$bgcolor = "bg-danger";
127
														break;
128
													case "loss":
129
														$online = gettext("Warning, Packetloss") . ': ' . $status['loss'];
130
														$bgcolor = "bg-warning";
131
														break;
132
													case "delay":
133
														$online = gettext("Warning, Latency") . ': ' . $status['delay'];
134
														$bgcolor = "bg-warning";
135
														break;
136
													default:
137
														if ($status['monitor_disable'] || ($status['monitorip'] == "none")) {
138
															$online = gettext("Online <br/>(unmonitored)");
139
														} else {
140
															$online = gettext("Online");
141
														}
142
														$bgcolor = "bg-success";
143
												}
144
											} elseif (stristr($status['status'], "down")) {
145
												$bgcolor = "bg-danger";
146
												switch ($status['substatus']) {
147
													case "force_down":
148
														$online = gettext("Offline (forced)");
149
														break;
150
													case "highloss":
151
														$online = gettext("Offline, Packetloss") . ': ' . $status['loss'];
152
														break;
153
													case "highdelay":
154
														$online = gettext("Offline, Latency") . ': ' . $status['delay'];
155
														break;
156
													default:
157
														$online = gettext("Offline");
158
												}
130 159
											} else {
131 160
												$online = gettext("Gathering data");
132 161
												$bgcolor = "bg-info";
src/usr/local/www/status_gateways.php
124 124
				</td>
125 125
<?php
126 126
					$status = $gateways_status[$i];
127
					switch ($status['status']) {
128
						case "force_down":
129
							$online = gettext("Offline (forced)");
130
							$bgcolor = "bg-danger";
131
							break;
132
						case "down":
133
							$online = gettext("Offline");
134
							$bgcolor = "bg-danger";
135
							break;
136
						case "highloss":
137
							$online = gettext("Danger, Packetloss") . ': ' . $status['loss'];
138
							$bgcolor = "bg-danger";
139
							break;
140
						case "loss":
141
							$online = gettext("Warning, Packetloss") . ': ' . $status['loss'];
142
							$bgcolor = "bg-warning";
143
							break;
144
						case "highdelay":
145
							$online = gettext("Danger, Latency") . ': ' . $status['delay'];
146
							$bgcolor = "bg-danger";
147
							break;
148
						case "delay":
149
							$online = gettext("Warning, Latency") . ': ' . $status['delay'];
150
							$bgcolor = "bg-warning";
151
							break;
152
						case "none":
153
							$online = gettext("Online");
154
							$bgcolor = "bg-success";
155
							break;
156
						default:
157
							$online = gettext("Pending");
158
							$bgcolor = "bg-info";
127
					if (stristr($status['status'], "online")) {
128
						switch ($status['substatus']) {
129
							case "highloss":
130
								$online = gettext("Danger, Packetloss") . ': ' . $status['loss'];
131
								$bgcolor = "bg-danger";
132
								break;
133
							case "highdelay":
134
								$online = gettext("Danger, Latency") . ': ' . $status['delay'];
135
								$bgcolor = "bg-danger";
136
								break;
137
							case "loss":
138
								$online = gettext("Warning, Packetloss") . ': ' . $status['loss'];
139
								$bgcolor = "bg-warning";
140
								break;
141
							case "delay":
142
								$online = gettext("Warning, Latency") . ': ' . $status['delay'];
143
								$bgcolor = "bg-warning";
144
								break;
145
							default:
146
								if ($status['monitor_disable'] || ($status['monitorip'] == "none")) {
147
									$online = gettext("Online <br/>(unmonitored)");
148
								} else {
149
									$online = gettext("Online");
150
								}
151
								$bgcolor = "bg-success";
152
						}
153
					} elseif (stristr($status['status'], "down")) {
154
						$bgcolor = "bg-danger";
155
						switch ($status['substatus']) {
156
							case "force_down":
157
								$online = gettext("Offline (forced)");
158
								break;
159
							case "highloss":
160
								$online = gettext("Offline, Packetloss") . ': ' . $status['loss'];
161
								break;
162
							case "highdelay":
163
								$online = gettext("Offline, Latency") . ': ' . $status['delay'];
164
								break;
165
							default:
166
								$online = gettext("Offline");
167
						}
168
					} else {
169
						$online = gettext("Pending");
170
						$bgcolor = "bg-info";
159 171
					}
160 172
?>
161 173
				<td class="<?=$bgcolor?>">
src/usr/local/www/widgets/widgets/gateways.widget.php
106 106
			$rtnstr .= 	"</td>\n";
107 107

  
108 108
			if ($gateways_status[$gname]) {
109
				if (stristr($gateways_status[$gname]['status'], "force_down")) {
110
					$online = gettext("Offline (forced)");
111
					$bgcolor = "danger";  // lightcoral
109
				if (stristr($gateways_status[$gname]['status'], "online")) {
110
					switch ($gateways_status[$gname]['substatus']) {
111
						case "highloss":
112
							$online = gettext("Danger, Packetloss");
113
							$bgcolor = "danger";
114
							break;
115
						case "highdelay":
116
							$online = gettext("Danger, Latency");
117
							$bgcolor = "danger";
118
							break;
119
						case "loss":
120
							$online = gettext("Warning, Packetloss");
121
							$bgcolor = "warning";
122
							break;
123
						case "delay":
124
							$online = gettext("Warning, Latency");
125
							$bgcolor = "warning";
126
							break;
127
						default:
128
							if ($status['monitor_disable'] || ($status['monitorip'] == "none")) {
129
								$online = gettext("Online <br/>(unmonitored)");
130
							} else {
131
								$online = gettext("Online");
132
							}
133
							$bgcolor = "success";
134
					}
112 135
				} elseif (stristr($gateways_status[$gname]['status'], "down")) {
113
					$online = gettext("Offline");
114
					$bgcolor = "danger";  // lightcoral
115
				} elseif (stristr($gateways_status[$gname]['status'], "highloss")) {
116
					$online = gettext("Packetloss");
117
					$bgcolor = "danger";  // lightcoral
118
				} elseif (stristr($gateways_status[$gname]['status'], "loss")) {
119
					$online = gettext("Packetloss");
120
					$bgcolor = "warning";  // khaki
121
				} elseif (stristr($gateways_status[$gname]['status'], "highdelay")) {
122
					$online = gettext("Latency");
123
					$bgcolor = "danger";  // lightcoral
124
				} elseif (stristr($gateways_status[$gname]['status'], "delay")) {
125
					$online = gettext("Latency");
126
					$bgcolor = "warning";  // khaki
127
				} elseif ($gateways_status[$gname]['status'] == "none") {
128
					if ($gateways_status[$gname]['monitor_disable'] || ($gateways_status[$gname]['monitorip'] == "none")) {
129
						$online = gettext("Online <br/>(unmonitored)");
130
					} else {
131
						$online = gettext("Online");
136
					$bgcolor = "danger";
137
					switch ($gateways_status[$gname]['substatus']) {
138
						case "force_down":
139
							$online = gettext("Offline (forced)");
140
							break;
141
						case "highloss":
142
							$online = gettext("Offline, Packetloss");
143
							break;
144
						case "highdelay":
145
							$online = gettext("Offline, Latency");
146
							break;
147
						default:
148
							$online = gettext("Offline");
132 149
					}
133
					$bgcolor = "success";  // lightgreen
134
				} elseif ($gateways_status[$gname]['status'] == "") {
150
				} else {
135 151
					$online = gettext("Pending");
136 152
					$bgcolor = "info";  // lightgray
137 153
				}

Also available in: Unified diff